1. 首先删除mariadb
yum remove mariadb*
2. 在mysql-8.0.30centos、redhat7安装包-MySQL文档类资源-CSDN下载mysql-8.0.30centos、redhat7安装包更多下载资源、学习资料请访问CSDN下载频道.https://download.csdn.net/download/vah101/86503452下载mysql-8.0.30相关的安装包,之后执行如下命令:
tar zxvf mysql-8.0.30.tgz
cd mysql
yum install *.rpm
3. 启动mysql
service mysqld start
4. 修改root密码
查看mysql的日志,找到初始密码
tail -f /var/log/mysqld.log
获得如下结果:
2022-08-30T03:44:38.727039Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-08-30T03:44:41.434551Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-08-30T03:44:43.357239Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: aVbcdU09ua(E
2022-08-30T03:44:47.398735Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.30) starting as process 30583
如:aVbcdU09ua(E
之后执行:
mysql -uroot -paVbcdU09ua(E
登录到mysql命令行,执行如下操作:
alter user root@localhost identified by 'test_first@4312';
将新密码设置成test_first@4312,注意,mysql8默认的密码规则比较严格,需要包括数字、符号、字母并且长度大于6,执行成功之后,退出mysql命令行,再执行
mysql -uroot -p
使用新密码登录,
再执行如下命令:
use mysql;
update user set host='%' where user='root';
flush privileges;
退出命令行,即可完成mysql的安装配置。