开启mysql远程访问过程当中所遇常见问题的解决办法

MYSQL ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.10.210' (111) 解决方法

今天在测试MySQL的链接时候,发现链接不经过,并报错ERROR 2003 (HY000): Can't connect to mysql server on '192.168.10.210' (111) 
测试代码:html

require 'mysql2' client = Mysql2::Client.new(:host=>"192.168.10.210",:username=>'root',:password=>"root") puts results = client.query("show databases;")

谷歌了一下以后,原来是在mysql的my.cnf中有下面一段代码:mysql

# 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 #这里默认监听本地localhost

若是要让mysql监听到其余的地址,能够将bind-address = 127.0.0.1注释掉。 
或者将bind-address = 0.0.0.0监听全部的地址sql

屏蔽掉以后再次运行代码又出现:Host '192.168.10.83' is not allowed to connect to this MySQL server 
这里写图片描述 
解决方法: 
若是想让192.168.10.83可以链接到本地的这个数据库,要让数据库给其分配权限,登陆mysql,执行:(username 和 password是登陆mysql的用户名和密码)数据库

GRANT ALL PRIVILEGES ON *.* TO 'username'@'192.168.10.83' IDENTIFIED BY 'password' WITH GRANT OPTION;

若是要想全部的外部ip地址都可以访问使用mysql,能够执行下面:less

GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

以后执行刷新数据库:tcp

flush privileges;

若是要查看用户的权限,能够执行:post

> show grants for 'root'@192.168.10.83

这里写图片描述

以上摘抄于:测试

http://www.cnblogs.com/zihanxing/p/7049244.htmlui

 

CentOS6开启MySQL远程访问

1.开放MySQL访问端口3306this

修改防火墙配置文件

vi /etc/sysconfig/iptables 

加入端口配置     

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

从新加载规则

service iptables restart  


2.修改mysql库里的host

登陆mysql;

use mysql

update user set host='%' where user='root' and host='localhost';

记得必定还得修改密码,由于这时密码已失效,虽然本地还能够原密码登陆,可远程改了host后仍是无法访问

UPDATE user SET password=password("root") WHERE user='root'; 

flush privileges;

3.重启mysql,远程就能够访问了

service mysqld restart;


 CentOS7开启MySQL远程访问

CentOS7这个版本的防火墙默认使用的是firewall,与以前的版本使用iptables不同。按以下方便配置防火墙:

一、关闭防火墙:sudo systemctl stop firewalld.service


二、关闭开机启动:sudo systemctl disable firewalld.service

 

三、安装iptables防火墙

执行如下命令安装iptables防火墙:sudo yum install iptables-services

 

四、配置iptables防火墙,打开指定端口(CentOS6同样)

五、设置iptables防火墙开机启动:sudo systemctl enable iptables

六、以后的和CentOS6同样


CentOS下防火墙的基本操做命令

CentOS 配置防火墙操做实例(启、停、开、闭端口):

 

注:防火墙的基本操做命令:

查询防火墙状态:

[root@localhost ~]# service   iptables status

中止防火墙:

[root@localhost ~]# service   iptables stop 

启动防火墙:

[root@localhost ~]# service   iptables start 

重启防火墙:

[root@localhost ~]# service   iptables restart

永久关闭防火墙:

[root@localhost ~]# chkconfig   iptables off

永久关闭后启用:

[root@localhost ~]# chkconfig   iptables on

以上摘抄于:

https://www.cnblogs.com/qianzf/p/6995140.html

 

若是上述列出的方案不可以解决你遇到的问题,能够参考以下mysql官方网页:

https://dev.mysql.com/doc/refman/5.6/en/problems-connecting.html

相关文章
相关标签/搜索