背景介紹 ubuntu 20.04 版本系統自帶的 MySQL 版本是 8.0,普通方法很難安裝 5.7 版本的。由於 8.0 版本較 5.7 版本做了不少改動,筆者比較習慣使用 5.7 版本。 網上搜做了一圈,跟著各種教程試了很多遍,最後終於找到了成功的方法。過程記錄分享出來,供大家參考。 安裝過 ...
背景介紹
ubuntu 20.04 版本系統自帶的 MySQL 版本是 8.0,普通方法很難安裝 5.7 版本的。由於 8.0 版本較 5.7 版本做了不少改動,筆者比較習慣使用 5.7 版本。
網上搜做了一圈,跟著各種教程試了很多遍,最後終於找到了成功的方法。過程記錄分享出來,供大家參考。
安裝過程
筆者的環境:
[email protected]:/home# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.4 LTS"
-
若已經安裝了 8.0 版本的 MySQL,請先操作刪除。
-
添加 MySQL 源
sudo vim /etc/apt/sources.list.d/mysql.list
添加如下內容,
deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-apt-config
deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-5.7
deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-tools
deb-src http://repo.mysql.com/apt/ubuntu/ bionic mysql-5.7
更新,
sudo apt update
執行過程中可能會出現如下錯誤,
W: GPG error: http://repo.mysql.com/apt/ubuntu bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 467B942D3A79BD29
E: The repository 'http://repo.mysql.com/apt/ubuntu bionic InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
執行如下命令即可,467B942D3A79BD29
根據實際情況替換。
root@hz192-168-1-55:/home# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
接著再重新執行更新,
sudo apt update
- 安裝 MySQL
查看支持的 MySQL 版本,此處我們已經可以看到有 5.7.40-1ubuntu18.04
,接近成功了。
root@hz192-168-1-55:/home# sudo apt-cache policy mysql-server
mysql-server:
Installed: (none)
Candidate: 8.0.30-0ubuntu0.20.04.2
Version table:
8.0.30-0ubuntu0.20.04.2 500
500 http://mirrors.aliyun.com/ubuntu focal-updates/main amd64 Packages
500 http://mirrors.aliyun.com/ubuntu focal-security/main amd64 Packages
8.0.19-0ubuntu5 500
500 http://mirrors.aliyun.com/ubuntu focal/main amd64 Packages
5.7.40-1ubuntu18.04 500
500 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 Packages
安裝 MySQL 5.7 版本客戶端和服務端,版本信息根據上面的輸出自行修改。
sudo apt install mysql-server=5.7.40-1ubuntu18.04
sudo apt install mysql-client=5.7.40-1ubuntu18.04
如無需安裝 mysql-client 服務,執行安裝 mysql-server 服務,可能會報如下錯誤。
只需要手動安裝 mysql-community-server 即可。sudo apt install mysql-community-server=5.7.40-1ubuntu18.04
The following packages have unmet dependencies:
mysql-server : Depends: mysql-community-server (= 5.7.40-1ubuntu18.04) but it is not going to be installed
- 驗證
root@hz192-168-1-55:/home# mysql --version
mysql Ver 14.14 Distrib 5.7.40, for Linux (x86_64) using EditLine wrapper
ok, 完結。踩坑君再次填好一個坑,接著去踩下一個啦。