【在阿里云的 Centos 8 上装 Mysql 的心酸历程】

在阿里云的 Centos 8 上装 Mysql 的心酸历程

前言 : 本打算在阿里云的服务器上装个mysql数据库, 本以为很顺利, 结果发现麻烦连连

  • 第一步 下载更新源: wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
[root@zenyLinux home]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
URL transformed to HTTPS due to an HSTS policy
--2022-05-01 20:18:01--  https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm [following]
--2022-05-01 20:18:02--  https://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.46.201.170
Connecting to repo.mysql.com (repo.mysql.com)|23.46.201.170|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9116 (8.9K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-8.noarch.rpm’

mysql57-community-release-el7-8.noarch. 100%[==============================================================================>]   8.90K  --.-KB/s    in 0s

2022-05-01 20:18:10 (94.9 MB/s) - ‘mysql57-community-release-el7-8.noarch.rpm’ saved [9116/9116]

  • 第二步安装 : yum localinstall mysql57-community-release-el7-8.noarch.rpm
[root@zenyLinux home]# yum localinstall mysql57-community-release-el7-8.noarch.rpm
Repository extras is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository epel is listed more than once in the configuration
CentOS-8 - AppStream                                                                                                           7.7 kB/s | 2.3 kB     00:00
Errors during downloading metadata for repository 'AppStream':
  - Status code: 404 for http://mirrors.cloud.aliyuncs.com/centos/8/AppStream/x86_64/os/repodata/repomd.xml (IP: 100.100.2.148)
Error: Failed to download metadata for repo 'AppStream': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

  • 这一步发生了问题…, 之前在本地的虚拟机装过都没问题的。 起初是以为版本的问题, 于是换个新版本mysql80-community-release-el8-4
[root@zenyLinux mysqlFile]# yum localinstall mysql80-community-release-el8-4.noarch.rpm
Repository epel is listed more than once in the configuration
CentOS-8 - AppStream                                                                                                           7.9 kB/s | 2.3 kB     00:00
Errors during downloading metadata for repository 'AppStream':
  - Status code: 404 for http://mirrors.cloud.aliyuncs.com/centos/8/AppStream/x86_64/os/repodata/repomd.xml (IP: 100.100.2.148)
Error: Failed to download metadata for repo 'AppStream': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
[root@zenyLinux home]# cd /etc/yum.repos.d/
[root@zenyLinux yum.repos.d]# ls -l
total 76
-rw-r--r-- 1 root root  635 Sep 14  2020 CentOS-AppStream.repo
-rw-r--r-- 1 root root  619 Sep 14  2020 CentOS-Base.repo
-rw-r--r-- 1 root root  701 Sep 14  2020 CentOS-centosplus.repo
-rw-r--r-- 1 root root 1329 Sep 14  2020 CentOS-CR.repo
-rw-r--r-- 1 root root  668 Sep 14  2020 CentOS-Debuginfo.repo
-rw-r--r-- 1 root root  227 Sep 14  2020 CentOS-epel.repo
-rw-r--r-- 1 root root  663 Sep 14  2020 CentOS-Extras.repo
-rw-r--r-- 1 root root  242 Sep 14  2020 CentOS-fasttrack.repo
-rw-r--r-- 1 root root    1 May  1 20:05 CentOS-Linux-AppStream.repo
-rw-r--r-- 1 root root 2495 Feb 14 21:16 CentOS-LinuxBaseOS.repo
-rw-r--r-- 1 root root  928 Sep 14  2020 CentOS-Media.repo
-rw-r--r-- 1 root root  639 Sep 14  2020 CentOS-PowerTools.repo
-rw-r--r-- 1 root root 1382 Sep 14  2020 CentOS-Sources.repo
-rw-r--r-- 1 root root   74 Sep 14  2020 CentOS-Vault.repo
-rw-r--r-- 1 root root 1485 Sep  5  2021 epel-modular.repo
-rw-r--r-- 1 root root 1564 Sep  5  2021 epel-playground.repo
-rw-r--r-- 1 root root 1422 Sep  5  2021 epel.repo
-rw-r--r-- 1 root root 1584 Sep  5  2021 epel-testing-modular.repo
-rw-r--r-- 1 root root 1521 Sep  5  2021 epel-testing.repo
[root@zenyLinux yum.repos.d]# mkdir bakup
[root@zenyLinux yum.repos.d]# mv *repo bakup/
[root@zenyLinux yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
--2022-05-01 20:22:05--  https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 106.15.218.233, 106.15.218.236, 106.15.218.229, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|106.15.218.233|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2495 (2.4K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’

/etc/yum.repos.d/CentOS-Base.repo       100%[==============================================================================>]   2.44K  --.-KB/s    in 0s

2022-05-01 20:22:05 (37.9 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2495/2495]

[root@zenyLinux yum.repos.d]# ll
total 8
drwxr-xr-x 2 root root 4096 May  1 20:21 bakup
-rw-r--r-- 1 root root 2495 Feb 14 21:16 CentOS-Base.repo
[root@zenyLinux yum.repos.d]# yum makecache
CentOS-8.5.2111 - Base - mirrors.aliyun.com                                                                                     12 MB/s | 4.6 MB     00:00
CentOS-8.5.2111 - Extras - mirrors.aliyun.com                                                                                   38 kB/s |  10 kB     00:00
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com                                                                                13 MB/s | 8.4 MB     00:00
Metadata cache created.
[root@zenyLinux yum.repos.d]# ll
total 8
drwxr-xr-x 2 root root 4096 May  1 20:21 bakup
-rw-r--r-- 1 root root 2495 Feb 14 21:16 CentOS-Base.repo
[root@zenyLinux yum.repos.d]#  yum install -y lrzsz
Last metadata expiration check: 0:00:59 ago on Sun 01 May 2022 08:22:51 PM CST.
Dependencies resolved.
===============================================================================================================================================================
 Package                            Architecture                        Version                                        Repository                         Size
===============================================================================================================================================================
Installing:
 lrzsz                              x86_64                              0.12.20-43.el8                                 base                               84 k

Transaction Summary
===============================================================================================================================================================
Install  1 Package

Total download size: 84 k
Installed size: 190 k
Downloading Packages:
lrzsz-0.12.20-43.el8.x86_64.rpm                                                                                                624 kB/s |  84 kB     00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                          616 kB/s |  84 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                       1/1
  Installing       : lrzsz-0.12.20-43.el8.x86_64                                                                                                           1/1
  Running scriptlet: lrzsz-0.12.20-43.el8.x86_64                                                                                                           1/1
  Verifying        : lrzsz-0.12.20-43.el8.x86_64                                                                                                           1/1

Installed:
  lrzsz-0.12.20-43.el8.x86_64

Complete!

  • ok, 解决了这一步的问题
[root@zenyLinux mysqlFile]# ls
mysql57-community-release-el7-8.noarch.rpm  mysql80-community-release-el8-4.noarch.rpm
[root@zenyLinux mysqlFile]# yum localinstall mysql80-community-release-el8-4.noarch.rpm
Last metadata expiration check: 0:02:14 ago on Sun 01 May 2022 08:22:51 PM CST.
Dependencies resolved.
===============================================================================================================================================================
 Package                                            Architecture                    Version                        Repository                             Size
===============================================================================================================================================================
Installing:
 mysql80-community-release                          noarch                          el8-4                          @commandline                           14 k

Transaction Summary
===============================================================================================================================================================
Install  1 Package

Total size: 14 k
Installed size: 8.6 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                       1/1
  Installing       : mysql80-community-release-el8-4.noarch                                                                                                1/1
  Verifying        : mysql80-community-release-el8-4.noarch                                                                                                1/1

Installed:
  mysql80-community-release-el8-4.noarch

Complete!

  • 但。。。。问题又来了
[root@zenyLinux mysqlFile]# yum install mysql-community-server
MySQL Connectors Community                                                                                                      55 kB/s |  49 kB     00:00
MySQL Tools Community                                                                                                          414 kB/s | 651 kB     00:01
MySQL 5.7 Community Server                                                                                                     202 kB/s | 2.6 MB     00:13
All matches were filtered out by modular filtering for argument: mysql-community-server
Error: Unable to find a match: mysql-community-server

  • 又出一个报错, 这时我又以为是版本的问题, 就打算把它卸了装旧版的mysql
  • 于是使用 yum remove 命令把它卸载了
[root@zenyLinux mysqlFile]# yum remove mysql80-community-release-el8-4.noarch
Dependencies resolved.
===============================================================================================================================================================
 Package                                           Architecture                   Version                          Repository                             Size
===============================================================================================================================================================
Removing:
 mysql80-community-release                         noarch                         el8-4                            @@commandline                         8.6 k

Transaction Summary
===============================================================================================================================================================
Remove  1 Package

Freed space: 8.6 k
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                       1/1
  Erasing          : mysql80-community-release-el8-4.noarch                                                                                                1/1
  Verifying        : mysql80-community-release-el8-4.noarch                                                                                                1/1

Removed:
  mysql80-community-release-el8-4.noarch

Complete!
[root@zenyLinux mysqlFile]# yum module disable mysql
Last metadata expiration check: 0:00:57 ago on Sun 01 May 2022 08:30:57 PM CST.
Dependencies resolved.
===============================================================================================================================================================
 Package                               Architecture                         Version                                Repository                             Size
===============================================================================================================================================================
Disabling modules:
 mysql

Transaction Summary
===============================================================================================================================================================

Is this ok [y/N]: y
Complete!
  • 接下来再试一遍 :
[root@zenyLinux mysqlFile]# yum install mysql-community-server
Last metadata expiration check: 0:01:27 ago on Sun 01 May 2022 08:30:57 PM CST.
Dependencies resolved.
===============================================================================================================================================================
 Package                                      Architecture                 Version                               Repository                               Size
===============================================================================================================================================================
Installing:
 mysql-community-server                       x86_64                       5.7.38-1.el7                          mysql57-community                       178 M
Installing 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
 mysql-community-libs                         x86_64                       5.7.38-1.el7                          mysql57-community                       2.6 M

Transaction Summary
===============================================================================================================================================================
Install  4 Packages

Total download size: 208 M
Installed size: 890 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): mysql-community-common-5.7.38-1.el7.x86_64.rpm                                                                          262 kB/s | 311 kB     00:01
(2/4): mysql-community-libs-5.7.38-1.el7.x86_64.rpm                                                                            1.4 MB/s | 2.6 MB     00:01
(3/4): mysql-community-client-5.7.38-1.el7.x86_64.rpm                                                                          5.6 MB/s |  28 MB     00:04
(4/4): mysql-community-server-5.7.38-1.el7.x86_64.rpm                                                                           10 MB/s | 178 MB     00:17
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                           11 MB/s | 208 MB     00:18
warning: /var/cache/dnf/mysql57-community-65b9ecb4cc6a2553/packages/mysql-community-client-5.7.38-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
MySQL 5.7 Community Server                                                                                                     5.7 MB/s | 5.8 kB     00:00
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: A4A9 4068 76FC BD3C 4567 70C8 8C71 8D3B 5072 E1F5
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Key imported successfully
Import of key(s) didn't help, wrong key(s)?
Public key for mysql-community-client-5.7.38-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-client-5.7.38-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-common-5.7.38-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-common-5.7.38-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-libs-5.7.38-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-libs-5.7.38-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-server-5.7.38-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-server-5.7.38-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'yum clean packages'.
Error: GPG check FAILED

  • 焯, 又出现新问题, 真是问题解决一个又来一个, 好家伙等于白做功

  • 按着它的提示 : 清除缓存的包 yum clean packages

  • [root@zenyLinux mysqlFile]# yum clean packages
    4 files removed
    [root@zenyLinux mysqlFile]# yum install mysql-community-server
    
    
  • 发现并没有卵用

  • 顺着报错去搜索, 参考Error: GPG check FAILED

    • 这由于源key错误导致的 yum(软件包管理器)安装软件失败。
    • 直接输入 yum install mysql-community-server --nogpgcheck
[root@zenyLinux mysqlFile]# yum install mysql-community-server --nogpgcheck
Last metadata expiration check: 0:11:17 ago on Sun 01 May 2022 08:30:57 PM CST.
Dependencies resolved.
===============================================================================================================================================================
 Package                                      Architecture                 Version                               Repository                               Size
===============================================================================================================================================================
Installing:
 mysql-community-server                       x86_64                       5.7.38-1.el7                          mysql57-community                       178 M
Installing 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
 mysql-community-libs                         x86_64                       5.7.38-1.el7                          mysql57-community                       2.6 M

Transaction Summary
===============================================================================================================================================================
Install  4 Packages

Total size: 208 M
Installed size: 890 M
Is this ok [y/N]: y
Downloading Packages:
[SKIPPED] mysql-community-client-5.7.38-1.el7.x86_64.rpm: Already downloaded
[SKIPPED] mysql-community-common-5.7.38-1.el7.x86_64.rpm: Already downloaded
[SKIPPED] mysql-community-libs-5.7.38-1.el7.x86_64.rpm: Already downloaded
[SKIPPED] mysql-community-server-5.7.38-1.el7.x86_64.rpm: Already downloaded
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                       1/1
  Installing       : mysql-community-common-5.7.38-1.el7.x86_64                                                                                            1/4
  Installing       : mysql-community-libs-5.7.38-1.el7.x86_64                                                                                              2/4
  Running scriptlet: mysql-community-libs-5.7.38-1.el7.x86_64                                                                                              2/4
  Installing       : mysql-community-client-5.7.38-1.el7.x86_64                                                                                            3/4
  Running scriptlet: mysql-community-server-5.7.38-1.el7.x86_64                                                                                            4/4
  Installing       : mysql-community-server-5.7.38-1.el7.x86_64                                                                                            4/4
  Running scriptlet: mysql-community-server-5.7.38-1.el7.x86_64                                                                                            4/4
  Verifying        : mysql-community-client-5.7.38-1.el7.x86_64                                                                                            1/4
  Verifying        : mysql-community-common-5.7.38-1.el7.x86_64                                                                                            2/4
  Verifying        : mysql-community-libs-5.7.38-1.el7.x86_64                                                                                              3/4
  Verifying        : mysql-community-server-5.7.38-1.el7.x86_64                                                                                            4/4

Installed:
  mysql-community-client-5.7.38-1.el7.x86_64           mysql-community-common-5.7.38-1.el7.x86_64           mysql-community-libs-5.7.38-1.el7.x86_64
  mysql-community-server-5.7.38-1.el7.x86_64

Complete!

  • 很快啊, 就安装完了

  • 接下来

    • 启动MySQL服务 : systemctl start mysqld

    • 设置开机启动 : systemctl enable mysqld

    • 重新加载系统配置 : systemctl daemon-reload

[root@zenyLinux mysqlFile]# systemctl start mysqld
[root@zenyLinux mysqlFile]# systemctl enable mysqld
[root@zenyLinux mysqlFile]# systemctl daemon-reload

  • 修改root本地登录密码

    • 查看mysql密码 : grep "temporary password" /var/log/mysqld.log ,该随机密码待会连接Mysql数据库要用上
  • 连接mysql

    • mysql -u root -p
[root@zenyLinux mysqlFile]# grep "temporary password" /var/log/mysqld.log
2022-05-01T12:43:53.204071Z 1 [Note] A temporary password is generated for root@localhost: tkt&WpsQI6uG
[root@zenyLinux mysqlFile]# 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> 
  • OK, 连接成功

  • 修改mysql的root密码

    • 使用刚刚的随机密码登录进去
    • 使用该命令 set password for 'root'@'localhost'=password('xxxxxxx'); 修改密码, # xxxxxx处是设置的密码
[root@zenyLinux mysqlFile]# 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> set password for 'root'@'localhost'=password('xxxxxxxxx');  # xxxxxx处是设置的密码
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye


  • 退出mysql , 试试有没有改密成功

  • [root@zenyLinux mysqlFile]# mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 4
    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> 
    
  • OK, 更改成功

  • 顺便使用 ps -ef | grep mysql 查看mysql的后台进程

[root@zenyLinux mysqlFile]# ps -ef | grep mysql
mysql     489630       1  0 20:43 ?        00:00:01 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root      497019  443357  0 21:08 pts/1    00:00:00 grep --color=auto mysql

  • OK, 几经波折, 终于安装完成了。
  • 本来装mysql就不是很麻烦的, 这一搞浪费了一些时间…
  • 其中也走了挺多弯路, 这多亏别人提供的参考经验, 让我解决了许多问题。 为此记录下这个过程, 希望对有遇到这问题的小伙伴能有一丢丢的帮助。

上述参考到的博文 :

https://blog.csdn.net/weixin_43025071/article/details/108464547

https://blog.csdn.net/ichen820/article/details/123326321

https://blog.csdn.net/wt334502157/article/details/123189000

https://blog.csdn.net/qq_40251815/article

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值