一、问题原因
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>