共计 4236 个字符,预计需要花费 11 分钟才能阅读完成。
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.linuxidc.com/Linux/2019-08/160317.htm。
: