MySQL remote access under cloud server ubantu_Take node.js as an example

【Non-original】

For the source, please visit: http://www.voidcn.com/blog/ctroll/article/p-4949801.html

 

【problem appear】

Remote access is not enabled by default

It will prompt MySQL error: Can't connect to MySQL server (10060/1) error[1], we need to start from the following aspects: [Solution]

1. Any remote host can access the database  

     //[Explanation] Allow root user to access all databases with any IP address

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;

    

    //You need to enter the update command to make the changes take effect

mysql> FLUSH PRIVILEGES;      

    //quit

mysql> EXIT     

 

 

2. Modify the mysql configuration file my.cnf under the ubantu server.

     //The default binding is bind-address = 127.0.0.1, which needs to be modified

# sudo vim /etc/mysql/my.cnf    

      Comment out bind-address = ******** and add # before the sentence 

      Add the following two sentences:

          skip-external-locking

          skip-name-resolve

 

     // restart mysql

#sudo  service mysql restart 

 Usually the problem is solved in the second step.

 

3、sudo apt-get install mysql-server mysql-client[2]组件安装全。

 

4、关闭防火墙,或者是添加好3306端口的开放。[3]

#/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

 #/etc/rc.d/init.d/iptables save  保存:

  # service iptables restart 重启生效

 或者 /sbin/iptables-save 

 

当然除了开放3306端口外,还有一个方法就是关闭防火墙,命令为:

  # service iptables stop 

 

5、添加访问允许

/etc/hosts.allow [4]

mysqld : ALL : ALLOW

mysqld-max : ALL :ALLOW

 

修改/etc/hosts.allow和/etc/hosts.deny允许linux服务器允许和限制访问

 

对于能过xinetd程序启动的网络服务,比如ftp telnet,我们就可以修改/etc/hosts.allow和/etc/hosts.deny的配置,来许可或者拒绝哪些IP、主机、用户可以访问。

【参考链接】

[1]http://www.2cto.com/database/201307/224401.html使用sqlyog远程连接mysql错误2003 cant connect to mysql 10060/10061解决方法

[2]http://jingyan.baidu.com/article/425e69e6bbc6c7be14fc1640.htmlUbuntu 14.04数据库服务器--mysql的安装和配置

[3]http://www.voidcn.com/blog/zhu_xun/article/p-2663301.htmlCan't connect to MySQL server (10060)异常解决方法

[4]http://www.2cto.com/os/201310/250376.html修改/etc/hosts.allow和/etc/hosts.deny允许linux服务器允许和限制访问

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326449849&siteId=291194637