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就可以成功连接至数据库了

你可能感兴趣的:(2003 - Can't connect to MySQL server on 'x.x.x.x' (10038))