MySQL8允许远程访问连接
# 简介
在开发阶段,允许数据库远程访问,可以更灵活的管理数据。出于安全考虑,数据库安装后默认是不允许远程访问的,这个时候就需要手动修改一下配置了。
# 修改配置
# 开放数据库连接端口
MySQL 默认使用的是 3306 端口,如果是你修改了使用其它端口,开放该端口即可。当然可以直接关闭防火墙(适用开发阶段)。
# 修改数据表配置
登录数据,修改配置。
mysql> use mysql;
Database changed
mysql> update user set host='%' where user ='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 修改数据库配置文件
编辑文件 /etc/mysql/mysql.conf.d/mysqld.cnf
,修改 bind-address。
# If MySQL is running as a replication slave, this should be
# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
# tmpdir = /tmp
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address = 127.0.0.1
bind-address = 0.0.0.0
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
重启数据库。
╭─root@ubuntu /etc/mysql/mysql.conf.d
╰─➤ service mysql restart;
1
2
2
# 测试是否能够远程访问连接
上次更新: 2023/09/19, 14:48:57