作者:E4b9a6, 创建:2021-06-15, 字数:810, 已阅:61, 最后更新:2024-03-10
今天在内网机器上搭建一个测试MariaDB数据库,按照习惯配置远程访问
CREATE USER chancel@chancel IDENTIFIED BY 'chancel';
GRANT ALL PRIVILEGES ON chancel_api.* TO 'chancel'@'192.168.11.13' IDENTIFIED BY 'chancel' WITH GRANT OPTION;
然后在远程机器上访问到时候弹出了connect reset,这很明显说连接到端口就被拒绝了,看了下防火墙也是打开3306的默认端口,猜测下可能是MariaDB的问题
查查3306端口的情况
chancel@chancel-nas /etc/mysql/mariadb.conf.d » netstat -ntulp | grep 3306
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 127.0.0.1:3306 0.0.0.0:* LISTEN
显然说db绑定了127.0.0.1的本地端口导致外网连接不了,找一下MariaDB到配置文件,编辑‘127.0.0.1’并改成'0.0.0.0'即可
chancel@chancel-nas ~» vim /etc/mysql/mariadb.conf.d/50-server.cnf
...
bind-address = 0.0.0.0 # 编辑‘127.0.0.1’并改成'0.0.0.0'即可
...