Can';t远程连接到MySQL服务器

Can';t远程连接到MySQL服务器,mysql,linux,azure,azure-virtual-machine,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] defa

我已经读了很多关于这个问题的答案,但没有找到解决办法。 我在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服务mysql

然后,为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)

如何解决这个问题?

默认情况下,mysql不允许根用户远程登录,这是一种安全预防措施。 如果您想使用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)]> 

这不是一个真正的问题,因为你似乎有坚实的连通性。你试过创建一个普通用户吗?您可以参考my Linux on Azure guide for MariaDB,以了解如何做到这一点。我认为这是一个很好的下一步。我的数据库中有“root@%”。@VladMarkushin请尝试这个命令,我使用mysql 2grant所有权限。使用grant选项发送到由“密码”标识的“根”@“%”@VladMarkushin在我的测试中,选择结果与您相同,但仍然不能远程使用root登录,我们应该授予所有权限。到“根”@“%”。好的,我用另一种方式告诉您。我的数据库中有“root@%”,因为我之前已经使用了“授予所有权限”。要授予“root@%”,请在授予所有权限之前选择“mysql”数据库,使用命令“使用mysql;”