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

1. 问题描述
在连接数据库时出现连接失败信息:
xx@ubuntu:~$ mysql -h192.168.247.128 -uroot -p123456
mysql: [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 -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server 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 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> 
 
 
 
 
OK, Enjoy it!!!
 
 
 

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值