1、Yum安装MySql

MySQL官方的 Yum Repository

环境: Centos7 + MYSQL5.7

1.下载RPM包,并安装启动

惹失效--> 查看 https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/#repo-qg-yum-fresh-install

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

yum -y install mysql57-community-release-el7-10.noarch.rpm
yum repolist enabled | grep mysql


yum -y install mysql-community-server
systemctl start  mysqld && systemctl status mysqld && systemctl enable  mysqld

2.获取初始密码

grep "password" /var/log/mysqld.log
mysql -uroot -p     # 回车后会提示输入密码

3.修改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

# 注意: 这里密码不能过于简单,若需要更改简单密码,需要修改密码规则
# SHOW VARIABLES LIKE 'validate_password%';
# set global validate_password_policy=0;
# set global validate_password_length=1;
# ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

4.清除多余文件

# 因为安装了Yum Repository,以后每次yum操作都会自动更新,需要把这个卸载掉:
yum -y remove mysql57-community-release-el7-10.noarch

Last updated