2003 - Can't connect to MySQL server on 'x.x.x.x' (10038)

Linux Distribution:Ubuntu 14

MySQL版本:5.5.47

安装完成后使用Navicat连接一下,但是报错了:

mysql服务没问题:

sean@sean:~$ ps -ef|grep mysqld
mysql      1219      1  0 21:09 ?        00:00:01 /usr/sbin/mysqld
sean      10373   9602  0 21:38 pts/7    00:00:00 grep --color=auto mysqld

并且本地的登录也能成功:

sean@sean:~$ mysql -u root -h 127.0.0.1
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 40
Server version: 5.5.47-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2015, 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> 

但是使用外网地址却无法登录:

sean@sean:~$ mysql -u root -h 192.168.137.128
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.137.128' (111)

于是修改了一下MySQL的配置文件:

sean@sean:~$ sudo vi /etc/mysql/my.cnf 

在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服务:

sean@sean:~$ sudo service mysql restart
mysql stop/waiting
mysql start/running, process 11622

原先的问题解决了,现在遇到了新的问题:

再次搜索了一下,发现是授权的问题

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host, user, password from user;
+-----------+------------------+-------------------------------------------+
| host      | user             | password                                  |
+-----------+------------------+-------------------------------------------+
| localhost | root             |                                           |
| sean      | root             |                                           |
| 127.0.0.1 | root             |                                           |
| ::1       | root             |                                           |
| localhost | debian-sys-maint | *0AA379AB8AFD785B32D661A07E9D5C7A24E3B186 |
+-----------+------------------+-------------------------------------------+
5 rows in set (0.00 sec)

mysql> update user set host = "%" where host = "sean" and user = "root";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select host, user, password from user;
+-----------+------------------+-------------------------------------------+
| host      | user             | password                                  |
+-----------+------------------+-------------------------------------------+
| localhost | root             |                                           |
| %         | root             |                                           |
| 127.0.0.1 | root             |                                           |
| ::1       | root             |                                           |
| localhost | debian-sys-maint | *0AA379AB8AFD785B32D661A07E9D5C7A24E3B186 |
+-----------+------------------+-------------------------------------------+
5 rows in set (0.00 sec)

之后使用Navicat就可以成功连接至数据库了

  • 8
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值