以前安装过mysql
前言:检查以前是否装有mysql
rpm -qa|grep -i mysql
安装了会显示: bt-mysql57-5.7.31-1.el7.x86_64
停止mysql服务和删除之前安装的mysql
rpm -e bt-mysql57-5.7.31-1.el7.x86_64
查找并删除mysql相关目录
find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/lib64/mysql
.....
rm -rf /var/lib/mysql
rm -rf /var/lib/mysql
rm -rf /usr/lib64/mysql
....
注意:卸载mysql后/etc/my.cnf不会删除,需要进行手动删
rm -rf /etc/my.cnf
再次执行 rpm -qa|grep -i mysql
检查一下
安装mysql
1、在线下载rpm包
wget -c https://repo.huaweicloud.com/mysql/Downloads/MySQL-5.7/mysql-5.7.37-1.el7.x86_64.rpm-bundle.tar
ls命令查看
2、解压rpm包
tar xf mysql-5.7.37-1.el7.x86_64.rpm-bundle.tar
ls命令查看
3、数据库之间会冲突因此需要卸载mariadb-libs
yum remove mariadb-libs
4、安装mysql相关包
rpm -ivh mysql-community-client-5.7.37-1.el7.x86_64.rpm mysql-community-common-5.7.37-1.el7.x86_64.rpm mysql-community-libs-5.7.37-1.el7.x86_64.rpm mysql-community-server-5.7.37-1.el7.x86_64.rpm
5、启动mysql
systemctl start mysqld
6、查看mysql启动状态
systemctl status mysqld
7、临时密码登录并修改密码
P=`awk '/temporary password/ {print $NF}' /var/log/mysqld.log`
mysql -uroot -p$P
登录成功~
8、修改登录密码
ALTER USER root@localhost identified by 'MySQL@123';
密码为大写字母、小写字母、特殊字符、数字的8位及以上的组合
本文参考于:linux系统中三种方法安装MySQL5.7(rhel7/centos7)