1.之前安装了5.6,先卸载了
[root@chen ~]# rpm -qa|grep -i mysql
mysql-community-libs-5.6.48-2.el7.x86_64
mysql-community-release-el7-5.noarch
mysql-community-common-5.6.48-2.el7.x86_64
mysql-community-client-5.6.48-2.el7.x86_64
mysql-community-server-5.6.48-2.el7.x86_64
[root@chen ~]# systemctl stop mysqld.service
[root@chen ~]# rpm -ev --nodeps mysql-community-libs-5.6.48-2.el7.x86_64
Preparing packages...
mysql-community-libs-5.6.48-2.el7.x86_64
[root@chen ~]# rpm -ev --nodeps mysql-community-release-el7-5.noarch
Preparing packages...
mysql-community-release-el7-5.noarch
[root@chen ~]# rpm -ev --nodeps mysql-community-common-5.6.48-2.el7.x86_64
Preparing packages...
mysql-community-common-5.6.48-2.el7.x86_64
[root@chen ~]# rpm -ev --nodeps mysql-community-client-5.6.48-2.el7.x86_64
Preparing packages...
mysql-community-client-5.6.48-2.el7.x86_64
[root@chen ~]# rpm -ev --nodeps mysql-community-server-5.6.48-2.el7.x86_64
Preparing packages...
mysql-community-server-5.6.48-2.el7.x86_64
warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave
[root@chen ~]# rpm -qa|grep -i mysql
[root@chen ~]#
2.没有wget的,先安装
yum -y install wget
3.下载安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm --no-check-certificate
4.安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
5.检查是否安装成功了
yum repolist enabled | grep "mysql.*-community.*"
6.安装mysql并启动
yum install mysql-community-server
#或者service mysqld start
systemctl start mysqld
#查看状态
systemctl status mysqld
7.设置开机启动
systemctl enable mysqld
systemctl daemon-reload
8.获取初始化密码
如果执行获取命令没拿到,需要删除原来安装的mysql残留数据
[root@chen ~]# grep 'temporary password' /var/log/mysqld.log
[root@chen ~]# rm -rf /var/lib/mysql
[root@chen ~]# systemctl restart mysqld
[root@chen ~]# grep 'temporary password' /var/log/mysqld.log
2019-08-07T19:16:44.402628Z 1 [Note] A temporary password is generated for root@localhost: W6+uRkglZ0ex
9.修改密码
mysql -u root -p
输入上一步获取的临时密码
#5.7出于安全考虑不让设置简单密码,要先更改其密码机制
set global validate_password_policy=LOW;
# 设置密码长度
set global validate_password_length=6;
# 修改密码
SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
flush privileges;
use mysql;
update user set host = '%' where user = 'root';
# 使配置生效
flush privileges;
10.设置字符集
set character_set_database=utf8;
flush privileges;