云服务器ubantu下的mysql远程访问_以node.js替例
【非原创】
出处请访问:http://www.voidcn.com/blog/ctroll/article/p-4949801.html
【出现问题】
默认没有开远程访问
会提示MySQL错误:Can't connect to MySQL server (10060/1)的错误[1],需要从以下几个方面入手:【解决方案】
1、任何远程主机都可以访问数据库
//[解释] 允许root用户以任何IP地址访问全部数据库
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
//需要输入更新命令使修改生效
mysql> FLUSH PRIVILEGES;
//退出
mysql> EXIT
2、修改ubantu服务器下mysql配置文件my.cnf.
//默认绑定的是bind-address = 127.0.0.1,需要修改
#sudo vim /etc/mysql/my.cnf
注释掉 bind-address = ********一句前边加上 #
再加上一下两句:
skip-external-locking
skip-name-resolve
//重启mysql
#sudo service mysql restart
一般到第二步问题就解决了。
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服务器允许和限制访问