ubuntu 20.04安装mysql5.7

ubuntu 22.04系统安装mysql5.7

一、查看系统默认安装的数据库版本

apt-get update
apt-cache policy mysql-server

image

ubuntu 20.04自带的版本是8.0.34,而我们需要安装mysql5.7的版本就需要换源

二、更换apt源

1. 备份原来的source文件

cp /etc/apt/sources.list /etc/apt/sources.list.back

2.修改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

image

- 再次查看默认安装的mysql数据库版本,可以看到默认的已经变成了mysql5.7的版本了。

apt-cache policy mysql-serverimage

四、安装mysql数据库

apt-get -y install mysql-server-5.7

## 查看mysql是否安装成功
1.dpkg -l | grep mysql
2.mysql -V
3.systemctl status mysql

image

- 设置开启自启

systemctl enable mysql

五、修改mysql root密码和换回apt源

1. 修改mysql数据库密码

# 此时无需密码即可进入
mysql

# 修改密码
use mysql;
alter user root@'localhost' identified with mysql_native_password by "12345678";
flush privileges;

2. 更换apt源

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

至此mysql5.7数据库安装完成。

posted @ 2023-10-16 14:05  wltianOne  阅读(1946)  评论(0编辑  收藏  举报