当前位置:服务支持 >  软件文章 >  MySQL远程连接:bind-address参数详解

MySQL远程连接:bind-address参数详解

阅读数 329
点赞 39
article_banner

1. 3306端口是不是没有打开?

使用nestat命令查看3306端口状态:

~# netstat -an | grep 3306

tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN

从结果可以看出3306端口只是在IP 127.0.0.1上监听,所以拒绝了其他IP的访问。

解决方法:修改/etc/mysql/my.cnf文件。打开文件,找到下面内容:

# 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

把上面这一行注释掉或者把127.0.0.1换成合适的IP,建议注释掉。

重新启动后,重新使用netstat检测:

~# netstat -an | grep 3306tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN

2. 问题解决了吗?

现在使用下面命令测试:

~# mysql -h 10.1.1.2 -u root -p

Enter password:

ERROR 1130 (00000): Host 'B0324-Desktop.local' is not allowed to connect to this MySQL server

结果出乎意料,还是不行。

解决方法:原来还需要把用户权限分配各远程用户。

登录到mysql服务器,使用grant命令分配权限

mysql> grant all on database_name.* touser_name@'%' identified by 'user_password';

其中database_name、user_name和user_password根据实际情况设置。

完成后使用mysql命令连接,提示成功,为了确保正确可以再远程登陆测试一下

相关文章
QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利