[size=medium][b]1、确认一下3306是否对外开放,MySQL默认状态下是不开放对外访问功能的。查看的办法如下:
[/b][/size]
~# netstat -an | grep 3306
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
[size=medium]可以看出,mysql的3306端口只是监听本地的连接,这样就阻碍了外部IP对该数据库的访问。
[b]2、进入到mysql的配置文件所在目录(/etc/mysql/my.cnf)下,找到文件中的如下内容:[/b][/size]
# 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
[size=medium]将bind-address注释掉,或者改成你想要使用的客户端主机IP。
这样mysql的远程访问端口就算开启了,下面还有一个更重要的步骤,就是要给远程用户授权。
[b]3、确认客户端用户是否具有访问权限[/b][/size]
mysql> grant all on *.* to user_name@'%' identified by 'user_password';
[size=medium][b]4、重启服务[/b][/size]
sudo /etc/init.d/mysql restart
[/b][/size]
~# netstat -an | grep 3306
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
[size=medium]可以看出,mysql的3306端口只是监听本地的连接,这样就阻碍了外部IP对该数据库的访问。
[b]2、进入到mysql的配置文件所在目录(/etc/mysql/my.cnf)下,找到文件中的如下内容:[/b][/size]
# 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
[size=medium]将bind-address注释掉,或者改成你想要使用的客户端主机IP。
这样mysql的远程访问端口就算开启了,下面还有一个更重要的步骤,就是要给远程用户授权。
[b]3、确认客户端用户是否具有访问权限[/b][/size]
mysql> grant all on *.* to user_name@'%' identified by 'user_password';
[size=medium][b]4、重启服务[/b][/size]
sudo /etc/init.d/mysql restart