参考于官方文档:https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/
- 首先加入mysql yum源
需要先从这里下载你对应平台的rpm,并确保你的rpm在当前目录下然后:
sudo rpm -Uvh mysql57-community-release-el7-11.noarch.rpm
- 然后选择你需要安装的版本:
yum repolist all | grep mysql
如图:
- 最后安装Mysql:
sudo yum install mysql-community-server
中间一直y就行了
-
安装完成后查看root的临时密码:
sudo grep 'temporary password' /var/log/mysqld.log
第一次登陆后务必更改下密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
-
如果是在云服务器上搭建的话,还要开启远程连接
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
password替换为自己的密码,再刷新下
FLUSH PRIVILEGES;
最后重启下mysql就大功告成了!
sudo systemctl restart mysqld.service
相关服务命令:
- 开启mysql服务
sudo systemctl start mysqld.service
- 关闭mysql服务
sudo systemctl stop mysqld.service
- 查看mysql服务状态
sudo systemctl status mysqld.service
- 重启mysql服务
sudo systemctl restart mysqld.service