在CentOS安裝MySQL5.7。
1. 使用el 8源不能成功安装
安装步骤如下1:
- 添加MySQL仓库源
在dev.mysql.com/downloads/repo/yum/查看相应系统版本的下载链接。当前CentOS 8对应的链接是:mysql80-community-release-el8-1.noarch.rpm,使用wget下载:
$ wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
添加yum源:
sudo yum localinstall mysql80-community-release-el8-1.noarch.rpm
查看可用的MySQL源:
yum repolist enabled | grep "mysql.*-community.*"
...
mysql80-community MySQL 8.0 Community Server 41
显示源已经被成功添加,目前可用的是8.0版本。
- 选择MySQL版本
查看所有的版本:
$ yum repolist all | grep mysql
...
mysql80-community MySQL 8.0 Community Server enabled: 41
mysql80-community-source MySQL 8.0 Community Server - S disabled
但是发现添加的源并没有包含5.7版本,网上有讨论同样的问题:installing-mysql-5-7-on-centos-8,需要使用其它方法安装。
2. 使用el 7源成功安装
安装步骤如下2:
- 禁止默认的MySQL源
$ sudo dnf remove @mysql
$ sudo dnf module reset mysql && sudo dnf module disable mysql
- 使用el 7的源,修改mysql源文件
sudo vi /etc/yum.repos.d/mysql-community.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-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/basearch/
enabled=1
gpgcheck=0
[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=0
- 更新源并再次查看可用的版本,5.7版本出现
$ sudo dnf update
$ yum repolist all | grep mysql
...
mysql57-community MySQL 5.7 Community Server enabled: 424
mysql80-community-source MySQL 8.0 Community Server - S disabled
- 安装5.7版本
$ sudo dnf --enablerepo=mysql57-community install mysql-community-server
3. 设置MySQL
- 启动MySQL
$ sudo systemctl start mysqld.service
- 可以检查是否开机启动:
$ systemctl is-enabled mysqld.service
enabled
- 查看初始root密码
sudo grep 'temporary password' /var/log/mysqld.log
- 进行安全设置
$ mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
The existing password for the user account root has expired. Please set a new password.
New password:
Re-enter new password:
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y
New password:
Re-enter new password:
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
至此MySQL5.7安装完毕,可以进一步做如远程链接等其它设置。