1 网络下载rpm包
powershell
wget -c https://repo.huaweicloud.com/mysql/Downloads/MySQL-5.7/mysql-5.7.37-1.el7.x86_64.rpm-bundle.tar
2 解压
powershell
tar xf mysql-5.7.37-1.el7.x86_64.rpm-bundle.tar
3 数据库之间会冲突因此需要卸载mariadb-libs
powershell
yum remove mariadb-libs
4 安装
如果没有net-tools需要先安装
powershell
yum install net-tools -y
powershell
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
powershell
systemctl start mysqld
6 临时密码登录并修改密码
powershell
P=`awk '/temporary password/ {print $NF}' /var/log/mysqld.log`
mysql -uroot -p$P
7 登陆进入后,改变MySQL密码策略(密码强度默认为中等,大小写字母、数字、特殊符号,只有修改成功后才能设置更简单的密码):
powershell
set global validate_password_policy=0;
set global validate_password_length=6;
8 修改root密码,红色部分为设置的用户名和密码:
powershell
alter user 'root'@'localhost' IDENTIFIED BY '12345678';
9 开启root远程访问权限(会降低安全性):
powershell
use mysql;
select host,user from user;
update user set host='%' where user='root';
flush privileges;
10 修改/etc/my.cnf文件
powershell
vim /etc/my.cnf
mysqld\] 下面添加文件内容: ```powershell #设置表名忽略⼤⼩写,增加⼀⾏ lower_case_table_names =1 ``` 11 重启mysql服务 启动MySQL: ```powershell systemctl start mysqld ``` 查看MySQL服务状态: ```powershell systemctl status mysqld ``` 参考:[linux系统中三种方法安装MySQL5.7(rhel7/centos7)](https://blog.csdn.net/weixin_52951697/article/details/123766776)