1. Obtain the Yum Repository Configuration
First, download the MySQL rpeository configuration package from a domestic mirror source:
100%[=======================================================================================================================================================================>] 26,024 26.9KB/s in 0.9s
2023-11-15 14:32:47 (26.9 KB/s) - Saved 'mysql80-community-release-el7-3.noarch.rpm' [26024/26024])
[root@database-server ~]# ls mysql80-community-release-el7-3.noarch.rpm [root@database-server ~]# ll total 28 -rw-r--r--. 1 root root 26024 Nov 15 2019 mysql80-community-release-el7-3.noarch.rpm [root@database-server ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm warning: mysql80-community-release-el7-3.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql80-community-release-el7-3 ################################# [100%]
</div>### 2. Install MySQL via Yum
Now install the MySQL server package using yum:
<div class="code-block">```
[root@database-server ~]# yum install mysql-server
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
mysql-connectors-community | 2.6 kB 00:00:00
mysql-tools-community | 2.6 kB 00:00:00
mysql80-community | 2.6 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/3): mysql-connectors-community/x86_64/primary_db | 77 kB 00:00:02
(2/3): mysql80-community/x86_64/primary_db | 153 kB 00:00:02
(3/3): mysql-tools-community/x86_64/primary_db | 87 kB 00:00:03
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:8.0.24-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 8.0.24-1.el7 for package: mysql-community-server-8.0.24-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 8.0.11 for package: mysql-community-server-8.0.24-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:8.0.24-1.el7 will be installed
--> Processing Dependency: mysql-community-client-plugins = 8.0.24-1.el7 for package: mysql-community-client-8.0.24-1.el7.x86_64
--> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.11 for package: mysql-community-client-8.0.24-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-common.x86_64 0:8.0.24-1.el7 will be installed
--> Processing Dependency: mariadb-libs.x86_64 1:5.5.68-1.el7 for package: mysql-community-common-8.0.24-1.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
---> Package mysql-community-client-plugins.x86_64 0:8.0.24-1.el7 will be installed
---> Package mysql-community-libs.x86_64 0:8.0.24-1.el7 will be installed
---> Package mysql-community-libs-compat.x86_64 0:8.0.24-1.el7 will be installed
---> Package postfix.x86_64 2:2.10.1-9.el7 will be updated
--> Running transaction check
---> Package postfix.x86_64 2:2.10.1-6.el7 will be obsoleted
--> Finished Dependency Resolution
=================================================================================================================================================================================================================
Package Architecture Version Repository Size
=================================================================================================================================================================================================================
Installing:
mysql-community-libs x86_64 8.0.24-1.el7 mysql80-community 4.0 M
Replacing mariadb-libs.x86_64 1:5.5.68-1.el7
mysql-community-libs-compat x86_64 8.0.24-1.el7 mysql80-community 1.2 M
Replacing mariadb-libs.x86_64 1:5.5.68-1.el7
mysql-community-server x86_64 8.0.24-1.el7 mysql80-community 428 M
Installing for dependencies:
mysql-community-client x86_64 8.0.24-1.el7 mysql80-community 45 M
mysql-community-client-plugins x86_64 8.0.24-1.el7 mysql80-community 189 k
mysql-community-common x86_64 8.0.24-1.el7 mysql80-community 614 k
Updating for dependencies:
postfix x86_64 2:2.10.1-9.el7 base 2.4 M
Transaction Summary
=================================================================================================================================================================================================================
Install 3 Packages (+3 Dependent packages)
Upgrade ( 1 Dependent package)
Total download size: 482 M
Is this ok [y/d/N]: y
Downloading packages:
No Presto metadata available for base
warning: /var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-client-plugins-8.0.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY ] 130 kB/s | 150 kB 01:03:19 ETA
Public key for mysql-community-client-plugins-8.0.24-1.el7.x86_64.rpm is not installed
(1/7): mysql-community-client-plugins-8.0.24-1.el7.x86_64.rpm | 189 kB 00:00:01
(2/7): mysql-community-common-8.0.24-1.el7.x86_64.rpm | 614 kB 00:00:01
(3/7): mysql-community-libs-8.0.24-1.el7.x86_64.rpm | 4.0 MB 00:00:03
(4/7): mysql-community-libs-compat-8.0.24-1.el7.x86_64.rpm | 1.2 MB 00:00:00
(5/7): postfix-2.10.1-9.el7.x86_64.rpm | 2.4 MB 00:00:09
(6/7): mysql-community-client-8.0.24-1.el7.x86_64.rpm | 45 MB 00:02:24
(7/7): mysql-community-server-8.0.24-1.el7.x86_64.rpm | 428 MB 00:06:02
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 1.3 MB/s | 482 MB 00:06:08
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
User ID : "MySQL Release Engineering <mysql-build>"
Fingerprint : a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
Package : mysql80-community-release-el7-3.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
warning: RPM database has been modified outside yum.
Installing : mysql-community-client-plugins-8.0.24-1.el7.x86_64 1/9
Installing : mysql-community-common-8.0.24-1.el7.x86_64 2/9
Installing : mysql-community-libs-8.0.24-1.el7.x86_64 3/9
Installing : mysql-community-libs-compat-8.0.24-1.el7.x86_64 4/9
Installing : mysql-community-client-8.0.24-1.el7.x86_64 5/9
Installing : mysql-community-server-8.0.24-1.el7.x86_64 6/9
Updating : 2:postfix-2.10.1-9.el7.x86_64 7/9
Cleaning : 2:postfix-2.10.1-6.el7.x86_64 8/9
Removing : 1:mariadb-libs-5.5.68-1.el7.x86_64 9/9
Verifying : mysql-community-server-8.0.24-1.el7.x86_64 1/9
Verifying : mysql-community-libs-8.0.24-1.el7.x86_64 2/9
Verifying : mysql-community-common-8.0.24-1.el7.x86_64 3/9
Verifying : 2:postfix-2.10.1-9.el7.x86_64 4/9
Verifying : mysql-community-libs-compat-8.0.24-1.el7.x86_64 5/9
Verifying : mysql-community-client-plugins-8.0.24-1.el7.x86_64 6/9
Verifying : mysql-community-client-8.0.24-1.el7.x86_64 7/9
Verifying : 1:mariadb-libs-5.5.68-1.el7.x86_64 8/9
Verifying : 2:postfix-2.10.1-6.el7.x86_64 9/9
Installed:
mysql-community-libs.x86_64 0:8.0.24-1.el7 mysql-community-libs-compat.x86_64 0:8.0.24-1.el7 mysql-community-server.x86_64 0:8.0.24-1.el7
As dependencies:
mysql-community-client.x86_64 0:8.0.24-1.el7 mysql-community-client-plugins.x86_64 0:8.0.24-1.el7 mysql-community-common.x86_64 0:8.0.24-1.el7
As updated:
postfix.x86_64 2:2.10.1-9.el7
Replaced:
mariadb-libs.x86_64 1:5.5.68-1.el7
Complete!
[root@database-server ~]#
</mysql-build>
After installation, start the MySQL service:
</div>### 4. Initialize Database
Initialize the MySQL database:
<div class="code-block">```
mysqld --initialize
Check the MySQL log file to find the temporary root password:
</div>### 6. Login and Reset Root Password
Login to MySQL with the temporary password and reset the root password:
<div class="code-block">```
[root@database-server ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.24
Copyright (c) 2000, 2023, 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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@localhost identified by 'My_RootPs2';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> alter user 'root'@localhost identified by 'My_RootPs2';
Query OK, 0 rows affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
Final, create a database and a user with appropriate permissions:
mysql> create user 'hive'@'%' identified by 'Hive_Ps2'; Query OK, 0 rows affected (0.02 sec)
mysql> grant all on hivemetastore to 'hive'@'%'; ERROR 1046 (3D000): No database selected mysql> grant all on hivemetastore.* to 'hive'@'%'; Query OK, 0 rows affected (0.01 sec)
mysql>
</div></div>