1.下载rpm安装包
[root@VM-4-17-centos ~]# wget https://repo.mysql.com/mysql57-community-release-el7.rpm
--2022-05-11 00:08:38-- https://repo.mysql.com/mysql57-community-release-el7.rpm
Resolving repo.mysql.com (repo.mysql.com)... 104.90.24.228
Connecting to repo.mysql.com (repo.mysql.com)|104.90.24.228|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25680 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7.rpm’
100%[==========================================================================================>] 25,680 --.-K/s in 0s
2022-05-11 00:08:48 (238 MB/s) - ‘mysql57-community-release-el7.rpm’ saved [25680/25680]
[root@VM-4-17-centos ~]# ls
mysql57-community-release-el7.rpm
2.安装rpm包
rpm -ivh mysql57-community-release-el7.rpm
warning: mysql57-community-release-el7.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql57-community-release-el7-11 ################################# [100%]
[root@VM-4-17-centos ~]# yum install mysql-server
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
mysql-connectors-community | 2.6 kB 00:00:02
mysql-tools-community | 2.6 kB 00:00:00
mysql57-community | 2.6 kB 00:00:00
os | 3.6 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/3): mysql-tools-community/x86_64/primary_db | 86 kB 00:00:01
(2/3): mysql57-community/x86_64/primary_db | 306 kB 00:00:01
(3/3): mysql-connectors-community/x86_64/primary_db | 87 kB 00:00:02
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.38-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.38-1.el7 for package: mysql-community-server-5.7.38-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.38-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.38-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.38-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.38-1.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.68-1.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
---> Package mysql-community-libs.x86_64 0:5.7.38-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.38-1.el7 will be obsoleting
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================
Installing:
mysql-community-libs x86_64 5.7.38-1.el7 mysql57-community 2.6 M
replacing mariadb-libs.x86_64 1:5.5.68-1.el7
mysql-community-libs-compat x86_64 5.7.38-1.el7 mysql57-community 1.2 M
replacing mariadb-libs.x86_64 1:5.5.68-1.el7
mysql-community-server x86_64 5.7.38-1.el7 mysql57-community 178 M
Installing for dependencies:
mysql-community-client x86_64 5.7.38-1.el7 mysql57-community 28 M
mysql-community-common x86_64 5.7.38-1.el7 mysql57-community 311 k
Transaction Summary
====================================================================================================================================
Install 3 Packages (+2 Dependent packages)
Total download size: 209 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.38-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Public key for mysql-community-common-5.7.38-1.el7.x86_64.rpm is not installed
(1/5): mysql-community-common-5.7.38-1.el7.x86_64.rpm | 311 kB 00:00:03
(2/5): mysql-community-libs-5.7.38-1.el7.x86_64.rpm | 2.6 MB 00:00:06
(3/5): mysql-community-libs-compat-5.7.38-1.el7.x86_64.rpm | 1.2 MB 00:00:05
(4/5): mysql-community-client-5.7.38-1.el7.x86_64.rpm | 28 MB 00:00:21
(5/5): mysql-community-server-5.7.38-1.el7.x86_64.r 35% [==============- ] 117 kB/s | 74 MB 00:19:40 ETA
3.安装mysql服务
yum install mysql-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel | 4.7 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
mysql57-community | 2.6 kB 00:00:00
os | 3.6 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/2): epel/7/x86_64/updateinfo | 1.0 MB 00:00:00
(2/2): epel/7/x86_64/primary_db | 7.0 MB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.38-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.38-1.el7 for package: mysql-community-server-5.7.38-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.38-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.38-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.38-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.38-1.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.68-1.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
---> Package mysql-community-libs.x86_64 0:5.7.38-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.38-1.el7 will be obsoleting
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================
Installing:
mysql-community-libs x86_64 5.7.38-1.el7 mysql57-community 2.6 M
replacing mariadb-libs.x86_64 1:5.5.68-1.el7
mysql-community-libs-compat x86_64 5.7.38-1.el7 mysql57-community 1.2 M
replacing mariadb-libs.x86_64 1:5.5.68-1.el7
mysql-community-server x86_64 5.7.38-1.el7 mysql57-community 178 M
Installing for dependencies:
mysql-community-client x86_64 5.7.38-1.el7 mysql57-community 28 M
mysql-community-common x86_64 5.7.38-1.el7 mysql57-community 311 k
Transaction Summary
====================================================================================================================================
Install 3 Packages (+2 Dependent packages)
Total size: 209 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-libs-compat-5.7.38-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
Package : mysql57-community-release-el7-11.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Public key for mysql-community-libs-compat-5.7.38-1.el7.x86_64.rpm is not installed
Failing package is: mysql-community-libs-compat-5.7.38-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
但是发现有报错
service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Failed to start mysqld.service: Unit not found.
升级下解决问题
rpm -ivh mysql57-community-release-el7.rpm
Preparing... ################################# [100%]
package mysql57-community-release-el7-11.noarch is already installed
[root@VM-4-17-centos ~]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
[root@VM-4-17-centos ~]# yum install mysql-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.38-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.38-1.el7 for package: mysql-community-server-5.7.38-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.38-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.38-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.38-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.38-1.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.68-1.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
---> Package mysql-community-libs.x86_64 0:5.7.38-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.38-1.el7 will be obsoleting
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================
Installing:
mysql-community-libs x86_64 5.7.38-1.el7 mysql57-community 2.6 M
replacing mariadb-libs.x86_64 1:5.5.68-1.el7
mysql-community-libs-compat x86_64 5.7.38-1.el7 mysql57-community 1.2 M
replacing mariadb-libs.x86_64 1:5.5.68-1.el7
mysql-community-server x86_64 5.7.38-1.el7 mysql57-community 178 M
Installing for dependencies:
mysql-community-client x86_64 5.7.38-1.el7 mysql57-community 28 M
mysql-community-common x86_64 5.7.38-1.el7 mysql57-community 311 k
Transaction Summary
====================================================================================================================================
Install 3 Packages (+2 Dependent packages)
Total size: 209 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : mysql-community-common-5.7.38-1.el7.x86_64 1/6
Installing : mysql-community-libs-5.7.38-1.el7.x86_64 2/6
Installing : mysql-community-client-5.7.38-1.el7.x86_64 3/6
Installing : mysql-community-server-5.7.38-1.el7.x86_64 4/6
Installing : mysql-community-libs-compat-5.7.38-1.el7.x86_64 5/6
Erasing : 1:mariadb-libs-5.5.68-1.el7.x86_64 6/6
Verifying : mysql-community-libs-compat-5.7.38-1.el7.x86_64 1/6
Verifying : mysql-community-client-5.7.38-1.el7.x86_64 2/6
Verifying : mysql-community-server-5.7.38-1.el7.x86_64 3/6
Verifying : mysql-community-libs-5.7.38-1.el7.x86_64 4/6
Verifying : mysql-community-common-5.7.38-1.el7.x86_64 5/6
Verifying : 1:mariadb-libs-5.5.68-1.el7.x86_64 6/6
Installed:
mysql-community-libs.x86_64 0:5.7.38-1.el7 mysql-community-libs-compat.x86_64 0:5.7.38-1.el7
mysql-community-server.x86_64 0:5.7.38-1.el7
Dependency Installed:
mysql-community-client.x86_64 0:5.7.38-1.el7 mysql-community-common.x86_64 0:5.7.38-1.el7
Replaced:
mariadb-libs.x86_64 1:5.5.68-1.el7
Complete!
4.启动服务成功
[root@VM-4-17-centos ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@VM-4-17-centos ~]# netstat -tanp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1590/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1171/master
tcp 0 0 10.0.4.17:22 221.182.0.210:34833 ESTABLISHED 17861/sshd: root [p
tcp 0 0 10.0.4.17:34540 169.254.0.55:5574 ESTABLISHED 1784/YDService
tcp 0 0 10.0.4.17:56282 169.254.0.138:8086 ESTABLISHED 1248/tat_agent
tcp 0 48 10.0.4.17:22 117.176.158.57:12669 ESTABLISHED 15446/sshd: root@pt
tcp 0 0 10.0.4.17:22 117.176.158.57:12678 ESTABLISHED 15448/sshd: root@no
tcp6 0 0 :::22 :::* LISTEN 1590/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1171/master
tcp6 0 0 :::3306 :::* LISTEN 17580/mysqld
[root@VM-4-17-centos ~]# grep "password" /var/log/mysqld.log
2022-05-11T14:19:59.592148Z 1 [Note] A temporary password is generated for root@localhost: i4jnM.-L_Mk4
[root@VM-4-17-centos ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.38
Copyright (c) 2000, 2022, 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>
5.修改一下密码
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@VM-4-17-centos ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.38 MySQL Community Server (GPL)
Copyright (c) 2000, 2022, 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>