MySQL的最新版是8.0.x版本,与5.x版本相比,不仅仅快了很多,而且还带来了大量的更新和更快的性能,在读写工作负载,IO密集型工作负载中有着更加强劲的性能,使用了utf-8mb4作为默认字符集,同时增强了安全性。
1、首先安装rpm, 一个相当于加速的东西。
# rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
如有错误,见本文下面评论栏
2、列出CentOS 7.6当前支持的MySQL数据库,如下面所示
# yum repolist all | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community 启用: 118
mysql-connectors-community-source MySQL Connectors Community - Sour 禁用
mysql-tools-community/x86_64 MySQL Tools Community 启用: 95
mysql-tools-community-source MySQL Tools Community - Source 禁用
mysql-tools-preview/x86_64 MySQL Tools Preview 禁用
mysql-tools-preview-source MySQL Tools Preview - Source 禁用
mysql55-community/x86_64 MySQL 5.5 Community Server 禁用
mysql55-community-source MySQL 5.5 Community Server - Sour 禁用
mysql56-community/x86_64 MySQL 5.6 Community Server 禁用
mysql56-community-source MySQL 5.6 Community Server - Sour 禁用
mysql57-community/x86_64 MySQL 5.7 Community Server 启用: 364
mysql57-community-source MySQL 5.7 Community Server - Sour 禁用
mysql80-community/x86_64 MySQL 8.0 Community Server 禁用
mysql80-community-source MySQL 8.0 Community Server - Sour 禁用
从上面可以看出,会默认下载5.7版本的MySQL数据库,而8.0版本的默认是关闭的,先把5.7的禁用,启用MySQL 8.0数据库。
3、打开文件, 修改设置
# vi /etc/yum.repos.d/mysql-community.repo
输入命令后显示如下代码,每一个模块代表一个版本数据库。
其中可以看到5.7版本, enabled=1, 改为enabled=0, 禁用掉
另外可以看到8.0版本, enabled=0, 改为enabled=1, 开启
[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
# 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
[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-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
4、修改完之后查看可以用的MySQL版本
# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community 118
mysql-tools-community/x86_64 MySQL Tools Community 95
mysql80-community/x86_64 MySQL 8.0 Community Server 129
5、看到有MySQL 8.0版本之后,就可以正式开始安装MySQL了。
# yum install -y mysql-community-server
6、完成后启动MySQL
# systemctl start mysqld
7、查看MySQL启动状态
# systemctl status mysqld
8、 MySQL安装完成之后会在LOG文件( /var/log/mysqld.log)中生成一个默认的临时密码,可根据自己的实际情况修改(冒号后面为旧密码)。
2019-08-24T05:32:58.277335Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.17) initializing of server in progress as process 58121
2019-08-24T05:33:04.727785Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: jb_klPPYe12W
2019-08-24T05:33:06.400398Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.17) initializing of server has completed
2019-08-24T05:33:09.808077Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.17) starting as process 58170
2019-08-24T05:33:12.378185Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-08-24T05:33:12.428422Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.17' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.
2019-08-24T05:33:12.522176Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
9、登录MySQL并修改root密码
mysql -uroot -p
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'Linuxidc.com@123';
这里的Linuxidc.com@123 为新密码。
新密码强度默认为中等,需要同时有大小写字母、数字、特殊符号,只有修改成功后才能修改配置再设置更简单的密码,具体见 https://www.558idc.com/Linux/2019-08/160317.htm 。