CentOS 7 RPM 離線安裝 MySQL 8


1. 前往 MySQL 官網 下載 Bundle tar 包

這個是 x86 架構 64 位 CPU 的安裝包

2. 解壓 tar 包,得到以下文件

-rw-r--r--. 1 7155 31415  47810444 4月  26 15:36 mysql-community-client-8.0.25-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415    193616 4月  26 15:36 mysql-community-client-plugins-8.0.25-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415    628904 4月  26 15:36 mysql-community-common-8.0.25-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   6800820 4月  26 15:36 mysql-community-devel-8.0.25-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  23586756 4月  26 15:37 mysql-community-embedded-compat-8.0.25-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   4240320 4月  26 15:37 mysql-community-libs-8.0.25-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   1262876 4月  26 15:37 mysql-community-libs-compat-8.0.25-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 448614076 4月  26 15:38 mysql-community-server-8.0.25-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 260841936 4月  26 15:40 mysql-community-test-8.0.25-1.el7.x86_64.rpm

3. 卸載系統自帶的 MariaDB

rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

4. 按照以下順序安裝 MySQL8

1. rpm -ivh mysql-community-common-8.0.25-1.el7.x86_64.rpm
2. rpm -ivh mysql-community-client-plugins-8.0.25-1.el7.x86_64.rpm
3. rpm -ivh mysql-community-libs-8.0.25-1.el7.x86_64.rpm
4. rpm -ivh mysql-community-client-8.0.25-1.el7.x86_64.rpm
5. rpm -ivh mysql-community-server-8.0.25-1.el7.x86_64.rpm
6. rpm -ivh mysql-community-devel-8.0.25-1.el7.x86_64.rpm

4.1 安裝 mysql-community-server-8.0.25-1.el7.x86_64.rpm 的時候需要依賴 net-tools,如果沒有 net-tools 會安裝失敗,此時先安裝 net-tools,然后再安裝 mysql-community-server-8.0.25-1.el7.x86_64.rpm 即可

# 安裝 mysql-community-server-8.0.25-1.el7.x86_64.rpm 依賴報錯
[root@sangni mysql-installation]# rpm -ivh mysql-community-server-8.0.25-1.el7.x86_64.rpm
警告:mysql-community-server-8.0.25-1.el7.x86_64.rpm: 頭V3 DSA/SHA1 Signature, 密鑰 ID 5072e1f5: NOKEY
錯誤:依賴檢測失敗:
	net-tools 被 mysql-community-server-8.0.25-1.el7.x86_64 需要

# 安裝 net-tools
[root@sangni mysql-installation]# yum install net-tools
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.njupt.edu.cn
 * extras: mirrors.njupt.edu.cn
 * updates: mirrors.njupt.edu.cn
正在解決依賴關系
--> 正在檢查事務
---> 軟件包 net-tools.x86_64.0.2.0-0.25.20131004git.el7 將被 安裝
--> 解決依賴關系完成

依賴關系解決

==================================================================================================================================
 Package                      架構                      版本                                        源                       大小
==================================================================================================================================
正在安裝:
 net-tools                    x86_64                    2.0-0.25.20131004git.el7                    base                    306 k

事務概要
==================================================================================================================================
安裝  1 軟件包

總下載量:306 k
安裝大小:917 k
Is this ok [y/d/N]: y
Downloading packages:
net-tools-2.0-0.25.20131004git.el7.x86_64.rpm                                                              | 306 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 數據庫已被非 yum 程序修改。
** 發現 2 個已存在的 RPM 數據庫問題, 'yum check' 輸出如下:
2:postfix-2.10.1-9.el7.x86_64 有缺少的需求 libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-9.el7.x86_64 有缺少的需求 libmysqlclient.so.18(libmysqlclient_18)(64bit)
  正在安裝    : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                     1/1 
  驗證中      : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                     1/1 

已安裝:
  net-tools.x86_64 0:2.0-0.25.20131004git.el7                                                                                     

完畢!

# net-tools 安裝完成后再次安裝 mysql-community-server-8.0.25-1.el7.x86_64.rpm
[root@sangni mysql-installation]# rpm -ivh mysql-community-server-8.0.25-1.el7.x86_64.rpm 
警告:mysql-community-server-8.0.25-1.el7.x86_64.rpm: 頭V3 DSA/SHA1 Signature, 密鑰 ID 5072e1f5: NOKEY
准備中...                          ################################# [100%]
正在升級/安裝...
   1:mysql-community-server-8.0.25-1.e################################# [100%]

4.2 安裝 mysql-community-devel-8.0.25-1.el7.x86_64.rpm 的時候需要依賴 pkgconfig(openssl),如果報錯則同樣先安裝 openssl-devel 即可

# 安裝 mysql-community-devel-8.0.25-1.el7.x86_64.rpm 依賴報錯
[root@sangni mysql-installation]# rpm -ivh mysql-community-devel-8.0.25-1.el7.x86_64.rpm 
警告:mysql-community-devel-8.0.25-1.el7.x86_64.rpm: 頭V3 DSA/SHA1 Signature, 密鑰 ID 5072e1f5: NOKEY
錯誤:依賴檢測失敗:
	pkgconfig(openssl) 被 mysql-community-devel-8.0.25-1.el7.x86_64 需要

# 安裝 openssl-devel
[root@sangni mysql-installation]# yum install openssl-devel
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.njupt.edu.cn
 * extras: mirrors.njupt.edu.cn
 * updates: mirrors.njupt.edu.cn

正在解決依賴關系
--> 正在檢查事務
---> 軟件包 openssl-devel.x86_64.1.1.0.2k-21.el7_9 將被 安裝
--> 正在處理依賴關系 zlib-devel(x86-64),它被軟件包 1:openssl-devel-1.0.2k-21.el7_9.x86_64 需要
--> 正在處理依賴關系 krb5-devel(x86-64),它被軟件包 1:openssl-devel-1.0.2k-21.el7_9.x86_64 需要
--> 正在檢查事務
---> 軟件包 krb5-devel.x86_64.0.1.15.1-50.el7 將被 安裝
--> 正在處理依賴關系 libkadm5(x86-64) = 1.15.1-50.el7,它被軟件包 krb5-devel-1.15.1-50.el7.x86_64 需要
--> 正在處理依賴關系 libverto-devel,它被軟件包 krb5-devel-1.15.1-50.el7.x86_64 需要
--> 正在處理依賴關系 libselinux-devel,它被軟件包 krb5-devel-1.15.1-50.el7.x86_64 需要
--> 正在處理依賴關系 libcom_err-devel,它被軟件包 krb5-devel-1.15.1-50.el7.x86_64 需要
--> 正在處理依賴關系 keyutils-libs-devel,它被軟件包 krb5-devel-1.15.1-50.el7.x86_64 需要
---> 軟件包 zlib-devel.x86_64.0.1.2.7-19.el7_9 將被 安裝
--> 正在檢查事務
---> 軟件包 keyutils-libs-devel.x86_64.0.1.5.8-3.el7 將被 安裝
---> 軟件包 libcom_err-devel.x86_64.0.1.42.9-19.el7 將被 安裝
---> 軟件包 libkadm5.x86_64.0.1.15.1-50.el7 將被 安裝
---> 軟件包 libselinux-devel.x86_64.0.2.5-15.el7 將被 安裝
--> 正在處理依賴關系 libsepol-devel(x86-64) >= 2.5-10,它被軟件包 libselinux-devel-2.5-15.el7.x86_64 需要
--> 正在處理依賴關系 pkgconfig(libsepol),它被軟件包 libselinux-devel-2.5-15.el7.x86_64 需要
--> 正在處理依賴關系 pkgconfig(libpcre),它被軟件包 libselinux-devel-2.5-15.el7.x86_64 需要
---> 軟件包 libverto-devel.x86_64.0.0.2.5-4.el7 將被 安裝
--> 正在檢查事務
---> 軟件包 libsepol-devel.x86_64.0.2.5-10.el7 將被 安裝
---> 軟件包 pcre-devel.x86_64.0.8.32-17.el7 將被 安裝
--> 解決依賴關系完成

依賴關系解決

==================================================================================================================================
 Package                              架構                    版本                                 源                        大小
==================================================================================================================================
正在安裝:
 openssl-devel                        x86_64                  1:1.0.2k-21.el7_9                    updates                  1.5 M
為依賴而安裝:
 keyutils-libs-devel                  x86_64                  1.5.8-3.el7                          base                      37 k
 krb5-devel                           x86_64                  1.15.1-50.el7                        base                     273 k
 libcom_err-devel                     x86_64                  1.42.9-19.el7                        base                      32 k
 libkadm5                             x86_64                  1.15.1-50.el7                        base                     179 k
 libselinux-devel                     x86_64                  2.5-15.el7                           base                     187 k
 libsepol-devel                       x86_64                  2.5-10.el7                           base                      77 k
 libverto-devel                       x86_64                  0.2.5-4.el7                          base                      12 k
 pcre-devel                           x86_64                  8.32-17.el7                          base                     480 k
 zlib-devel                           x86_64                  1.2.7-19.el7_9                       updates                   50 k

事務概要
==================================================================================================================================
安裝  1 軟件包 (+9 依賴軟件包)

總下載量:2.8 M
安裝大小:6.0 M
Is this ok [y/d/N]: Is this ok [y/d/N]: y
Downloading packages:
(1/10): libcom_err-devel-1.42.9-19.el7.x86_64.rpm                                                          |  32 kB  00:00:00     
(2/10): keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm                                                         |  37 kB  00:00:00     
(3/10): krb5-devel-1.15.1-50.el7.x86_64.rpm                                                                | 273 kB  00:00:00     
(4/10): libkadm5-1.15.1-50.el7.x86_64.rpm                                                                  | 179 kB  00:00:00     
(5/10): libselinux-devel-2.5-15.el7.x86_64.rpm                                                             | 187 kB  00:00:00     
(6/10): libverto-devel-0.2.5-4.el7.x86_64.rpm                                                              |  12 kB  00:00:00     
(7/10): libsepol-devel-2.5-10.el7.x86_64.rpm                                                               |  77 kB  00:00:00     
(8/10): zlib-devel-1.2.7-19.el7_9.x86_64.rpm                                                               |  50 kB  00:00:00     
(9/10): openssl-devel-1.0.2k-21.el7_9.x86_64.rpm                                                           | 1.5 MB  00:00:00     
(10/10): pcre-devel-8.32-17.el7.x86_64.rpm                                                                 | 480 kB  00:00:00     
----------------------------------------------------------------------------------------------------------------------------------
總計                                                                                              2.0 MB/s | 2.8 MB  00:00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安裝    : libkadm5-1.15.1-50.el7.x86_64                                                                                1/10 
  正在安裝    : libsepol-devel-2.5-10.el7.x86_64                                                                             2/10 
  正在安裝    : libcom_err-devel-1.42.9-19.el7.x86_64                                                                        3/10 
  正在安裝    : zlib-devel-1.2.7-19.el7_9.x86_64                                                                             4/10 
  正在安裝    : pcre-devel-8.32-17.el7.x86_64                                                                                5/10 
  正在安裝    : libselinux-devel-2.5-15.el7.x86_64                                                                           6/10 
  正在安裝    : keyutils-libs-devel-1.5.8-3.el7.x86_64                                                                       7/10 
  正在安裝    : libverto-devel-0.2.5-4.el7.x86_64                                                                            8/10 
  正在安裝    : krb5-devel-1.15.1-50.el7.x86_64                                                                              9/10 
  正在安裝    : 1:openssl-devel-1.0.2k-21.el7_9.x86_64                                                                      10/10 
  驗證中      : libselinux-devel-2.5-15.el7.x86_64                                                                           1/10 
  驗證中      : 1:openssl-devel-1.0.2k-21.el7_9.x86_64                                                                       2/10 
  驗證中      : libverto-devel-0.2.5-4.el7.x86_64                                                                            3/10 
  驗證中      : krb5-devel-1.15.1-50.el7.x86_64                                                                              4/10 
  驗證中      : keyutils-libs-devel-1.5.8-3.el7.x86_64                                                                       5/10 
  驗證中      : pcre-devel-8.32-17.el7.x86_64                                                                                6/10 
  驗證中      : zlib-devel-1.2.7-19.el7_9.x86_64                                                                             7/10 
  驗證中      : libcom_err-devel-1.42.9-19.el7.x86_64                                                                        8/10 
  驗證中      : libsepol-devel-2.5-10.el7.x86_64                                                                             9/10 
  驗證中      : libkadm5-1.15.1-50.el7.x86_64                                                                               10/10 

已安裝:
  openssl-devel.x86_64 1:1.0.2k-21.el7_9                                                                                          

作為依賴被安裝:
  keyutils-libs-devel.x86_64 0:1.5.8-3.el7    krb5-devel.x86_64 0:1.15.1-50.el7       libcom_err-devel.x86_64 0:1.42.9-19.el7   
  libkadm5.x86_64 0:1.15.1-50.el7             libselinux-devel.x86_64 0:2.5-15.el7    libsepol-devel.x86_64 0:2.5-10.el7        
  libverto-devel.x86_64 0:0.2.5-4.el7         pcre-devel.x86_64 0:8.32-17.el7         zlib-devel.x86_64 0:1.2.7-19.el7_9        

完畢!

# 再次安裝 mysql-community-devel-8.0.25-1.el7.x86_64.rpm 
[root@sangni mysql-installation]# rpm -ivh mysql-community-devel-8.0.25-1.el7.x86_64.rpm 
警告:mysql-community-devel-8.0.25-1.el7.x86_64.rpm: 頭V3 DSA/SHA1 Signature, 密鑰 ID 5072e1f5: NOKEY
准備中...                          ################################# [100%]
正在升級/安裝...
   1:mysql-community-devel-8.0.25-1.el################################# [100%]

5. 啟動 MySQL 服務

# 啟動 MySQL 服務
[root@sangni mysql-installation]# service mysqld start 
Redirecting to /bin/systemctl start mysqld.service

# 查看啟動狀態
[root@sangni mysql-installation]# service status mysqld
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
[root@sangni mysql-installation]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 一 2021-06-14 13:50:41 CST; 29s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 7989 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 8070 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─8070 /usr/sbin/mysqld

6月 14 13:50:31 sangni systemd[1]: Starting MySQL Server...
6月 14 13:50:41 sangni systemd[1]: Started MySQL Server.

6. 修改默認密碼開啟遠程連接

# 查看默認密碼
[root@sangni ~]# grep 'temporary password' /var/log/mysqld.log 
2021-06-14T05:50:35.796216Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: wfz2/(r6oiwM

# 使用默認密碼登陸 MySQL
[root@sangni log]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.25

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> select version();
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

# 修改 root 用戶密碼
mysql> alter user 'root'@'localhost' identified by 'xxxx';
Query OK, 0 rows affected (0.01 sec)

# 查看 MySQL 版本
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.25    |
+-----------+
1 row in set (0.00 sec)

# 使用 MySQL Schema/Database
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

# 修改 root 用戶的 host 列值,開啟遠程連接
mysql> update user set host='%' where user ='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

# 刷新緩存
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

# 給 root 用戶授予所有權限
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
Query OK, 0 rows affected (0.01 sec)

7. 搞定收工,飲茶先啦!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM