记录下个人在ubantu20.04安装mysql5.7的过程
开始时是打算用安装包安装的,但是下载下安装包解压后安装报错.deb文件损坏可能是下载时候出的问题就改用了源安装
1,添加源
$ wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb
2,安装存储库
$ sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb
2.1选择 Ubuntu bionic,然后单击确定
2.2提示显示默认选择的MySQL 8.0。选择第一个选项,然后单击确定
2.3选择 MySQL 5.7 服务器,然后单击确定
2.4提示默认选择MySQL5.7。选择最后一个 Ok,然后单击 OK
3,更新软件包
$sudo apt update
如报错:
命中:1 http://security.ubuntu.com/ubuntu focal-security InRelease
获取:2 http://repo.mysql.com/apt/ubuntu bionic InRelease [20.0 kB]
命中:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal InRelease
命中:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates InRelease
命中:5 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports InRelease
错误:2 http://repo.mysql.com/apt/ubuntu bionic InRelease
由于没有公钥,无法验证下列签名: NO_PUBKEY B7B3B788A8D3785C
正在读取软件包列表... 完成
W: GPG 错误:http://repo.mysql.com/apt/ubuntu bionic InRelease: 由于没有公钥,无法验证下列签名: NO_PUBKEY B7B3B788A8D3785C
E: 仓库 “http://repo.mysql.com/apt/ubuntu bionic InRelease” 没有数字签名。
N: 无法安全地用该源进行更新,所以默认禁用该源。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。
注意这两个值要一样
执行
$ apt-key adv --keyserver keyserver.ubuntu.com --recv B7B3B788A8D3785C
$ sudo apt update 再次更新
4,查看mysql5.7 包
$ apt-cache policy mysql-server
5, 安装 MySQL 5.7
$ sudo apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7*
6,$ sudo mysql_secure_installation
当系统提示输入密码时,请提供上面设置的 root 密码。设置用户的密码长度,用户登录账号权限
Enter current password for root (enter for none): <Enter password>
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: Y
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
Using existing password for root.
Estimated strength of the password: 25
Change the password for root ? ((Press y|Y for Yes, any other key for No) : d
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
Thanks for using MariaDB!
7,修改配置文件
/etc/mysql/mysql.conf.d$ sudo vi mysqld.cnf
查找行“bind_address”并更改如下:
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
bind-address = 0.0.0.0
八,$ systemctl restart mysql 重启服务
九,$ sudo systemctl status mysql 查看服务状态
十,修改用户权限
$ mysql -u root -p
mysql> use mysql
mysql> select host,user from user;
mysql> update user set host='%' where user='root';
mysql> select host,user from user;
mysql> flush privileges;
十一,远程测试连接