一.卸载原有数据库
1.通过命令rpm -qa | grep mysql ,rpm -qa | grep mariadb 查看原有数据库
[root@ganluren-wk etc]# rpm -qa | grep mysql
[root@ganluren-wk etc]# rpm -qa | grep mariadb
2. [root@ganluren-wk etc]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64卸载数据库
或者[root@ganluren-wk etc]# yum -y remove mariadb-libs*
3.删除配置文件
[root@ganluren-wk etc]# rm -rf /etc/my.cnf
[root@ganluren-wk etc]# rm -rf /var/lib/mysql
二.安装mysql数据库5.7
1.添加源
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
或wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
2.安装
[root@ganluren-wk etc]# yum -y install mysql-community-server
原因是mysql的GPG升级了,需要重新获取
执行rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 ,再安装
安装成功
3.启动数据库
[root@ganluren-wk ~]# systemctl start mysqld
[root@ganluren-wk ~]# systemctl status mysqld
4.查找默认密码
[root@ganluren-wk ~]# grep 'temporary password' /var/log/mysqld.log
三.配置mysql
1. 使用默认密码,登录mysql
2.修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Ganluren@password123'; 密码设置复杂度需要符合安全规则, 默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位
或 mysql> set password for 'root'@'localhost'=password('Ganluren@password123');
3. 查看数据库show databases;
4.创建数据库
mysql> create database test;
5. 删除数据库
mysql> drop database test;
6.退出数据库
mysql> quit