环境如下
添加 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
执行过程中可能会出现如下错误,
y@y:~$ sudo apt update
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Get:4 http://repo.mysql.com/apt/ubuntu bionic InRelease [20.0 kB]
Hit:5 http://archive.ubuntu.com/ubuntu focal-security InRelease
Err:4 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
安装 MySQL
查看支持的 MySQL 版本
sudo apt-cache policy mysql-server
y@y:~$ sudo apt-cache policy mysql-server
mysql-server:
Installed: (none)
Candidate: 8.0.40-0ubuntu0.20.04.1
Version table:
8.0.40-0ubuntu0.20.04.1 500
500 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
500 http://archive.ubuntu.com/ubuntu focal-security/main amd64 Packages
8.0.19-0ubuntu5 500
500 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages
5.7.42-1ubuntu18.04 500
500 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 Packages
可以看到有 5.7.40-1ubuntu18.04,接近成功了
安装 MySQL 5.7 版本客户端和服务端,版本信息根据上面的输出自行修改。
安装客户端
如无需安装 mysql-client 服务,执行安装 mysql-server 服务,可能会报如下错误。
只需要手动安装 mysql-community-server 即可。sudo apt install mysql-community-server=5.7.42-1ubuntu18.04
sudo apt install mysql-client=5.7.42-1ubuntu18.04
安装服务端(安装服务端的过程中 会让 输入 MySQL 的密码)
sudo apt install mysql-server=5.7.42-1ubuntu18.04
配置 MySQL 监听地址及其端口
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
查看文件内容,并修改如下
bind-address 我装好默认是127.0.0.1,需要修改
port 我装好没有,需要自行添加
bind-address = 0.0.0.0
port = 3306
All done, enjoy it!
评论 (0)