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