远程连接Mysql数据库 ERROR 2003 (HY000)问题的解决方法

发布时间:2019-09-14编辑:脚本学堂
远程连接Mysql数据库时,出现错误提示:ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.0.19' (111)。本文给出解决方法,供大家参考。

用客户端及远程连接服务器mysql/ target=_blank class=infotextkey>mysql数据库的过程中,出现如下的提示消息:
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.0.19' (111)
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.0.19' (111)

原因在于:
Mysql数据库的默认配置文件my.cnf(linux下)中的bind-address默认为127.0.0.1,即便创建了可以 remote访问的用户,也不能使用mysql -h命令进行访问,若访问就会出现上出问题,因为此时Mysql只接受localhost,则需要把bind-address屏蔽掉。

my.cnf文件一般在/etc/mysql下面,如果不在使用locate my.cnf查找,修改前的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
#
# 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

需要屏蔽这个bind-address行,屏蔽后为:
 

复制代码 代码示例:
#
# 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
#
# 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

这样操作后,就可以用mysql -h命令进行相关操作了,如登录数据库:
 

复制代码 代码示例:
mysql -h 192.168.0.19 -u root -p

您可能感兴趣的文章:
mysql远程连接无法打开 解决mysql无法打开远程连接的问题
打开mysql中root账户的远程登录功能
配置mysql允许远程连接
Linux 下开启mysql远程访问功能的方法
mysql授权远程访问的例子
为Mysql添加远程用户的方法
Linux下启用MySQL数据库远程访问