Ubuntu 20.x 安装 MySQL8.x 并配置远程连接

安装MySQL8.x

1
2
3
4
#命令1
sudo apt-get update
#命令2
sudo apt-get install mysql-server

配置MySQL

开始初始化

1
sudo mysql_secure_installation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#1
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N (我的选项)

#2
Please set the password for root here...
New password: (输入密码)
Re-enter new password: (重复输入)

#3
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的选项)

#4
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network...
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y (我的选项)

#5
By default, MySQL comes with a database named 'test' that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项)

#6
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的选项)

检查mysql服务状态:

1
systemctl status mysql.service

显示如下结果说明mysql服务是正常的:

配置远程访问

首先用根用户进入:

1
sudo mysql -uroot -p

在mysql数据库就行下一步操作,使用use mysql 命令进入mysql数据库 。

创建新用户

1
create user 'admin'@'%' identified by 'password';

执行授权

1
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%';

刷新权限

1
flush privileges;

授权远程

1
ALTER USER 'admin'@'%' IDENTIFIED WITH mysql_native_password BY 'password';

刷新权限

1
flush privileges;

使用 exit 命令退出后,修改 mysql 的配置文件
进入mysql安装目录的etc/mysql/mysql.conf.d处,打开终端,并切换root权限,修改mysqld.cnf文件为可修改。

找到 “bind-address = 127.0.0.1” , 修改为 bind-address = 0.0.0.0 并保存

重新修改权限为只读。

重启mysql服务

1
service mysql restart

通过ifconfig命令查看IP地址

利用Navicat 远程连接测试:
测试用过


Ubuntu 20.x 安装 MySQL8.x 并配置远程连接
https://www.liaomz.top/2020/12/28/ubuntu-20.x-an-zhuang-mysql8.x-bing-pei-zhi-yuan-cheng-lian-jie/
作者
发布于
2020年12月28日
许可协议