亲测-ubuntu20.04 安装 MySQL5.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"
  1. 若已经安装了 8.0 版本的 MySQL,请先操作删除。
  2. 添加 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根据实际情况替换。

    [email protected]:/home# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29

    接着再重新执行更新,

    sudo apt update
  3. 安装 MySQL

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

[email protected]:/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
  1. 验证

    [email protected]:/home# mysql --version
    mysql  Ver 14.14 Distrib 5.7.40, for Linux (x86_64) using  EditLine wrapper

    ok, 完结。踩坑君再次填好一个坑,接着去踩下一个啦。

    参考:

  2. Is it possible to install MySQL Server 5.7 on Ubuntu 19.10?
  3. Install MySQL 5.7 on Ubuntu 20.04

你可能感兴趣的:(亲测-ubuntu20.04 安装 MySQL5.7)