MYSQL ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.10.210' (111) 解决方法
程序员文章站
2022-04-21 08:17:27
今天在测试MySQL的连接时候,发现连接不通过,并报错ERROR 2003 (HY000): Can't connect to mysql server on '192.168.10.210' (111) 测试代码: 谷歌了一下之后,原来是在mysql的my.cnf中有下面一段代码: 如果要让mys ......
今天在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,可以执行下面:
grant all privileges on *.* to 'username'@'%' identified by 'password' with grant option;
之后执行刷新数据库:
flush privileges;
如果要查看用户的权限,可以执行:
> show grants for 'root'@192.168.10.83
文章转自:https://www.cnblogs.com/zmdComeOn/p/10376015.html
推荐阅读
-
Linux登录MySQL时出现 Can't connect to local MySQL server through socket '/tmp/mysql.sock'解决方法
-
连接Mysql提示Can’t connect to local MySQL server through socket的解决方法
-
MYSQL ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.10.210' (111) 解决方法
-
MySQL错误 ERROR 2002 (HY000): Can't connect to local MySQL server through socket 的解决办法
-
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)解决办法
-
MySQL问题记录——2003-Can't connect to MySQL server on 'localhost'(10038)
-
linux安装MySQL后输入mysql显示 ERROR 2002 (HY000): Can't connect to local MySQL server through socket
-
mysql2003-Can't connect to MySQL server (10060)
-
远程连接centos7 上的mysql报(ERROR 2003 (HY000): Can't connect to MySQL server on '168.x.x.x' (10060) )
-
关于CentOS输入mysql提示ERROR 2002 (HY000):Can't connect to_MySQL