CentOS7 yum方式在线安装MySQL5.7及设置密码

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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值