通过以下命令查看系统默认的mysql-server版本:
apt-cache policy mysql-server
如果找不到,先执行以下命令:
apt-get update
第一步命令输入以下内容:
mysql-server:
Installed: (none)
Candidate: 8.0.37-0ubuntu0.20.04.3
Version table:
8.0.37-0ubuntu0.20.04.3 500
500 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/main amd64 Packages
500 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/main i386 Packages
500 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/main amd64 Packages
500 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/main i386 Packages
8.0.19-0ubuntu5 500
500 http://mirrors.cloud.aliyuncs.com/ubuntu focal/main amd64 Packages
500 http://mirrors.cloud.aliyuncs.com/ubuntu focal/main i386 Packages
可以看到只有8.0版本。
以下通过更换安装源的方式,切换5.7版本。
首先在/etc/apt/sources.list文件中添加以下安装源:
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
接着需要安装证书:
gpg --keyserver keyserver.ubuntu.com --recv 3B4FE6ACC0B21F32
gpg --export --armor 3B4FE6ACC0B21F32 | apt-key add -
最后刷新一下缓存:
apt-get update
再次执行命令:
apt-cache policy mysql-server
输出以下内容:
mysql-server:
Installed: (none)
Candidate: 8.0.37-0ubuntu0.20.04.3
Version table:
8.0.37-0ubuntu0.20.04.3 500
500 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/main amd64 Packages
500 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/main i386 Packages
500 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/main amd64 Packages
500 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security/main i386 Packages
8.0.19-0ubuntu5 500
500 http://mirrors.cloud.aliyuncs.com/ubuntu focal/main amd64 Packages
500 http://mirrors.cloud.aliyuncs.com/ubuntu focal/main i386 Packages
5.7.42-0ubuntu0.18.04.1 500
500 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 Packages
500 http://mirrors.aliyun.com/ubuntu bionic-security/main i386 Packages
500 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 Packages
500 http://mirrors.aliyun.com/ubuntu bionic-updates/main i386 Packages
5.7.21-1ubuntu1 500
500 http://mirrors.aliyun.com/ubuntu bionic/main amd64 Packages
500 http://mirrors.aliyun.com/ubuntu bionic/main i386 Packages
此时就可以通过apt-get
命令安装5.7版本了。