安装其他版本的,请修改 /etc/yum.repos.d/mysql-community.repo,这个文件中的baseurl
#官网下载地址:https://downloads.mysql.com/archives/community/
根据需要选择要下载的版本
清华源安装mysql -5.7
vim /etc/yum.repos.d/mysql-community.repo
cat >/etc/yum.repos.d/mysql-community.repo<<EOF
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
EOF
#安装
yum install mysql mysql-server -y
service mysqld start
#若无法进入
vim /etc/my.cnf
[mysqld] #下添加一行,使其登录时跳过权限检查,设置密码后在还原
skip_grant_tables
service mysqld restart
#进入mysql 时直接输入mysql就可以进入,重新设置root密码
use mysql;
update user set authentication_string=password('123456'), password_expired='N' where user="root";
flush privileges;
service mysqld restart
mysql -uroot -p123456