在网上找了很久,都是到官网下载安装包,最后终于找到了一个非常简便的方法!

⭐参考文章:ubuntu 20.04安装mysql5.7 - wltianOne - 博客园

查看自己源对应的mysql版本:

apt-cache policy mysql-server

说明直接使用apt-get install mysql-server会直接安装mysql8.0版本 

root@ruihanna-virtual-machine:/etc/apt# apt-cache policy mysql-server
mysql-server:
  已安装:(无)
  候选: 8.0.39-0ubuntu0.22.04.1
  版本列表:
     8.0.39-0ubuntu0.22.04.1 500
        500 http://mirrors.aliyun.com/ubuntu jammy-updates/main amd64 Packages
        500 http://mirrors.aliyun.com/ubuntu jammy-updates/main i386 Packages
        500 http://mirrors.aliyun.com/ubuntu jammy-security/main amd64 Packages
        500 http://mirrors.aliyun.com/ubuntu jammy-security/main i386 Packages
     8.0.28-0ubuntu4 500
        500 http://mirrors.aliyun.com/ubuntu jammy/main amd64 Packages
        500 http://mirrors.aliyun.com/ubuntu jammy/main i386 Packages

 换源实现安装mysql5.7:

#  阿里源
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

备份sources.list, 并换为以上阿里源

cp /etc/apt/sources.list /etc/apt/sources.list.back
cd /etc/apt
vim sources.list # 换源

# 更新源
gpg --keyserver keyserver.ubuntu.com --recv 3B4FE6ACC0B21F32
gpg --export --armor 3B4FE6ACC0B21F32 | apt-key add -
apt-get update

 再次查看对应mysql版本:

root@ruihanna-virtual-machine:/home/hadoop# apt-cache policy mysql-server
mysql-server:
  已安装:(无)
  候选: 5.7.42-0ubuntu0.18.04.1
  版本列表:
     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

安装mysql5.7,查看mysql版本,验证是否安装成功

apt-get -y install mysql-server-5.7 # 安装
mysql -V # 查看mysql版本

最后,换回镜像源

cd /etc/apt
mv sources.list sources.list.old
mv sources.list.back  sources.list
apt-get update

 

Logo

欢迎加入西安开发者社区!我们致力于为西安地区的开发者提供学习、合作和成长的机会。参与我们的活动,与专家分享最新技术趋势,解决挑战,探索创新。加入我们,共同打造技术社区!

更多推荐