官网地址 https://dev.mysql.com/downloads/repo/yum/
wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
yum localinstall mysql80-community-release-el7-3.noarch.rpm
yum repolist enabled | grep "mysql.*-community.*"
选择指定版本。
vim /etc/yum.repos.d/mysql-community.repo
把5.7的enabled设置成1并且把8.0的设置成0
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
yum install -y mysql-community-server
# 启动MySQL
systemctl start mysqld
systemctl status mysqld
# 设置开启重启
systemctl enable mysqld
systemctl daemon-reload
初次安装 root密码位置
grep 'temporary password' /var/log/mysqld.log
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
或者
mysql> set password for 'root'@'localhost'=password('root');
如果不能设置简单密码,开发环境可以调整如下参数
mysql> set global validate_password_policy=0;
# 5.7密码长度不能小于4
mysql> set global validate_password_length=4;