Ubuntu22.04 安装 MySQL5.7

Ubuntu22.04 安装 MySQL5.7

1 . 添加 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

执行过程中可能会出现如下错误

Err:5 http://repo.mysql.com/apt/ubuntu bionic InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY B7B3B788A8D3785C
Reading package lists... Done
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 B7B3B788A8D3785C
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

执行如下命令即可,B7B3B788A8D3785C 根据实际情况替换

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B7B3B788A8D3785C

接着再重新执行更新

sudo apt update

2 . 安装 MySQL

查看支持的 MySQL 版本,此处我们已经可以看到有 5.7.42-1ubuntu18.04,接近成功了

mysql-server:
  Installed: (none)
  Candidate: 8.0.36-0ubuntu0.22.04.1
  Version table:
     8.0.36-0ubuntu0.22.04.1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages
        500 http://us.archive.ubuntu.com/ubuntu jammy-security/main amd64 Packages
     8.0.28-0ubuntu4 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
     5.7.42-1ubuntu18.04 500
        500 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 Packages

安装 MySQL 5.7 版本客户端和服务端,版本信息根据上面的输出自行修改

sudo apt install mysql-client=5.7.42-1ubuntu18.04
sudo apt install mysql-server=5.7.42-1ubuntu18.04

3 . 验证

mysql --version
Comments are closed.