天天看点

使用yum repository 安装MySQL 8.0

第一次在网上写文档,心乱如麻,文档根据MySQL官网整理而得,如有不妥,请多多指教。

系统:CentOS 6.8

前期准备:系统初始化(关闭防火墙、SELINUX、配置网卡及主机名等)

yum源准备: wget http://file.kangle.odata.cc/repo/Centos-6.repo

wget http://file.kangle.odata.cc/repo/epel-6.repo

1、下载并安装MySQL源安装包

下载地址:https://dev.mysql.com/downloads/repo/yum/

[[email protected] yum.repos.d]# ls -l mysql80-community-release-el6-3.noarch.rpm 
-rw-r--r-- 1 root root 26012 Apr 25  2019 mysql80-community-release-el6-3.noarch.rpm
[[email protected] yum.repos.d]# yum install mysql80-community-release-el6-3.noarch.rpm 
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Examining mysql80-community-release-el6-3.noarch.rpm: mysql80-community-release-el6-3.noarch
Marking mysql80-community-release-el6-3.noarch.rpm to be installed
Loading mirror speeds from cached hostfile
 * base: mirrors.cloud.tencent.com
 * extras: mirrors.cloud.tencent.com
 * updates: mirrors.cloud.tencent.com
Resolving Dependencies
--> Running transaction check
---> Package mysql80-community-release.noarch 0:el6-3 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================
 Package                                   Arch                   Version                Repository                                               Size
=======================================================================================================================================================
Installing:
 mysql80-community-release                 noarch                 el6-3                  /mysql80-community-release-el6-3.noarch                  31 k

Transaction Summary
=======================================================================================================================================================
Install       1 Package(s)

Total size: 31 k
Installed size: 31 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mysql80-community-release-el6-3.noarch                                                                                              1/1 
  Verifying  : mysql80-community-release-el6-3.noarch                                                                                              1/1 

Installed:
  mysql80-community-release.noarch 0:el6-3                                                                                                             

Complete!
           

通过以下命令检查MySQL Yum存储库是否已成功添加

[[email protected] yum.repos.d]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community    MySQL Connectors Community        153
mysql-tools-community         MySQL Tools Community              99
mysql80-community             MySQL 8.0 Community Server        201
           

2、选择发布系列

使用MySQL Yum存储库时,默认情况下会选择最新的GA系列(目前为MySQL 8.0)进行安装,默认情况下禁用所有其他系列的子存储库。使用以下命令查看 MySQL Yum 存储库中的所有子存储库,并查看其中哪些子存储库已启用或禁用。

要安装最新GA系列的最新版本,不需要配置。要安装除最新GA系列外的特定系列的最新版本,请在运行安装命令之前执行以下命令禁用最新GA系列的子存储库,并启用特定系列的子存储库

[[email protected] ~]#  yum-config-manager --disable mysql57-community
[[email protected] ~]#  yum-config-manager --enable mysql80-community
           

3、安装MySQL

[[email protected] ~]# yum install mysql-community-server
////**这将安装MySQL服务器的软件包(mysql-community-server),也安装运行服务器所需的组件的软件包,包括客户端的软件包(mysql-community-client)、客户端和服务器的常见错误消息和字符集(mysql-community-common)以及共享客户端库(mysql-community-libs)**/////

Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:8.0.23-1.el6 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 8.0.23-1.el6 for package: mysql-community-server-8.0.23-1.el6.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 8.0.11 for package: mysql-community-server-8.0.23-1.el6.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:8.0.23-1.el6 will be installed
--> Processing Dependency: mysql-community-client-plugins = 8.0.23-1.el6 for package: mysql-community-client-8.0.23-1.el6.x86_64
--> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.11 for package: mysql-community-client-8.0.23-1.el6.x86_64
---> Package mysql-community-common.x86_64 0:8.0.23-1.el6 will be installed
--> Running transaction check
---> Package mysql-community-client-plugins.x86_64 0:8.0.23-1.el6 will be installed
---> Package mysql-community-libs.x86_64 0:8.0.23-1.el6 will be obsoleting
---> Package mysql-libs.x86_64 0:5.1.73-7.el6 will be obsoleted
--> Processing Dependency: libmysqlclient.so.16()(64bit) for package: 2:postfix-2.6.6-6.el6_7.1.x86_64
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: 2:postfix-2.6.6-6.el6_7.1.x86_64
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:8.0.23-1.el6 will be obsoleting
---> Package postfix.x86_64 2:2.6.6-6.el6_7.1 will be updated
---> Package postfix.x86_64 2:2.6.6-8.el6 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================
 Package                                          Arch                     Version                           Repository                           Size
=======================================================================================================================================================
Installing:
 mysql-community-libs                             x86_64                   8.0.23-1.el6                      mysql80-community                   4.8 M
     replacing  mysql-libs.x86_64 5.1.73-7.el6
 mysql-community-libs-compat                      x86_64                   8.0.23-1.el6                      mysql80-community                   1.7 M
     replacing  mysql-libs.x86_64 5.1.73-7.el6
 mysql-community-server                           x86_64                   8.0.23-1.el6                      mysql80-community                   561 M
Installing for dependencies:
 mysql-community-client                           x86_64                   8.0.23-1.el6                      mysql80-community                    49 M
 mysql-community-client-plugins                   x86_64                   8.0.23-1.el6                      mysql80-community                   239 k
 mysql-community-common                           x86_64                   8.0.23-1.el6                      mysql80-community                   812 k
Updating for dependencies:
 postfix                                          x86_64                   2:2.6.6-8.el6                     base                                2.0 M

Transaction Summary
=======================================================================================================================================================
Install       6 Package(s)
Upgrade       1 Package(s)

Total download size: 620 M
Is this ok [y/N]: y
Downloading Packages:
(1/7): mysql-community-client-8.0.23-1.el6.x86_64.rpm                                                                           |  49 MB     00:09     
(2/7): mysql-community-client-plugins-8.0.23-1.el6.x86_64.rpm                                                                   | 239 kB     00:00     
(3/7): mysql-community-common-8.0.23-1.el6.x86_64.rpm                                                                           | 812 kB     00:00     
(4/7): mysql-community-libs-8.0.23-1.el6.x86_64.rpm                                                                             | 4.8 MB     00:01     
(5/7): mysql-community-libs-compat-8.0.23-1.el6.x86_64.rpm                                                                      | 1.7 MB     00:00     
(6/7): mysql-community-server-8.0.23-1.el6.x86_64.rpm                                                                           | 561 MB     02:06     
(7/7): postfix-2.6.6-8.el6.x86_64.rpm                                                                                           | 2.0 MB     00:00     
-------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                  4.4 MB/s | 620 MB     02:21     
warning: rpmts_HdrFromFdno: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid : MySQL Release Engineering <mysql-[email protected].oracle.com>
 Package: mysql80-community-release-el6-3.noarch (@/mysql80-community-release-el6-3.noarch)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mysql-community-client-plugins-8.0.23-1.el6.x86_64                                                                                  1/9 
  Installing : mysql-community-common-8.0.23-1.el6.x86_64                                                                                          2/9 
  Installing : mysql-community-libs-8.0.23-1.el6.x86_64                                                                                            3/9 
  Installing : mysql-community-client-8.0.23-1.el6.x86_64                                                                                          4/9 
  Installing : mysql-community-libs-compat-8.0.23-1.el6.x86_64                                                                                     5/9 
  Updating   : 2:postfix-2.6.6-8.el6.x86_64                                                                                                        6/9 
  Installing : mysql-community-server-8.0.23-1.el6.x86_64                                                                                          7/9 
  Cleanup    : 2:postfix-2.6.6-6.el6_7.1.x86_64                                                                                                    8/9 
  Erasing    : mysql-libs-5.1.73-7.el6.x86_64                                                                                                      9/9 
  Verifying  : mysql-community-libs-8.0.23-1.el6.x86_64                                                                                            1/9 
  Verifying  : mysql-community-common-8.0.23-1.el6.x86_64                                                                                          2/9 
  Verifying  : 2:postfix-2.6.6-8.el6.x86_64                                                                                                        3/9 
  Verifying  : mysql-community-client-plugins-8.0.23-1.el6.x86_64                                                                                  4/9 
  Verifying  : mysql-community-client-8.0.23-1.el6.x86_64                                                                                          5/9 
  Verifying  : mysql-community-server-8.0.23-1.el6.x86_64                                                                                          6/9 
  Verifying  : mysql-community-libs-compat-8.0.23-1.el6.x86_64                                                                                     7/9 
  Verifying  : mysql-libs-5.1.73-7.el6.x86_64                                                                                                      8/9 
  Verifying  : 2:postfix-2.6.6-6.el6_7.1.x86_64                                                                                                    9/9 

Installed:
  mysql-community-libs.x86_64 0:8.0.23-1.el6     mysql-community-libs-compat.x86_64 0:8.0.23-1.el6     mysql-community-server.x86_64 0:8.0.23-1.el6    

Dependency Installed:
  mysql-community-client.x86_64 0:8.0.23-1.el6   mysql-community-client-plugins.x86_64 0:8.0.23-1.el6   mysql-community-common.x86_64 0:8.0.23-1.el6  

Dependency Updated:
  postfix.x86_64 2:2.6.6-8.el6                                                                                                                         

Replaced:
  mysql-libs.x86_64 0:5.1.73-7.el6                                                                                                                     

Complete!
           

4、启动MySQL

[[email protected] ~]# /etc/init.d/mysqld start
Initializing MySQL database:                               [  OK  ]
Starting mysqld:                                           [  OK  ]
           

5、查看MySQL状态

[[email protected] ~]# /etc/init.d/mysqld status
mysqld (pid  3356) is running...
           

6、查看MySQL初始密码并尝试登陆MySQL

[[email protected] ~]# grep 'temporary password' /var/log/mysqld.log
2021-02-23T00:57:56.719137Z 6 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: UpNhalqgo6+6
[[email protected] ~]# mysql -uroot -p"UpNhalqgo6+6"
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.23

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
           

7、修改密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '[email protected]';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
           

报错原因:不符合密码策略。以下方式解决:

mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password.length=4;
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '[email protected]';
Query OK, 0 rows affected (0.04 sec)
           

8、使用新密码登陆MySQL数据库

[[email protected] ~]# mysql -uroot [email protected]
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
           

参考网站:https://www.mysql.com