解决"ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.247.128' (111)"

来源:互联网 发布:皇室战争迫击炮数据 编辑:程序博客网 时间:2024/06/06 12:40
1. 问题描述
在连接数据库时出现连接失败信息:
xx@ubuntu:~$ mysql -h192.168.247.128 -uroot -p123456mysql: [Warning] Using a password on the command line interface can be insecure.ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.247.128' (111)xx@ubuntu:~$
2. 解决方法
出现上面mysql数据库连接失败的原因是多种的, 其中可用ping ip来看看网络是否畅通,下面是本人的解决方法。
这是因为之前我进行了root密码设置操作,
root@ubuntu:/usr/local/mysql/bin# ./mysqld_safe --user=mysql --skip-grant-tables --skip-networking&  [1] 5810
注意上面的--skip-grant-tables --skip-networking,只允许本地socket连接, 放弃对TCP/IP的监听 
在解决上述问题之前,我们先保证已经对mysql数据库进行远程授权, 
进入/usr/local/mysql/support-files/下, 执行以下命令:
# cp my-default.cnf my.cnf
这里得到了mysql数据库的配置文件my.cnf, 再重启mysql服务, 然后 执行 mysql -h192.168.247.128 -uroot -p  (ps:主机ip请输入自己的)
并输入数据库用户root的密码即可连接mysql数据库。如下:
xx@ubuntu:/usr/local/mysql$ sudo ./support-files/mysql.server restart[sudo] password for xx: Shutting down MySQL.... * Starting MySQL.. * xx@ubuntu:/usr/local/mysql$ mysql -h192.168.245.128 -uroot -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.7.5-m15 MySQL Community Server (GPL)Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 
 
 
 
OK, Enjoy it!!!
                                             
0 0