keac's Bolg.

centos7 yum 方式安装mysql

字数统计: 269阅读时长: 1 min
2019/08/01 Share

1) 下载mysql源安装包

wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

2) 安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm

3) 检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"

4) 修改 vim /etc/yum.repos.d/mysql-community.repo源 ,改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。

5) 安装MySQL

yum install mysql-community-server -y

6) 启动mysql服务

systemctl start mysqld

7) 开启启动

systemctl enable mysqld

systemctl daemon-reload

8) 修改root本地登录密码
1) 查看mysql密码

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

![](5.png)

2) 连接mysql

`mysql -uroot -p`

3) 修改密码[注意:后面的分号一定要跟上]

mysql> `ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';`

或者

mysql>  `set password for 'root'@'localhost'=password('MyNewPass4!');`

mysql> `show variables like '%password%'`;

注意,密码一定要足够复杂!!!
![](6.png) 

9) 添加远程登录用户
mysql> GRANT ALL PRIVILEGES ON *.* TO 'keac'@'%' IDENTIFIED BY 'Password!!!' WITH GRANT OPTION;

CATALOG