图解 Centos7.5 环境下安装 MySQL5.7版本数据库

Step1 : 先检查当前系统中是否存在mysql相关信息。

yum list installed | grep mysql
yum -y remove mysql-libs.x86_64

Step2: 下载mysql5.7 的rpm包

wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
[maxwell@mysqlmaster software]$ wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
--2022-10-14 21:23:36--  https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 23.76.83.234, 2600:140b:10:1099::2e31, 2600:140b:10:1083::2e31
Connecting to dev.mysql.com (dev.mysql.com)|23.76.83.234|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm [following]
--2022-10-14 21:23:37--  https://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.36.253.13
Connecting to repo.mysql.com (repo.mysql.com)|23.36.253.13|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9224 (9.0K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-9.noarch.rpm’

100%[=====================================================================================================================================================================>] 9,224       --.-K/s   in 0s      

2022-10-14 21:23:38 (268 MB/s) - ‘mysql57-community-release-el7-9.noarch.rpm’ saved [9224/9224]

[maxwell@mysqlmaster software]$

Step3: 安装rpm包

rpm -ivh mysql57-community-release-el7-9.noarch.rpm
[root@mysqlmaster software]# rpm -ivh mysql57-community-release-el7-9.noarch.rpm
warning: mysql57-community-release-el7-9.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql57-community-release-el7-9  ################################# [100%]
[root@mysqlmaster software]# 

Step4:完成Step3后会在/etc/yum.repos.d/目录下生成两个repo文件:

  • mysql-community.repo
  • mysql-community-source.repo
[root@mysqlmaster software]# ls -ltr /etc/yum.repos.d/
total 48
-rw-r--r--. 1 root root 1440 Sep 12  2016 mysql-community-source.repo
-rw-r--r--. 1 root root 1416 Sep 12  2016 mysql-community.repo
-rw-r--r--. 1 root root 1050 Oct  3  2017 epel-testing.repo
-rw-r--r--. 1 root root  951 Oct  3  2017 epel.repo
-rw-r--r--. 1 root root 4768 Apr 29  2018 CentOS-Vault.repo
-rw-r--r--. 1 root root 1331 Apr 29  2018 CentOS-Sources.repo
-rw-r--r--. 1 root root  630 Apr 29  2018 CentOS-Media.repo
-rw-r--r--. 1 root root  314 Apr 29  2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  649 Apr 29  2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 1309 Apr 29  2018 CentOS-CR.repo
-rw-r--r--. 1 root root 1664 Apr 29  2018 CentOS-Base.repo
[root@mysqlmaster software]# s

Step 5: yum安装 mysql-server

FYI :必须进入到 /etc/yum.repos.d/目录后再执行以下脚本

cd /etc/yum.repos.d/
yum install mysql-server
[root@mysqlmaster software]# cd /etc/yum.repos.d/
[root@mysqlmaster yum.repos.d]# yum install mysql-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.bupt.edu.cn
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.bfsu.edu.cn
 * updates: mirrors.bupt.edu.cn
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     
(1/3): mysql-tools-community/x86_64/primary_db                                                                                                                                          |  89 kB  00:00:00     
(2/3): mysql-connectors-community/x86_64/primary_db                                                                                                                                     |  93 kB  00:00:01     
(3/3): mysql57-community/x86_64/primary_db                                                                                                                                              | 325 kB  00:00:01     
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.40-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.40-1.el7 for package: mysql-community-server-5.7.40-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.40-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.40-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.40-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.40-1.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be obsoleted
--> 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-libs.x86_64 0:5.7.40-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.40-1.el7 will be obsoleting
---> Package postfix.x86_64 2:2.10.1-6.el7 will be updated
---> Package postfix.x86_64 2:2.10.1-9.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================================
 Package                                                      Arch                                    Version                                         Repository                                          Size
===============================================================================================================================================================================================================
Installing:
 mysql-community-libs                                         x86_64                                  5.7.40-1.el7                                    mysql57-community                                  2.6 M
     replacing  mariadb-libs.x86_64 1:5.5.56-2.el7
 mysql-community-libs-compat                                  x86_64                                  5.7.40-1.el7                                    mysql57-community                                  1.2 M
     replacing  mariadb-libs.x86_64 1:5.5.56-2.el7
 mysql-community-server                                       x86_64                                  5.7.40-1.el7                                    mysql57-community                                  178 M
Installing for dependencies:
 mysql-community-client                                       x86_64                                  5.7.40-1.el7                                    mysql57-community                                   28 M
 mysql-community-common                                       x86_64                                  5.7.40-1.el7                                    mysql57-community                                  311 k
Updating for dependencies:
 postfix                                                      x86_64                                  2:2.10.1-9.el7                                  base                                               2.4 M

Transaction Summary
===============================================================================================================================================================================================================
Install  3 Packages (+2 Dependent packages)
Upgrade             ( 1 Dependent package)

Total size: 213 M
Total download size: 211 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.40-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY           ]  0.0 B/s | 119 kB  --:--:-- ETA 
Public key for mysql-community-common-5.7.40-1.el7.x86_64.rpm is not installed
(1/5): mysql-community-common-5.7.40-1.el7.x86_64.rpm                                                                                                                                   | 311 kB  00:00:01     
(2/5): mysql-community-libs-5.7.40-1.el7.x86_64.rpm                                                                                                                                     | 2.6 MB  00:00:02     
(3/5): mysql-community-libs-compat-5.7.40-1.el7.x86_64.rpm                                                                                                                              | 1.2 MB  00:00:00     
(4/5): mysql-community-client-5.7.40-1.el7.x86_64.rpm                                                                                                                                   |  28 MB  00:00:17     
(5/5): mysql-community-server-5.7.40-1.el7.x86_64.rpm                                                                                                                                   | 178 MB  00:01:20     
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                          2.5 MB/s | 211 MB  00:01:24     
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-9.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y


Public key for mysql-community-client-5.7.40-1.el7.x86_64.rpm is not installed


 Failing package is: mysql-community-client-5.7.40-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[root@mysqlmaster yum.repos.d]#

Step 6: 修复  Step5 报错问题

 Failing package is: mysql-community-client-5.7.40-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
yum install -y mysql-community-server
[root@mysqlmaster yum.repos.d]# 
[root@mysqlmaster yum.repos.d]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
[root@mysqlmaster yum.repos.d]# yum install -y mysql-community-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.bfsu.edu.cn
 * updates: mirrors.bupt.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.40-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.40-1.el7 for package: mysql-community-server-5.7.40-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.40-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.40-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.40-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.40-1.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be obsoleted
--> 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-libs.x86_64 0:5.7.40-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.40-1.el7 will be obsoleting
---> Package postfix.x86_64 2:2.10.1-6.el7 will be updated
---> Package postfix.x86_64 2:2.10.1-9.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================================
 Package                                                      Arch                                    Version                                         Repository                                          Size
===============================================================================================================================================================================================================
Installing:
 mysql-community-libs                                         x86_64                                  5.7.40-1.el7                                    mysql57-community                                  2.6 M
     replacing  mariadb-libs.x86_64 1:5.5.56-2.el7
 mysql-community-libs-compat                                  x86_64                                  5.7.40-1.el7                                    mysql57-community                                  1.2 M
     replacing  mariadb-libs.x86_64 1:5.5.56-2.el7
 mysql-community-server                                       x86_64                                  5.7.40-1.el7                                    mysql57-community                                  178 M
Installing for dependencies:
 mysql-community-client                                       x86_64                                  5.7.40-1.el7                                    mysql57-community                                   28 M
 mysql-community-common                                       x86_64                                  5.7.40-1.el7                                    mysql57-community                                  311 k
Updating for dependencies:
 postfix                                                      x86_64                                  2:2.10.1-9.el7                                  base                                               2.4 M

Transaction Summary
===============================================================================================================================================================================================================
Install  3 Packages (+2 Dependent packages)
Upgrade             ( 1 Dependent package)

Total size: 213 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 9 pre-existing rpmdb problem(s), 'yum check' output follows:
icedtea-web-1.7.1-1.el7.x86_64 has missing requires of java-1.8.0-openjdk
icedtea-web-1.7.1-1.el7.x86_64 has missing requires of jpackage-utils
icedtea-web-1.7.1-1.el7.x86_64 has missing requires of jpackage-utils
jline-1.0-8.el7.noarch has missing requires of java >= ('0', '1.5', None)
jline-1.0-8.el7.noarch has missing requires of jpackage-utils
rhino-1.7R5-1.el7.noarch has missing requires of jpackage-utils
rhino-1.7R5-1.el7.noarch has missing requires of jpackage-utils
tagsoup-1.2.1-8.el7.noarch has missing requires of jpackage-utils
tagsoup-1.2.1-8.el7.noarch has missing requires of jpackage-utils >= ('0', '1.6', None)
  Installing : mysql-community-common-5.7.40-1.el7.x86_64                                                                                                                                                  1/8 
  Installing : mysql-community-libs-5.7.40-1.el7.x86_64                                                                                                                                                    2/8 
  Installing : mysql-community-client-5.7.40-1.el7.x86_64                                                                                                                                                  3/8 
  Installing : mysql-community-libs-compat-5.7.40-1.el7.x86_64                                                                                                                                             4/8 
  Updating   : 2:postfix-2.10.1-9.el7.x86_64                                                                                                                                                               5/8 
  Installing : mysql-community-server-5.7.40-1.el7.x86_64                                                                                                                                                  6/8 
  Cleanup    : 2:postfix-2.10.1-6.el7.x86_64                                                                                                                                                               7/8 
  Erasing    : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                                                                                                          8/8 
  Verifying  : mysql-community-client-5.7.40-1.el7.x86_64                                                                                                                                                  1/8 
  Verifying  : mysql-community-server-5.7.40-1.el7.x86_64                                                                                                                                                  2/8 
  Verifying  : mysql-community-common-5.7.40-1.el7.x86_64                                                                                                                                                  3/8 
  Verifying  : mysql-community-libs-5.7.40-1.el7.x86_64                                                                                                                                                    4/8 
  Verifying  : mysql-community-libs-compat-5.7.40-1.el7.x86_64                                                                                                                                             5/8 
  Verifying  : 2:postfix-2.10.1-9.el7.x86_64                                                                                                                                                               6/8 
  Verifying  : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                                                                                                          7/8 
  Verifying  : 2:postfix-2.10.1-6.el7.x86_64                                                                                                                                                               8/8 

Installed:
  mysql-community-libs.x86_64 0:5.7.40-1.el7                       mysql-community-libs-compat.x86_64 0:5.7.40-1.el7                       mysql-community-server.x86_64 0:5.7.40-1.el7                      

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.40-1.el7                                                           mysql-community-common.x86_64 0:5.7.40-1.el7                                                          

Dependency Updated:
  postfix.x86_64 2:2.10.1-9.el7                                                                                                                                                                                

Replaced:
  mariadb-libs.x86_64 1:5.5.56-2.el7                                                                                                                                                                           

Complete!
[root@mysqlmaster yum.repos.d]# 

Step 7 : 启动

systemctl enable mysqld // 开机启动
systemctl start mysqld
[root@mysqlmaster yum.repos.d]# systemctl enable mysqld
[root@mysqlmaster yum.repos.d]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
[root@mysqlmaster yum.repos.d]# systemctl start mysqld 
[root@mysqlmaster yum.repos.d]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-10-14 21:56:13 CST; 38s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 5096 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 5037 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 5099 (mysqld)
    Tasks: 27
   CGroup: /system.slice/mysqld.service
           └─5099 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Oct 14 21:55:56 mysqlmaster systemd[1]: Starting MySQL Server...
Oct 14 21:56:13 mysqlmaster systemd[1]: Started MySQL Server.
[root@mysqlmaster yum.repos.d]# 

Step 8 : 获取 临时登录密码

[root@mysqlmaster yum.repos.d]# grep 'temporary password' /var/log/mysqld.log
2022-10-14T13:56:09.143492Z 1 [Note] A temporary password is generated for root@localhost: sit.8!Zq43Fv
[root@mysqlmaster yum.repos.d]# 

Note: 若未获取到临时密码,则删除之前安装mysql的残留数据,重启mysql

rm -rf /var/lib/mysql

systemctl restart mysqld

Step 9: 登录(临时密码登录)

[root@mysqlmaster yum.repos.d]# 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.40

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> 

Step 10 . 重置 密码

查看 mysql 初始的密码策略

mysql> 
mysql> SHOW VARIABLES LIKE 'validate_password%';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set global validate_password_length=6;
Query OK, 0 rows affected (0.00 sec)

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

mysql> set password for root@localhost = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> 

Step 11.远程连接前的设置

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> 
mysql> update user set Host='%' where User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> 
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host from user where user='root';
+------+
| host |
+------+
| %    |
+------+
1 row in set (0.00 sec)

mysql> 

把allowPublicKeyRetrieval的值设为TRUE

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值