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

   Debian7 系统远程连接mysql数据库时出现如下错误:

# mysql -h 192.168.1.116 -u root 
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.116' (111)

Debian 7 操作系统 MYSQL数据库默认连接主机为localhost,如果需要远程连接,需要配置bind-address配置项,步骤如下:  

    打开mysql配置文件

vim /etc/mysql/my.cnf

   

    找到默认连接主机的配置项(bind-address),修改为数据库主机IP

bind-address= 127.0.0.1  // 修改为数据库主机所在服务器IP如: bind-address=192.168.1.102

 

   保存重启mysql配置完成

/etc/init.d/mysql  restart

   

    在/etc/hosts写入主机解析

192.168.1.116    t1  //添加主机解析。

  

  连接数据库

# mysql -h t1  -u root -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.1.66-0+squeeze1linx2 (Debian)

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

    完成。觉得有用给个赞亲!






你可能感兴趣的:(ERROR 2003 (HY000): Can't connect to MySQL server)