(一)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)
测试代码:
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
作者:子钦加油
出处:https://www.cnblogs.com/zmdComeOn/
个性签名:努力生活,努力走路
阿里云拼团:https://www.aliyun.com/1111/home?userCode=f4ee1llo1核2G1M,86一年,229三年;2核4G5M,799三年;2核8G5M,1399三年
腾讯云三月采购计划特价:https://cloud.tencent.com/act/cps/redirect?redirect=1073&cps_key=15d0b1673287c43fe946626d9f4e2eee&from=console1核2G1M,88一年;1核2G1M,268三年;2核4G5M,998一年;4核8G5M,2888元三年
出处:https://www.cnblogs.com/zmdComeOn/
个性签名:努力生活,努力走路
阿里云拼团:https://www.aliyun.com/1111/home?userCode=f4ee1llo1核2G1M,86一年,229三年;2核4G5M,799三年;2核8G5M,1399三年
腾讯云三月采购计划特价:https://cloud.tencent.com/act/cps/redirect?redirect=1073&cps_key=15d0b1673287c43fe946626d9f4e2eee&from=console1核2G1M,88一年;1核2G1M,268三年;2核4G5M,998一年;4核8G5M,2888元三年