mysql数据库,远程连接报错 not allowed to connect to this MysQL server

我们先来分析一下,这个错误,一般就是无权限,mysql拒绝了连接

解决也很简单,首先登录mysql

mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6538
Server version: 5.5.62-log Source distribution

Copyright (c) 2000, 2018, 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>show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |          |
+--------------------+
3 rows in set (0.00 sec)

找到mysql这个数据库,进入mysql数据库

mysql> use mysql;
Database changed

然后查询

mysql> show tables;
mysql> select Host, User,Password from user;
+-----------+------+-------------------------------------------+
| Host      | User | Password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| 127.0.0.1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| ::1       | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+------+-------------------------------------------+

看白名单没有你要远程登录,的ip

mysql> update user set host = '%' where user ='root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'

这是用通配符%,任何主机都能,远程连接mysql
这点注意了,它虽然报错了但是已经执行成功了,不用管它

mysql> select Host, User,Password from user;
+-----------+------+-------------------------------------------+
| Host      | User | Password                                  |
+-----------+------+-------------------------------------------+
| %         | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| 127.0.0.1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| ::1       | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+------+-------------------------------------------+
3 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

刷新一下就可以了,远程登录就成功了
如果还是失败,看一下端口对不对,我就是忽略了端口,导致改过之后还是连接不上,还是报这个错

你可能感兴趣的:(linux-mysql,mysql,数据库,linux,centos,ssh)