已复制
全屏展示
复制代码

CentOS7安装MySQL5.7


· 2 min read

一. MySQL5.7仓库配置

# cat /etc/yum.repos.d/mysql.repo
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0

二. 安装指定版本MySQL

sudo yum install mysql-community-server-5.7.28
# 或者
sudo yum install mysql-community-server-5.7.26

三. 配置登录用户名密码

# 启动 停止 开机自启 查看状态
sudo systemctl start mysqld
sudo systemctl stop mysqld
sudo systemctl enable mysqld
sudo systemctl status mysqld

# 查看临时生成的默认密码,然后登陆,配置新密码。
# "Xs%?Hp)rz5k:" 是临时密码,'123456MySQL_'是新密码,新密码需要有一定的复杂度。
cat /var/log/mysqld.log | grep "password is generated"


# 修改密码,并授权远程登录
mysql -uroot -p"Xs%?Hp)rz5k:"
mysql> alter user 'root'@'localhost' identified by '123456MySQL_';
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456MySQL_';
mysql> flush privileges;


# 使用新密码重新登陆
mysql -uroot -p123456MySQL_


# 查看密码要求
SHOW VARIABLES LIKE 'validate_password%';

# 修改密码策略
set global validate_password_policy=0;


# 新版本的将授权和创建用户分开了
create user 'root'@'%' identified by '123456MySQL_';
grant all privileges on *.* to 'root'@'%';

四. 安装其他版本的MySQL

配置指定的仓库即可安装指定版本的MySQL了

# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


# 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=0
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=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


[mysql-cluster-7.5-community]
name=MySQL Cluster 7.5 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-7.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


[mysql-cluster-7.6-community]
name=MySQL Cluster 7.6 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-7.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


[mysql-cluster-8.0-community]
name=MySQL Cluster 8.0 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

文章推荐