1、配置YUM源
在MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo/yum/
或者直接在服务器上用wget下载rpm安装包
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.*"
可以修改vim /etc/yum.repos.d/mysql-community.repo源,改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。
4安装MySQL
yum install mysql-community-server
5启动MySQL服务
systemctl start mysqld
然后输入如下命令查看服务状态
systemctl status mysqld
6配置开机启动
systemctl enable mysqld
systemctl daemon-reload
7修改root账号本地登录密码
mysql安装完成之后,在/var/log/mysqld.log文件中生成了一个root账号的默认密码。可通过以下命令查看这个密码:
grep 'temporary password' /var/log/mysqld.log
8自定义root账号密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPass666@';
或者
set password for 'root'@'localhost'=password('NewPass666@');
然后输入如下命令即使生效以上操作:
flush privileges;
至此mysql5.7在CentOs7上的安装完成!
Leave a Reply