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

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

谷歌了一下之后,原来是在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 #这里默认监听本地localhost

如果要让mysql监听到其他的地址,可以将bind-address = 127.0.0.1注释掉。 
或者将bind-address = 0.0.0.0监听所有的地址

屏蔽掉之后再次运行代码又出现: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,可以执行下面:(此处是对root用户授权mysql所有数据库)

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

如果针对某个特定的用户test授权某个指定的数据testdb用下面例子中的命令

mysql>GRANT ALL PRIVILEGES ON `testdb`.* TO 'test'@'%' IDENTIFIED BY 'newpwd' WITH GRANT OPTION; 

之后执行刷新数据库:

flush privileges;

如果要查看用户的权限,可以执行:

> show grants for 'root'@192.168.10.83

(一)MYSQL ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.10.210' (111) 解决方法的更多相关文章

  1. 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' (11 ...

  2. 连接mysql && ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

    上一篇:mysql服务正在启动 mysql服务无法启动 && mysql启动脚本 mysql关闭脚本 此篇目编写一个核心目的: 1.mysql连接 先抛出一个问题 这是因为mysql服 ...

  3. MySQL:ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

    错误 原因:可能是服务没有启动 以管理员身份打开cmd 输入 net start mysql

  4. mysql ERROR 2003 (HY000): Can't connect to MySQL server on '' (10060

    关闭防火墙即可连接成功: systemctl stop firewalld

  5. ERROR 2003 (HY000): Can't connect to MySQL server on 'ip address' (111)的处理办法

    远程连接mysql数据库时可以使用以下指令 mysql -h 192.168.1.104 -u root -p 如果是初次安装mysql,需要将所有/etc/mysql/内的所有配置文件的bind-a ...

  6. mysql绿色版安装问题解决(ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061))

    原来一直是使用MySQL安装版没有出现过问题,今天在安装绿色版MySQL时出现了点问题 在安装成windows服务成功后,用net start mysql 启动时提示启动成功,但当我连接mysql就报 ...

  7. 【linux错误解决】MySQL远程连接ERROR 2003 (HY000):Can't connect to MySQL server on'XXXXX'的问题

    问题描述: 从一台linux远程连接另一台linux上的MySQL, 出现ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx.xxx.x ...

  8. ERROR 2003 (HY000): Can't connect to MySQL server

    http://blog.csdn.net/longxibendi/article/details/6363934 一.问题的提出 /usr/local/webserver/mysql/bin/mysq ...

  9. ERROR 2003 (HY000): Can't connect to MySQL server on 'ip'(111)

    问题描述:  从一台linux远程连接另一台linux上的MySQL, 出现ERROR 2003 (HY000): Can't connect to MySQL server on 'ip'(111) ...

随机推荐

  1. js杨辉三角控制台输出

    function Yang(line){ var arr=new Array() ;i<=line;i++){ ]==undefined){arr[i-]=[];} ){arr[]=[i]}){ ...

  2. [.net 面向对象程序设计深入](18)实战设计模式——设计模式使用场景及原则

    [.net 面向对象程序设计深入](18)实战设计模式——设计模式使用场景及原则 1,什么是设计模式? 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计 ...

  3. vue+mescroll=VScrollFull

    VScrollFull 介绍 这个组件是什么? 是为了方便的使用下拉刷新,上拉加载而去封装的一个依赖于 mescroll.js 的 vue 组件(未发布,文末代码~) 封装这个组件使用了什么? mes ...

  4. [Swift]LeetCode320. 通用简写 $ Generalized Abbreviation

    Write a function to generate the generalized abbreviations of a word. Example: Given word = "wo ...

  5. [Swift]LeetCode645. 错误的集合 | Set Mismatch

    The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of ...

  6. [Swift]LeetCode816. 模糊坐标 | Ambiguous Coordinates

    We had some 2-dimensional coordinates, like "(1, 3)" or "(2, 0.5)".  Then, we re ...

  7. ubuntu18下安装docker

    1.通过指令检查linux内核 uname -a  可以看到大于3.10版本 2.检查是否存在对应目录 ls -l /sys/class/misc/device-mapper 3. apt-get指令 ...

  8. 在.NET中使用Redis

    dll文件 namespace RedisDemo { public partial class RedisPage : System.Web.UI.Page { protected void Pag ...

  9. Vue2.0中的transition组件

    组件的过度 Vue1.0中transition做为标签的行内属性被vue支持.但在Vue2.0中.Vue放弃了旧属性的支持并提供了transition组件,transition做为标签被使用. 使用t ...

  10. 总结Unity 初学者容易犯的编译与运行时错误

    总结Unity 初学者容易犯的编译与运行时错误 1: Untiy 出现编译错误: NewLine In Constant  解决方法:    方法一:如果报错脚本比较少量的话,可能用记事本打开报错的脚 ...