CentOS安装MySQL

 

  官方指南:https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

  查看yum源

 

  下载安装包,tips:tab键自动补全文件名

wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm

  安装mysql-server

sudo yum install -y mysql-community-server

  启动mysql

sudo systemctl start mysqld
sudo systemctl enable mysqld

  查看默认密码

grep 'temporary password' /var/log/mysqld.log

  登录mysql

mysql -u root -p

  登录之后第一件事就是更改密码

  修改默认密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'pswd4root@L';

  查看用户表

show database;
use mysql;
select host,user from user;

  修改允许访问的来源

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'pwd4root' WITH GRANT OPTION;
FLUSH PRIVILEGES;

  也可以通过修改user表的host来设置允许访问的来源,host='%'是允许任何来源,也可以修改为指定ip。

use mysql;
update user set host = '%' where user = 'root';
flush privileges;

  退出mysql

quit

  开放防火墙端口

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

  远程连接mysql

 

 

 

 

 

posted @ 2019-11-21 21:22  原来是李  阅读(245)  评论(0编辑  收藏  举报