无法远程连接到MySQL服务器

时间:2017-02-08 13:13:49

标签: mysql linux azure azure-virtual-machine

我已经为这个问题读了很多答案,但没有找到决心。 我在Azure上有一个mysql服务器(例如13.25.147.140)。

的my.cnf:

[mysqld]
# bind-address=127.0.0.1
init_connect= ^`^xSET collation_connection = utf8_unicode_ci ^`^y
character-set-server = utf8
collation-server = utf8_unicode_ci

[client]
default-character-set = utf8

然后,我做了sudo service mysql restart

然后,授予root权限:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'57.26.24.157' IDENTIFIED BY 'password' WITH GRANT OPTION;
mysql> SELECT user, host from user;
+------------------+--------------+
| user             | host         |
+------------------+--------------+
| root             | %            |
| root             | 57.26.24.157 |
| debian-sys-maint | localhost    |
| mysql.sys        | localhost    |
| paymon           | localhost    |
| phpmyadmin       | localhost    |
| root             | localhost    |
+------------------+--------------+

但是当我尝试从我的电脑连接时,我得到了这个:

mysql -u root -p -h 13.25.147.140
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'57.26.24.157' (using password: YES)

我该如何解决?

1 个答案:

答案 0 :(得分:0)

默认情况下,mysql远程禁止root登录,这是一个安全预防措施。 如果您想使用root远程登录进行某些测试,我们可以使用此命令对其进行修改:

[root@jasonvm etc]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution
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 from user where user="root";
+-----------+------+
| host      | user |
+-----------+------+
| %         | root |
| 127.0.0.1 | root |
| localhost | root |
+-----------+------+
3 rows in set (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;
Query OK, 0 rows affected (0.00 sec)

另一个使用root登录mysql的VM:

[root@localhost ~]# mysql -u root -p -h 40.71.33.231
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

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

MySQL [(none)]> 
相关问题