本文最后更新于 2020 年 3 月 20 日,文章已超过 6 个月!内容可能已失效,请自行测试 ~

rpm方式安装:

下载MySQL包

[root@master ~]# wget -r https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar
[root@master ~]# tar xf mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar

卸载原有的mysql及mysql-libs

[root@master ~]# rpm -e mysql mysql-libs –nodeps

RPM安装MySQL并启动

[root@master ~]# rpm -e mariadb-libs --nodeps
[root@master ~]# rpm -ivh mysql-community-common-8.0.19-1.el7.x86_64.rpm 
warning: mysql-community-common-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-8.0.19-1.e################################# [100%]
[root@master ~]# rpm -ivh mysql-community-libs-${Mysql_Version}-1.el7.x86_64.rpm
warning: mysql-community-libs-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-8.0.19-1.el7################################# [100%]
[root@master ~]# rpm -ivh mysql-community-client-${Mysql_Version}-1.el7.x86_64.rpm
warning: mysql-community-client-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-8.0.19-1.e################################# [100%]
[root@master ~]# rpm -ivh mysql-community-server-${Mysql_Version}-1.el7.x86_64.rpm
warning: mysql-community-server-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-8.0.19-1.e################################# [100%]
[root@master ~]# rpm -ivh ~/mysql-community-devel-8.0.19-1.el7.x86_64.rpm
warning: /root/mysql-community-devel-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-devel-8.0.19-1.el################################# [100%]
[root@master ~]# rpm -ivh mysql-community-libs-compat-8.0.19-1.el7.x86_64.rpm
warning: mysql-community-libs-compat-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-compat-8.0.1################################# [100%]
[root@master ~]# service mysqld start
初始化 MySQL 数据库:                                      [确定]
正在启动 mysqld:                                          [确定]
[root@master ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

获取MySQL默认root密码并更改

[root@master ~]# grep 'temporary password' /var/log/mysqld.log |awk '{print $13}'
kSAzJF%e,1ab

密码格式必须8位数大写字母+数字+特殊符号

[root@master ~]# grep 'temporary password' /var/log/mysqld.log |awk '{print $13}'
kSAzJF%e,1ab
[root@master ~]# mysql -uroot -p'kSAzJF%e,1ab'
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Abc123@!';
Query OK, 0 rows affected (0.07 sec)
mysql> create user'tests'@'localhost' identified by 'aBc123@!';
Query OK, 0 rows affected (0.09 sec)		//密码强度同上,授权用户tests于本地登陆密码为aBc123@!
[root@master ~]# mysql --help |grep Ver
mysql  Ver 8.0.19 for Linux on x86_64 (MySQL Community Server - GPL)

源码包安装:

遇到的问题

报错:

[root@master ~]# rpm -ivh mysql-community-libs-${Mysql_Version}-1.el7.x86_64.rpm 
warning: mysql-community-libs-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	mariadb-libs is obsoleted by mysql-community-libs-8.0.19-1.el7.x86_64

解决方法:

[root@master ~]# rpm -e mariadb-libs --nodeps

该文章采用「CC 协议」,转载必须注明作者和本文链接.
分类: Mysql