CentOS 7.2 安装 MySQL 5.7.13

前端之家收集整理的这篇文章主要介绍了CentOS 7.2 安装 MySQL 5.7.13前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1. 下载MysqL的repo源

CentOS7.2的yum源中默认没有MysqL,要先下载MysqL的repo源

wget http://repo.MysqL.com/MysqL57-community-release-el7-8.noarch.rpm

2. 安装MysqL57-community-release-el7-8.noarch.rpm包

rpm -ivh MysqL57-community-release-el7-8.noarch.rpm  --nodeps --force

安装这个包后,会获得两个MysqL的yum repo源:/etc/yum.repos.d/MysqL-community.repo,/etc/yum.repos.d/MysqL-community-source.repo

3.安装MysqL

yum install MysqL-server

4. 启动MysqL服务

查看MysqL服务是否已启动

service MysqLd status

启动服务

systemctl start MysqLd

5. 重置root密码

MysqL5.7会在安装后为root用户生成一个随机密码,而不是像以往版本的空密码。
可以安全模式修改root登录密码或者用随机密码登录@R_404_360@。下面用随机密码方式

MysqL为root用户生成随机密码通过MysqLd.log文件可以查找到:

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

修改root用户密码:(MysqL的密码策略比较复杂,过于简单的密码会被拒绝)

MysqL -u root -p
MysqL> Enter password: (输入刚才查询到的随机密码)
MysqL> SET PASSWORD FOR 'root'@'localhost'= "Root-123";
MysqL> exit

用root新密码登录

MysqL -u root -pRoot-123

如果上面的方式不能修改可以使用下面安全模式修改root:

关闭服务
systemctl stop MysqLd.service
vi /etc/my.cnf 
MysqLd下面添加skip-grant-tables 保存退出启动服务 systemctl start MysqLd.service MysqL -u root 不用密码直接回车 use MysqL update user set authentication_string=password('Root-123') where User='root' and Host='localhost';
flush privileges;
exit;
vi /etc/my.cnf 把 skip-grant-tables 一句删除保存退出重启MysqL服务 systemctl restart MysqLd.service 再次登录即可 MysqL -u root -pRoot-123 如果进行操作出现下面的提示: You must reset your password using ALTER USER statement before executing this statement. 就再设置一遍密码 set password = password('Root-123');

6. 开放3306端口

允许使用用户名root密码Root-123456从任何主机连接到MysqL服务器

MysqL>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root-123456' WITH GRANT OPTION;
MysqL>FLUSH PRIVILEGES;
MysqL>exit;

开启防火墙MysqL 3306端口的外部访问

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
原文链接:https://www.f2er.com/centos/378528.html

猜你在找的CentOS相关文章