第一次在網上寫文檔,心亂如麻,文檔根據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