[software development] MySQL8设置远程访问权限
Tofloor
poster avatar
191******22
deepin
2023-09-26 05:01
Author
#进入mysql
mysql -uroot -p

# 选择mysql
use mysql;

# 更新user表中的字段
update user set host='%'where user='root';

#刷新
flush privileges;

# 设置远程访问的权限 
grant all privileges on *.* to 'root'@'%' with grant option;

#刷新
flush privileges;
Reply Favorite View the author
All Replies
爱开发
deepin
2023-09-26 05:10
#1

这样不安全。其实可以不必这样的。使用 ssh -LN 将远程端口映射到本地即可。

Reply View the author
蔡EEPIN
deepin
2023-09-26 06:44
#2

不建议从mysql配置允许外网连接,端口转发是个好路子

Reply View the author
捕风
deepin
2023-09-26 18:33
#3
爱开发

这样不安全。其实可以不必这样的。使用 ssh -LN 将远程端口映射到本地即可。

细说下

Reply View the author
爱开发
deepin
2023-09-26 19:08
#4
捕风

细说下

# ssh -L 9999:example.org:80 -N -T username@remote_host
ssh -NL LocalPort:RemoteAddr:RemotePort root@xxx.com

ssh -NL 3307:example.org:3306 root@remote_ip -p remote_port

#
ssh -L 9999:example.org:80 -N -i ~/.ssh/id_rsa -p 2022 root@example.org

ssh -L 3307:127.0.0.1:3306 -N -i  ~/.ssh/id_rsa -p 2022 root@8.8.8.8

有些gui软件可以直接桥接的,比如 dbeaver

Reply View the author
h***e@gmail.com
deepin
2025-10-20 18:51
#5
The user is banned, and the content is hidden.
观摩
deepin
2025-10-20 21:21
#6
爱开发

这样不安全。其实可以不必这样的。使用 ssh -LN 将远程端口映射到本地即可。

开放端口,加IP限制,不用转发。

Reply View the author
g***g@gmail.com
deepin
2025-10-29 11:51
#7

打开 MySQL 配置文件 (一般为 /etc/mysql/mysql.conf.d/mysqld.cnf/etc/my.cnf

Reply View the author