最近生產(chǎn)系統(tǒng)系統(tǒng)需要使用MySQL5.7版本的數(shù)據(jù)庫,而Ubuntu20.04默認是8.0的版本,折騰了一段時間后,測試了3中方法,在實際應(yīng)用環(huán)境中測試成功,因此發(fā)布出來給大家參考。建議使用方案三方式部署,樂意折騰的可以試試方案二和方案一!
方案一
采用更換鏡像源的方式進行安裝部署。
1.更換鏡像源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.old #備份原來的文件
sudo vim /etc/apt/sources.list #修改sources.list文件
配置文件內(nèi)容如下所示:
#清華鏡像源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
2.更新
sudo apt update # 更新鏡像源
3.安裝MySQL5.7(需要輸入兩次mysql的root用戶的密碼)
安裝記錄如下所示
root@zgk-Ubuntu-T01:~# sudo apt install -y mysql-server-5.7
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
正在讀取狀態(tài)信息... 完成
有一些軟件包無法被安裝。如果您用的是 unstable 發(fā)行版,這也許是
因為系統(tǒng)無法達到您要求的狀態(tài)造成的。該版本中可能會有一些您需要的軟件
包尚未被創(chuàng)建或是它們已被從新到(Incoming)目錄移出。
下列信息可能會對解決問題有所幫助:
下列軟件包有未滿足的依賴關(guān)系:
mysql-server-5.7 : 依賴: mysql-client-5.7 (>= 5.7.33-0ubuntu0.16.04.1) 但是它將不會被安裝
E: 無法修正錯誤,因為您要求某些軟件包保持現(xiàn)狀,就是它們破壞了軟件包間的依賴關(guān)系。
root@zgk-Ubuntu-T01:~# sudo apt install -y mysql-client-5.7
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
正在讀取狀態(tài)信息... 完成
有一些軟件包無法被安裝。如果您用的是 unstable 發(fā)行版,這也許是
因為系統(tǒng)無法達到您要求的狀態(tài)造成的。該版本中可能會有一些您需要的軟件
包尚未被創(chuàng)建或是它們已被從新到(Incoming)目錄移出。
下列信息可能會對解決問題有所幫助:
下列軟件包有未滿足的依賴關(guān)系:
mysql-client-5.7 : 依賴: mysql-client-core-5.7 但是它將不會被安裝
E: 無法修正錯誤,因為您要求某些軟件包保持現(xiàn)狀,就是它們破壞了軟件包間的依賴關(guān)系。
root@zgk-Ubuntu-T01:~# sudo apt install -y mysql-client-core-5.7
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
正在讀取狀態(tài)信息... 完成
有一些軟件包無法被安裝。如果您用的是 unstable 發(fā)行版,這也許是
因為系統(tǒng)無法達到您要求的狀態(tài)造成的。該版本中可能會有一些您需要的軟件
包尚未被創(chuàng)建或是它們已被從新到(Incoming)目錄移出。
下列信息可能會對解決問題有所幫助:
下列軟件包有未滿足的依賴關(guān)系:
mysql-client-core-5.7 : 依賴: libtinfo5 (>= 6) 但是它將不會被安裝
E: 無法修正錯誤,因為您要求某些軟件包保持現(xiàn)狀,就是它們破壞了軟件包間的依賴關(guān)系。
root@zgk-Ubuntu-T01:~# sudo apt install libtinfo5
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
正在讀取狀態(tài)信息... 完成
下列軟件包將被【卸載】:
ncurses-base ncurses-term
下列【新】軟件包將被安裝:
libtinfo5
【警告】:下列基礎(chǔ)軟件包將被卸載。
請勿嘗試,除非您確實知道您在做什么!
ncurses-base
升級了 0 個軟件包,新安裝了 1 個軟件包,要卸載 2 個軟件包,有 1 個軟件包未被升級。
需要下載 76.8 kB 的歸檔。
解壓縮后將會空出 4,194 kB 的空間。
您的操作有潛在的危害性。
若要繼續(xù),請輸入下面的短句“是,按我說的做!”
?] 是,按我說的做!
獲取:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial/main amd64 libtinfo5 amd64 6.0+20160213-1ubuntu1 [76.8 kB]
已下載 76.8 kB,耗時 1秒 (51.4 kB/s)
(正在讀取數(shù)據(jù)庫 ... 系統(tǒng)當(dāng)前共安裝有 187784 個文件和目錄。)
正在卸載 ncurses-term (6.2-0ubuntu2) ...
dpkg: 警告: 由于開啟了 --force 選項,以下問題被忽略:
dpkg: 警告: 這是一個至關(guān)重要的軟件包;您不應(yīng)當(dāng)把它卸載。
正在卸載 ncurses-base (6.2-0ubuntu2) ...
正在選中未選擇的軟件包 libtinfo5:amd64。
(正在讀取數(shù)據(jù)庫 ... 系統(tǒng)當(dāng)前共安裝有 184914 個文件和目錄。)
準(zhǔn)備解壓 .../libtinfo5_6.0+20160213-1ubuntu1_amd64.deb ...
正在解壓 libtinfo5:amd64 (6.0+20160213-1ubuntu1) ...
正在設(shè)置 libtinfo5:amd64 (6.0+20160213-1ubuntu1) ...
正在處理用于 libc-bin (2.31-0ubuntu9.2) 的觸發(fā)器 ...
root@zgk-Ubuntu-T01:~# sudo apt install -y mysql-client-core-5.7
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
正在讀取狀態(tài)信息... 完成
將會同時安裝下列軟件:
libaio1 libssl1.0.0
下列【新】軟件包將被安裝:
libaio1 libssl1.0.0 mysql-client-core-5.7
升級了 0 個軟件包,新安裝了 3 個軟件包,要卸載 0 個軟件包,有 1 個軟件包未被升級。
需要下載 7,343 kB 的歸檔。
解壓縮后會消耗 34.4 MB 的額外空間。
獲取:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 libssl1.0.0 amd64 1.0.2g-1ubuntu4.20 [1,083 kB]
獲取:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial/main amd64 libaio1 amd64 0.3.110-2 [6,356 B]
獲取:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 mysql-client-core-5.7 amd64 5.7.33-0ubuntu0.16.04.1 [6,254 kB]
已下載 7,343 kB,耗時 8秒 (932 kB/s)
正在預(yù)設(shè)定軟件包 ...
正在選中未選擇的軟件包 libssl1.0.0:amd64。
(正在讀取數(shù)據(jù)庫 ... 系統(tǒng)當(dāng)前共安裝有 184922 個文件和目錄。)
準(zhǔn)備解壓 .../libssl1.0.0_1.0.2g-1ubuntu4.20_amd64.deb ...
正在解壓 libssl1.0.0:amd64 (1.0.2g-1ubuntu4.20) ...
正在選中未選擇的軟件包 libaio1:amd64。
準(zhǔn)備解壓 .../libaio1_0.3.110-2_amd64.deb ...
正在解壓 libaio1:amd64 (0.3.110-2) ...
正在選中未選擇的軟件包 mysql-client-core-5.7。
準(zhǔn)備解壓 .../mysql-client-core-5.7_5.7.33-0ubuntu0.16.04.1_amd64.deb ...
正在解壓 mysql-client-core-5.7 (5.7.33-0ubuntu0.16.04.1) ...
正在設(shè)置 libssl1.0.0:amd64 (1.0.2g-1ubuntu4.20) ...
正在設(shè)置 libaio1:amd64 (0.3.110-2) ...
正在設(shè)置 mysql-client-core-5.7 (5.7.33-0ubuntu0.16.04.1) ...
正在處理用于 man-db (2.9.1-1) 的觸發(fā)器 ...
正在處理用于 libc-bin (2.31-0ubuntu9.2) 的觸發(fā)器 ...
root@zgk-Ubuntu-T01:~# sudo apt install -y mysql-client-core-5.7
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
正在讀取狀態(tài)信息... 完成
mysql-client-core-5.7 已經(jīng)是最新版 (5.7.33-0ubuntu0.16.04.1)。
升級了 0 個軟件包,新安裝了 0 個軟件包,要卸載 0 個軟件包,有 1 個軟件包未被升級。
root@zgk-Ubuntu-T01:~# sudo apt install -y mysql-server-5.7
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
正在讀取狀態(tài)信息... 完成
將會同時安裝下列軟件:
initscripts insserv libcgi-pm-perl libhtml-template-perl mysql-client-5.7
mysql-server-core-5.7 sysv-rc
建議安裝:
bootchart2 libipc-sharedcache-perl mailx tinyca bum
推薦安裝:
libcgi-fast-perl
下列【新】軟件包將被安裝:
initscripts insserv libcgi-pm-perl libhtml-template-perl mysql-client-5.7
mysql-server-5.7 mysql-server-core-5.7 sysv-rc
升級了 0 個軟件包,新安裝了 8 個軟件包,要卸載 0 個軟件包,有 1 個軟件包未被升級。
需要下載 11.4 MB 的歸檔。
解壓縮后會消耗 126 MB 的額外空間。
獲取:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial/main amd64 insserv amd64 1.14.0-5ubuntu3 [38.2 kB]
獲取:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial/main amd64 sysv-rc all 2.88dsf-59.3ubuntu2 [18.2 kB]
獲取:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial/main amd64 initscripts amd64 2.88dsf-59.3ubuntu2 [24.4 kB]
獲取:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 mysql-client-5.7 amd64 5.7.33-0ubuntu0.16.04.1 [1,430 kB]
獲取:5 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 mysql-server-core-5.7 amd64 5.7.33-0ubuntu0.16.04.1 [7,215 kB]
獲取:6 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 mysql-server-5.7 amd64 5.7.33-0ubuntu0.16.04.1 [2,423 kB]
獲取:7 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial/main amd64 libcgi-pm-perl all 4.26-1 [185 kB]
獲取:8 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial/main amd64 libhtml-template-perl all 2.95-2 [60.4 kB]
已下載 11.4 MB,耗時 32秒 (351 kB/s)
正在預(yù)設(shè)定軟件包 ...
軟件包設(shè)置
┌──────────────────────────┤ 正在設(shè)定 mysql-server-5.7 ├──────────────────────────┐
│ While not mandatory, it is highly recommended that you set a password for the │
│ MySQL administrative "root" user. │
│ │
│ If this field is left blank, the password will not be changed. │
│ │
│ New password for the MySQL "root" user: │
│ │
│ *********______________________________________________________________________ │
│ │
│ <確定> │
│ │
└─────────────────────────────────────────────────────────────────────────────────┘
軟件包設(shè)置
┌────────┤ 正在設(shè)定 mysql-server-5.7 ├────────┐
│ │
│ │
│ Repeat password for the MySQL "root" user: │
│ │
│ *********__________________________________ │
│ │
│ <確定> │
│ │
└─────────────────────────────────────────────┘
正在選中未選擇的軟件包 insserv。
(正在讀取數(shù)據(jù)庫 ... 系統(tǒng)當(dāng)前共安裝有 184958 個文件和目錄。)
準(zhǔn)備解壓 .../0-insserv_1.14.0-5ubuntu3_amd64.deb ...
正在解壓 insserv (1.14.0-5ubuntu3) ...
正在選中未選擇的軟件包 sysv-rc。
準(zhǔn)備解壓 .../1-sysv-rc_2.88dsf-59.3ubuntu2_all.deb ...
正在解壓 sysv-rc (2.88dsf-59.3ubuntu2) ...
正在選中未選擇的軟件包 initscripts。
準(zhǔn)備解壓 .../2-initscripts_2.88dsf-59.3ubuntu2_amd64.deb ...
正在解壓 initscripts (2.88dsf-59.3ubuntu2) ...
被已安裝的軟件包 sysvinit-utils (2.96-2.1ubuntu1) 中的文件替換了...
正在選中未選擇的軟件包 mysql-client-5.7。
準(zhǔn)備解壓 .../3-mysql-client-5.7_5.7.33-0ubuntu0.16.04.1_amd64.deb ...
正在解壓 mysql-client-5.7 (5.7.33-0ubuntu0.16.04.1) ...
正在選中未選擇的軟件包 mysql-server-core-5.7。
準(zhǔn)備解壓 .../4-mysql-server-core-5.7_5.7.33-0ubuntu0.16.04.1_amd64.deb ...
正在解壓 mysql-server-core-5.7 (5.7.33-0ubuntu0.16.04.1) ...
正在選中未選擇的軟件包 mysql-server-5.7。
準(zhǔn)備解壓 .../5-mysql-server-5.7_5.7.33-0ubuntu0.16.04.1_amd64.deb ...
正在解壓 mysql-server-5.7 (5.7.33-0ubuntu0.16.04.1) ...
正在選中未選擇的軟件包 libcgi-pm-perl。
準(zhǔn)備解壓 .../6-libcgi-pm-perl_4.26-1_all.deb ...
正在解壓 libcgi-pm-perl (4.26-1) ...
正在選中未選擇的軟件包 libhtml-template-perl。
準(zhǔn)備解壓 .../7-libhtml-template-perl_2.95-2_all.deb ...
正在解壓 libhtml-template-perl (2.95-2) ...
正在設(shè)置 mysql-client-5.7 (5.7.33-0ubuntu0.16.04.1) ...
正在設(shè)置 libcgi-pm-perl (4.26-1) ...
正在設(shè)置 mysql-server-core-5.7 (5.7.33-0ubuntu0.16.04.1) ...
正在設(shè)置 libhtml-template-perl (2.95-2) ...
正在設(shè)置 insserv (1.14.0-5ubuntu3) ...
正在設(shè)置 sysv-rc (2.88dsf-59.3ubuntu2) ...
正在設(shè)置 initscripts (2.88dsf-59.3ubuntu2) ...
正在設(shè)置 mysql-server-5.7 (5.7.33-0ubuntu0.16.04.1) ...
update-alternatives: 使用 /etc/mysql/mysql.cnf 來在自動模式中提供 /etc/mysql/my.cnf (my.cnf)
Renaming removed key_buffer and myisam-recover options (if present)
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
正在處理用于 man-db (2.9.1-1) 的觸發(fā)器 ...
正在處理用于 systemd (245.4-4ubuntu3.15) 的觸發(fā)器 ...
4、安裝完成,查看MySQL的版本
root@zgk-Ubuntu-T01:~# mysql -V # 查看mysql版本
mysql Ver 14.14 Distrib 5.7.33, for Linux (x86_64) using EditLine wrapper
5、連接MySQL(使用root和剛才設(shè)置的root的密碼)
后面重啟系統(tǒng)后,發(fā)現(xiàn)鍵盤“Backspace”和方向鍵出現(xiàn)異常,切換到系統(tǒng)桌面終端任有此現(xiàn)象。
方案二
采用在線安裝方式進行。
1、下載deb文件并配置
如果你選擇下載mysql-apt-config_0.8.xx-1.all.deb文件,到這里下載,選擇一個版本,然后下載到ubuntu中,然后就可以dpkg -i運行,進行配置mysql-server的源。
安裝記錄如下所示?:
root@zgk-Ubuntu-T01:~# wget https://repo.mysql.com//mysql-apt-config_0.8.12-1_all.deb
--2022-12-09 17:05:27-- https://repo.mysql.com//mysql-apt-config_0.8.12-1_all.deb
正在解析主機 repo.mysql.com (repo.mysql.com)... 96.16.68.238
正在連接 repo.mysql.com (repo.mysql.com)|96.16.68.238|:443... 已連接。
已發(fā)出 HTTP 請求,正在等待回應(yīng)... 200 OK
長度: 36306 (35K) [application/x-debian-package]
正在保存至: “mysql-apt-config_0.8.12-1_all.deb”
mysql-apt-config_0.8.1 100%[=========================>] 35.46K 187KB/s 用時 0.2s
2022-12-09 17:05:28 (187 KB/s) - 已保存 “mysql-apt-config_0.8.12-1_all.deb” [36306/36306])
root@zgk-Ubuntu-T01:~# sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb
正在選中未選擇的軟件包 mysql-apt-config。
(正在讀取數(shù)據(jù)庫 ... 系統(tǒng)當(dāng)前共安裝有 187436 個文件和目錄。)
準(zhǔn)備解壓 mysql-apt-config_0.8.12-1_all.deb ...
正在解壓 mysql-apt-config (0.8.12-1) ...
正在設(shè)置 mysql-apt-config (0.8.12-1) ...
執(zhí)行這一步最好在機器上運行,在終端工具上,有可能顯示不了選項,我使用xshell可以正常。 這個彈出框里,我選擇的是“ubuntu bionic”。
之后單擊“確定”選項,進入下一個選項,此處默認為第一項,我們在第一項上,回車。
在出來的選項中,我們就可以選擇mysql-5.7了,在“mysq-5.7”上回車。
?回車后,系統(tǒng)自動顯示我們選擇的5.7的選項,通過鍵盤,選擇“ok”,然后回車確定。
配置結(jié)束后,運行update更新。
root@zgk-Ubuntu-T01:~# apt update
命中:1 http://mirrors.aliyun.com/ubuntu focal InRelease
獲取:2 http://mirrors.aliyun.com/ubuntu focal-updates InRelease [114 kB]
獲取:3 http://repo.mysql.com/apt/ubuntu bionic InRelease [20.0 kB]
錯誤:3 http://repo.mysql.com/apt/ubuntu bionic InRelease
由于沒有公鑰,無法驗證下列簽名: NO_PUBKEY 467B942D3A79BD29
獲取:4 http://mirrors.aliyun.com/ubuntu focal-backports InRelease [108 kB]
獲取:5 http://mirrors.aliyun.com/ubuntu focal-security InRelease [114 kB]
獲取:6 http://mirrors.aliyun.com/ubuntu focal-updates/main i386 Packages [761 kB]
獲取:7 http://mirrors.aliyun.com/ubuntu focal-updates/main amd64 Packages [2,267 kB]
獲取:8 http://mirrors.aliyun.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [275 kB]
獲取:9 http://mirrors.aliyun.com/ubuntu focal-updates/universe amd64 Packages [1,009 kB]
獲取:10 http://mirrors.aliyun.com/ubuntu focal-updates/universe i386 Packages [705 kB]
獲取:11 http://mirrors.aliyun.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [408 kB]
獲取:12 http://mirrors.aliyun.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [940 B]
獲取:13 http://mirrors.aliyun.com/ubuntu focal-backports/main amd64 DEP-11 Metadata [7,940 B]
獲取:14 http://mirrors.aliyun.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [30.5 kB]
獲取:15 http://mirrors.aliyun.com/ubuntu focal-security/main amd64 DEP-11 Metadata [40.7 kB]
獲取:16 http://mirrors.aliyun.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [93.9 kB]
獲取:17 http://mirrors.aliyun.com/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [940 B]
正在讀取軟件包列表... 完成
W: GPG 錯誤:http://repo.mysql.com/apt/ubuntu bionic InRelease: 由于沒有公鑰,無法驗證下列簽名: NO_PUBKEY 467B942D3A79BD29
E: 倉庫 “http://repo.mysql.com/apt/ubuntu bionic InRelease” 沒有數(shù)字簽名。
N: 無法安全地用該源進行更新,所以默認禁用該源。
?提示沒有公鑰,因此我們最好安裝公鑰。
root@zgk-Ubuntu-T01:~# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
Executing: /tmp/apt-key-gpghome.6S4Xo2qxW8/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
gpg: 密鑰 467B942D3A79BD29:公鑰 “MySQL Release Engineering <mysql-build@oss.oracle.com>” 已導(dǎo)入
gpg: 處理的總數(shù):1
gpg: 已導(dǎo)入:1
?執(zhí)行成功后,繼續(xù)執(zhí)行“apt update”,運行正常,接下來可以正常安裝。
2、安裝mysq-5.7
此時,在/etc/apt/source.list.d/目錄下生成mysql.list,更新完成,我們通過apt-cache policy mysql-server可以查看到,系統(tǒng)中出現(xiàn)了mysql5.7的源。
root@zgk-Ubuntu-T01:~# apt-cache policy mysql-server
mysql-server:
已安裝:(無)
候選: 8.0.31-0ubuntu0.20.04.2
版本列表:
8.0.31-0ubuntu0.20.04.2 500
500 http://mirrors.aliyun.com/ubuntu focal-updates/main amd64 Packages
500 http://mirrors.aliyun.com/ubuntu focal-updates/main i386 Packages
8.0.31-0ubuntu0.20.04.1 500
500 http://mirrors.aliyun.com/ubuntu focal-security/main amd64 Packages
500 http://mirrors.aliyun.com/ubuntu focal-security/main i386 Packages
8.0.19-0ubuntu5 500
500 http://mirrors.aliyun.com/ubuntu focal/main amd64 Packages
500 http://mirrors.aliyun.com/ubuntu focal/main i386 Packages
5.7.40-1ubuntu18.04 500
500 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 Packages
?2.1安裝mysql-client
root@zgk-Ubuntu-T01:~# sudo apt install mysql-client=5.7.40-1ubuntu18.04
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
正在讀取狀態(tài)信息... 完成
將會同時安裝下列軟件:
libaio1 libtinfo5 mysql-community-client
下列【新】軟件包將被安裝:
libaio1 libtinfo5 mysql-client mysql-community-client
升級了 0 個軟件包,新安裝了 4 個軟件包,要卸載 0 個軟件包,有 87 個軟件包未被升級。
需要下載 15.4 MB 的歸檔。
解壓縮后會消耗 98.9 MB 的額外空間。
您希望繼續(xù)執(zhí)行嗎? [Y/n] y
獲取:1 http://mirrors.aliyun.com/ubuntu focal/main amd64 libaio1 amd64 0.3.112-5 [7,184 B]
獲取:2 http://mirrors.aliyun.com/ubuntu focal/universe amd64 libtinfo5 amd64 6.2-0ubuntu2 [83.0 kB]
獲取:3 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 mysql-community-client amd64 5.7.40-1ubuntu18.04 [15.2 MB]
獲取:4 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 mysql-client amd64 5.7.40-1ubuntu18.04 [69.6 kB]
已下載 15.4 MB,耗時 4秒 (3,539 kB/s)
正在選中未選擇的軟件包 libaio1:amd64。
(正在讀取數(shù)據(jù)庫 ... 系統(tǒng)當(dāng)前共安裝有 187441 個文件和目錄。)
準(zhǔn)備解壓 .../libaio1_0.3.112-5_amd64.deb ...
正在解壓 libaio1:amd64 (0.3.112-5) ...
正在選中未選擇的軟件包 libtinfo5:amd64。
準(zhǔn)備解壓 .../libtinfo5_6.2-0ubuntu2_amd64.deb ...
正在解壓 libtinfo5:amd64 (6.2-0ubuntu2) ...
正在選中未選擇的軟件包 mysql-community-client。
準(zhǔn)備解壓 .../mysql-community-client_5.7.40-1ubuntu18.04_amd64.deb ...
正在解壓 mysql-community-client (5.7.40-1ubuntu18.04) ...
正在選中未選擇的軟件包 mysql-client。
準(zhǔn)備解壓 .../mysql-client_5.7.40-1ubuntu18.04_amd64.deb ...
正在解壓 mysql-client (5.7.40-1ubuntu18.04) ...
正在設(shè)置 libaio1:amd64 (0.3.112-5) ...
正在設(shè)置 libtinfo5:amd64 (6.2-0ubuntu2) ...
正在設(shè)置 mysql-community-client (5.7.40-1ubuntu18.04) ...
正在設(shè)置 mysql-client (5.7.40-1ubuntu18.04) ...
正在處理用于 man-db (2.9.1-1) 的觸發(fā)器 ...
正在處理用于 libc-bin (2.31-0ubuntu9.7) 的觸發(fā)器 ...
root@zgk-Ubuntu-T01:~# sudo apt install mysql-community=5.7.40-1ubuntu18.04
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
正在讀取狀態(tài)信息... 完成
2.2安裝mysql-community-server
root@zgk-Ubuntu-T01:~# sudo apt install mysql-community-server=5.7.40-1ubuntu18.04
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
正在讀取狀態(tài)信息... 完成
將會同時安裝下列軟件:
libmecab2
下列【新】軟件包將被安裝:
libmecab2 mysql-community-server
升級了 0 個軟件包,新安裝了 2 個軟件包,要卸載 0 個軟件包,有 88 個軟件包未被升級。
需要下載 40.1 MB 的歸檔。
解壓縮后會消耗 229 MB 的額外空間。
您希望繼續(xù)執(zhí)行嗎? [Y/n] y
獲取:1 http://mirrors.aliyun.com/ubuntu focal/main amd64 libmecab2 amd64 0.996-10build1 [233 kB]
獲取:2 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 mysql-community-server amd64 5.7.40-1ubuntu18.04 [39.8 MB]
已下載 40.1 MB,耗時 5秒 (8,313 kB/s)
正在預(yù)設(shè)定軟件包 ...
設(shè)置mysq的root密碼,并進行二次密碼確認
正在選中未選擇的軟件包 libmecab2:amd64。
(正在讀取數(shù)據(jù)庫 ... 系統(tǒng)當(dāng)前共安裝有 187517 個文件和目錄。)
準(zhǔn)備解壓 .../libmecab2_0.996-10build1_amd64.deb ...
正在解壓 libmecab2:amd64 (0.996-10build1) ...
正在選中未選擇的軟件包 mysql-community-server。
準(zhǔn)備解壓 .../mysql-community-server_5.7.40-1ubuntu18.04_amd64.deb ...
正在解壓 mysql-community-server (5.7.40-1ubuntu18.04) ...
正在設(shè)置 libmecab2:amd64 (0.996-10build1) ...
正在設(shè)置 mysql-community-server (5.7.40-1ubuntu18.04) ...
update-alternatives: 使用 /etc/mysql/mysql.cnf 來在自動模式中提供 /etc/mysql/my.cnf (my.cnf)
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
正在處理用于 systemd (245.4-4ubuntu3.15) 的觸發(fā)器 ...
正在處理用于 man-db (2.9.1-1) 的觸發(fā)器 ...
正在處理用于 libc-bin (2.31-0ubuntu9.7) 的觸發(fā)器 ...
?2.3安裝mysql-server
root@zgk-Ubuntu-T01:~# sudo apt install mysql-server=5.7.40-1ubuntu18.04
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
正在讀取狀態(tài)信息... 完成
下列【新】軟件包將被安裝:
mysql-server
升級了 0 個軟件包,新安裝了 1 個軟件包,要卸載 0 個軟件包,有 88 個軟件包未被升級。
需要下載 69.6 kB 的歸檔。
解壓縮后會消耗 79.9 kB 的額外空間。
獲取:1 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 mysql-server amd64 5.7.40-1ubuntu18.04 [69.6 kB]
已下載 69.6 kB,耗時 1秒 (98.2 kB/s)
正在選中未選擇的軟件包 mysql-server。
(正在讀取數(shù)據(jù)庫 ... 系統(tǒng)當(dāng)前共安裝有 187685 個文件和目錄。)
準(zhǔn)備解壓 .../mysql-server_5.7.40-1ubuntu18.04_amd64.deb ...
正在解壓 mysql-server (5.7.40-1ubuntu18.04) ...
正在設(shè)置 mysql-server (5.7.40-1ubuntu18.04) ...
3、驗證并測試
安裝完成后,通過“dpkg -l | grep mysql”命令可以看到mysql的版本為5.7.40
root@zgk-Ubuntu-T01:~# dpkg -l | grep mysql
ii libmysqlclient21:amd64 8.0.31-0ubuntu0.20.04.1 amd64 MySQL database client library
ii mysql-apt-config 0.8.12-1 all Auto configuration for MySQL APT Repo.
ii mysql-client 5.7.40-1ubuntu18.04 amd64 MySQL Client meta package depending on latest version
ii mysql-common 5.8+1.0.5ubuntu2 all MySQL database common files, e.g. /etc/mysql/my.cnf
ii mysql-community-client 5.7.40-1ubuntu18.04 amd64 MySQL Client
ii mysql-community-server 5.7.40-1ubuntu18.04 amd64 MySQL Server
ii mysql-server 5.7.40-1ubuntu18.04 amd64 MySQL Server meta package depending on latest version
?通過“mysql -u root -p”輸入密碼后,正常進入數(shù)據(jù)庫
root@zgk-Ubuntu-T01:~# 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.40 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> quit
系統(tǒng)重啟后,一切正常!無方案一的重啟后,鍵盤“Backspace”和方向鍵出現(xiàn)故障的現(xiàn)象。
方案三
采用源碼包安裝方式。
1、準(zhǔn)備源碼包與環(huán)境
提前通過如下方式下載包并解壓,刪除兩個帶test名稱的deb文件。
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-server_5.7.31-1ubuntu18.04_amd64.deb-bundle.tar
tar -xvf mysql-server_5.7.31-1ubuntu18.04_amd64.deb-bundle.tar
rm -f mysql-testsuite_5.7.31-1ubuntu18.04_amd64.deb
rm -f mysql-community-test_5.7.30-1ubuntu18.04_amd64.deb
依賴包可以去阿里巴巴開源鏡像站-阿里云官網(wǎng)開發(fā)者社區(qū)_云計算社區(qū)提供全面,高效和穩(wěn)定的系統(tǒng)鏡像、應(yīng)用軟件下載、域名解析和時間同步服務(wù)https://developer.aliyun.com/packageSearch?word=libaio1提前下載好。
1.1安裝步驟
1)本方案采用先裝如下安裝包
libmysqlclient20_5.7.31-1ubuntu18.04_amd64.deb
libmysqlclient-dev_5.7.31-1ubuntu18.04_amd64.deb
libmysqld-dev_5.7.31-1ubuntu18.04_amd64.deb
mysql-common_5.7.31-1ubuntu18.04_amd64.deb
2)再安裝如下安裝包(在安裝“mysql-community-client_5.7.31-1ubuntu18.04_amd64.deb”包時提示依賴關(guān)系存在問題,參考“2、處理依賴關(guān)系”,并安裝好幾個依賴包,采用離線方式安裝的話,可以去阿里鏡像源上下載匹配的包,本方案中使用amd64,所以下載了“libaio1_0.3.112-5_amd64.deb”、“libmecab2_0.996-10build1_amd64.deb”、“libtinfo5_6.2-0ubuntu2_amd64.deb”三個依賴包)
mysql-community-source_5.7.31-1ubuntu18.04_amd64.deb
mysql-community-client_5.7.31-1ubuntu18.04_amd64.deb
mysql-client_5.7.31-1ubuntu18.04_amd64.deb
3)最后安裝下述包
mysql-community-server_5.7.31-1ubuntu18.04_amd64.deb
mysql-server_5.7.31-1ubuntu18.04_amd64.deb
root@zgk-Ubuntu-T01:~# dpkg -i mysql-community-client_5.7.31-1ubuntu18.04_amd64.deb
(正在讀取數(shù)據(jù)庫 ... 系統(tǒng)當(dāng)前共安裝有 187799 個文件和目錄。)
準(zhǔn)備解壓 mysql-community-client_5.7.31-1ubuntu18.04_amd64.deb ...
正在解壓 mysql-community-client (5.7.31-1ubuntu18.04) 并覆蓋 (5.7.31-1ubuntu18.04) ...
dpkg: 依賴關(guān)系問題使得 mysql-community-client 的配置工作不能繼續(xù):
mysql-community-client 依賴于 libaio1 (>= 0.3.93);然而:
未安裝軟件包 libaio1。
mysql-community-client 依賴于 libtinfo5 (>= 6);然而:
未安裝軟件包 libtinfo5。
dpkg: 處理軟件包 mysql-community-client (--install)時出錯:
依賴關(guān)系問題 - 仍未被配置
正在處理用于 man-db (2.9.1-1) 的觸發(fā)器 ...
在處理時有錯誤發(fā)生:
mysql-community-client
root@zgk-Ubuntu-T01:~# sudo apt install libaio1
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
正在讀取狀態(tài)信息... 完成
您也許需要運行“apt --fix-broken install”來修正上面的錯誤。
下列軟件包有未滿足的依賴關(guān)系:
mysql-community-client : 依賴: libtinfo5 (>= 6) 但是它將不會被安裝
mysql-community-server : 依賴: libmecab2 但是它將不會被安裝
E: 有未能滿足的依賴關(guān)系。請嘗試不指明軟件包的名字來運行“apt --fix-broken install”(也可以指定一個解決辦法)。
root@zgk-Ubuntu-T01:~# sudo apt install libtinfo5
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
正在讀取狀態(tài)信息... 完成
您也許需要運行“apt --fix-broken install”來修正上面的錯誤。
下列軟件包有未滿足的依賴關(guān)系:
mysql-community-client : 依賴: libaio1 (>= 0.3.93) 但是它將不會被安裝
mysql-community-server : 依賴: libaio1 (>= 0.3.93) 但是它將不會被安裝
依賴: libmecab2 但是它將不會被安裝
E: 有未能滿足的依賴關(guān)系。請嘗試不指明軟件包的名字來運行“apt --fix-broken install”(也可以指定一個解決辦法)。
2、處理依賴關(guān)系
若出現(xiàn)單獨安裝某一個依賴包出現(xiàn)錯誤時,或安裝的依賴包互相有依賴關(guān)系,則選擇一次安裝所有的依賴包,即可解決互相關(guān)聯(lián)的依賴關(guān)系。
root@zgk-Ubuntu-T01:~# sudo apt install libaio1 libtinfo5 libmecab2
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
正在讀取狀態(tài)信息... 完成
下列【新】軟件包將被安裝:
libaio1 libmecab2 libtinfo5
升級了 0 個軟件包,新安裝了 3 個軟件包,要卸載 0 個軟件包,有 320 個軟件包未被升級。
有 4 個軟件包沒有被完全安裝或卸載。
需要下載 323 kB 的歸檔。
解壓縮后會消耗 2,435 kB 的額外空間。
獲取:1 http://mirrors.aliyun.com/ubuntu focal/main amd64 libaio1 amd64 0.3.112-5 [7,184 B]
獲取:2 http://mirrors.aliyun.com/ubuntu focal/universe amd64 libtinfo5 amd64 6.2-0ubuntu2 [83.0 kB]
獲取:3 http://mirrors.aliyun.com/ubuntu focal/main amd64 libmecab2 amd64 0.996-10build1 [233 kB]
已下載 323 kB,耗時 1秒 (543 kB/s)
正在選中未選擇的軟件包 libaio1:amd64。
(正在讀取數(shù)據(jù)庫 ... 系統(tǒng)當(dāng)前共安裝有 187799 個文件和目錄。)
準(zhǔn)備解壓 .../libaio1_0.3.112-5_amd64.deb ...
正在解壓 libaio1:amd64 (0.3.112-5) ...
正在選中未選擇的軟件包 libtinfo5:amd64。
準(zhǔn)備解壓 .../libtinfo5_6.2-0ubuntu2_amd64.deb ...
正在解壓 libtinfo5:amd64 (6.2-0ubuntu2) ...
正在選中未選擇的軟件包 libmecab2:amd64。
準(zhǔn)備解壓 .../libmecab2_0.996-10build1_amd64.deb ...
正在解壓 libmecab2:amd64 (0.996-10build1) ...
正在設(shè)置 libmecab2:amd64 (0.996-10build1) ...
正在設(shè)置 libaio1:amd64 (0.3.112-5) ...
正在設(shè)置 libtinfo5:amd64 (6.2-0ubuntu2) ...
正在設(shè)置 mysql-community-client (5.7.31-1ubuntu18.04) ...
正在設(shè)置 mysql-client (5.7.31-1ubuntu18.04) ...
正在設(shè)置 mysql-community-server (5.7.31-1ubuntu18.04) ...
?文章來源:http://www.zghlxwxcb.cn/news/detail-421493.html
update-alternatives: 使用 /etc/mysql/mysql.cnf 來在自動模式中提供 /etc/mysql/my.cnf (my.cnf)
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
正在設(shè)置 mysql-server (5.7.31-1ubuntu18.04) ...
正在處理用于 libc-bin (2.31-0ubuntu9.2) 的觸發(fā)器 ...
正在處理用于 systemd (245.4-4ubuntu3.15) 的觸發(fā)器 ...
3、安裝完成,查看數(shù)據(jù)庫是否正常并修改允許root登錄
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 user,host from user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select user,host from user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
4、配置允許其他IP訪問
root@zgk-Ubuntu-T01:/etc/mysql/mysql.conf.d# vim mysqld.cnf
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
log-error = /var/log/mysql/error.log
port = 3306
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
~
"mysqld.cnf" 38L, 1621C 已寫入
root@zgk-Ubuntu-T01:/etc/mysql/mysql.conf.d# /etc/init.d/mysql restart
至此,三種方案整理完畢!文章來源地址http://www.zghlxwxcb.cn/news/detail-421493.html
到了這里,關(guān)于Ubuntu20.04安裝MySQL5.7-實測3種方法(保姆級教程)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!