安装步骤
1. 安装yum仓库
到https://dev.mysql.com/downloads/repo/yum/ 下载对应操作系统版本的yum仓库,然后进行安装:sudo rpm -Uvh platform-and-version-specific-package-name.rpm
2. 选择需要安装的mysql版本
默认情况下,在上一步安装的yum仓库中激活的是最新版本的MySQL,例如现在最新版本的MySQL是5.7,如下:
shell> yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 42
mysql-connectors-community-source MySQL Connectors Community - S disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 55
mysql-tools-community-source MySQL Tools Community - Source disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - S disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - S disabled
mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 247
mysql57-community-source MySQL 5.7 Community Server - S disabled
mysql80-community/x86_64 MySQL 8.0 Community Server disabled
mysql80-community-source MySQL 8.0 Community Server - S disabled
如果确实需要安装最新版的MySQL,那么不需要做任何修改。
如果现在需要安装的是MySQL5.6而不是最新版的5.7,那么需要执行如下操作:
shell> sudo yum-config-manager --disable mysql57-community
shell> sudo yum-config-manager --enable mysql56-community
现在再来看激活的版本是什么: 显然是5.6版本的MySQL。
shell> yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 42
mysql-connectors-community-source MySQL Connectors Community - S disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 55
mysql-tools-community-source MySQL Tools Community - Source disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - S disabled
mysql56-community/x86_64 MySQL 5.6 Community Server enabled: 378
mysql56-community-source MySQL 5.6 Community Server - S disabled
mysql57-community/x86_64 MySQL 5.7 Community Server disabled
mysql57-community-source MySQL 5.7 Community Server - S disabled
mysql80-community/x86_64 MySQL 8.0 Community Server disabled
mysql80-community-source MySQL 8.0 Community Server - S disabled
3. 执行安装
shell> sudo yum install mysql-community-server
4. 启动MySQL
shell> sudo service mysqld start
启动成功之后就可以连接MySQL服务器了,使用root用户的登录不需要密码。
shell> mysql -uroot -p
当然,登录成功之后可以修改root密码:
mysql> update user set Password=password('!Q111111') where User='root';
注意,这种方式修改的root密码需要重启MySQL服务之后才能生效。
【参考】