Mysql连接报错:130 - Host ‘1*6.2*2.1*3.1*8‘ is not allowed to connect to this MySQL server


一、问题原因

1、出现这个问题就是说没有给远程连接权限。

在这里插入图片描述

二、 解决步骤

1、连接服务器 mysql -u root -p
[root@izbp1g3qo24yvt8e0635uxz /]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS         PORTS                                                                                                         NAMES
ed7e0fb12ca1   golang                "/bin/bash"              12 months ago   Up 12 months                                                                                                                 gifted_wilbur
146c021e1fcf   redis                 "docker-entrypoint.s…"   12 months ago   Up 12 months   6379/tcp                                                                                                      charming_visvesvaraya
dfa777b4a403   rabbitmq:management   "docker-entrypoint.s…"   13 months ago   Up 13 months   4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp   rabbitmq
336197ac3c79   mysql:latest          "docker-entrypoint.s…"   20 months ago   Up 13 months   0.0.0.0:3306->3306/tcp, 33060/tcp                                                                             mysql8
[root@izbp1g3qo24yvt8e0635uxz /]# docker exec -it 336197ac bash
root@336197ac3c79:/# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16225
Server version: 8.0.26 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> 
2、查看当前数据库 show databases;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| HELP               |
| README_ADK         |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
5 rows in set (0.02 sec)

mysql>
3、进入mysql这个数据库 use mysql
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> 
4、查看mysql数据库中所有表 show tables;
mysql> show tables;
+------------------------------------------------------+
| Tables_in_mysql                                      |
+------------------------------------------------------+
| columns_priv                                         |
| component                                            |
| db                                                   |
| default_roles                                        |
| engine_cost                                          |
| func                                                 |
| general_log                                          |
| global_grants                                        |
| gtid_executed                                        |
| help_category                                        |
| help_keyword                                         |
| help_relation                                        |
| help_topic                                           |
| innodb_index_stats                                   |
| innodb_table_stats                                   |
| password_history                                     |
| plugin                                               |
| procs_priv                                           |
| proxies_priv                                         |
| replication_asynchronous_connection_failover         |
| replication_asynchronous_connection_failover_managed |
| replication_group_configuration_version              |
| replication_group_member_actions                     |
| role_edges                                           |
| server_cost                                          |
| servers                                              |
| slave_master_info                                    |
| slave_relay_log_info                                 |
| slave_worker_info                                    |
| slow_log                                             |
| tables_priv                                          |
| time_zone                                            |
| time_zone_leap_second                                |
| time_zone_name                                       |
| time_zone_transition                                 |
| time_zone_transition_type                            |
| user                                                 |
+------------------------------------------------------+
37 rows in set (0.00 sec)

mysql>
5、查看user表中的数据 select Host,User from user;
mysql> select Host,User from user;
+-----------+------------------+
| Host      | User             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.00 sec)

mysql>
6、修改user表中的数据 update user set Host=‘%’ where User=‘root’;
mysql> update user set Host='%' where User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select Host,User from user;
+-----------+------------------+
| Host      | User             |
+-----------+------------------+
| %         | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
+-----------+------------------+
4 rows in set (0.00 sec)

mysql> 

注意:也可以直接执行下方进行授权

grant all privileges on *.* to 'root'@'%' with grant option;
7、最后刷新一下 flush privileges;
 flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>
8、重新连接即可成功
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值