使用Navicat连接CentOs7Docker的MYSQL出现1251的解决方案

[root@localhost 桌面]# docker ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS                               NAMES

a02900e19c97        mysql               "docker-entrypoint..."   21 seconds ago      Up 20 seconds                 3306/tcp, 0.0.0.0:3308->33060/tcp   mysql03

839fef5d95d4        mysql               "docker-entrypoint..."   15 minutes ago      Up 15 minutes                 3306/tcp, 0.0.0.0:3307->33060/tcp   mysql02

c6e764da6485        mysql               "docker-entrypoint..."   29 minutes ago      Exited (0) 27 minutes ago                                         mysql01

49074f451a0e        tomcat              "catalina.sh run"        About an hour ago   Exited (143) 16 minutes ago 

docker run -p 3306:3306 --name mysql02 -e MYSQL_ROOT_PASSWORD=123456 -d mysql

上述端口已经开放了但是依然报错还是连接不上。

解决方案:

查看进程
[root@localhost 桌面]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                               NAMES
7c0ae18150da        mysql               "docker-entrypoint..."   9 hours ago         Up 2 seconds                0.0.0.0:3306->3306/tcp, 33060/tcp   mysql01
49074f451a0e        tomcat              "catalina.sh run"        12 hours ago        Exited (143) 11 hours ago                                       frosty_einstein
进入MySQL容器
[root@localhost 桌面]# docker exec -it 7c0ae18150da  bash
root@7c0ae18150da:/# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.13 MySQL Community Server - GPL

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> select host,user,plugin,authentication_string from mysql.user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| host      | user             | plugin                | authentication_string                                                  |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| %         | root             | caching_sha2_password | $A$005$uj
                                                                  iZu    Xi*`s    :|ZADxWTQ1KIv.m/frdQEMmhIHoByUcXzn571taJhaaoP3 |
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session    | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys        | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root             | caching_sha2_password | $A$005$<GM_2Qt]cy{4xi(./16Jeq5NEc7SYsP0UIEaw.4kBJBNGa8NEpmaD3IbF5hzB |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
5 rows in set (0.01 sec)

备注:host为 % 表示不限制ip   localhost表示本机使用    plugin非mysql_native_password 则需要修改密码

navicat链接错误;我们继续往下看;

mysql>  ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; 这里我们修改下密码
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;   //刷新
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user,plugin,authentication_string from mysql.user; //刷新权限
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| host      | user             | plugin                | authentication_string                                                  |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| %         | root             | mysql_native_password | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9                              |
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session    | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys        | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root             | caching_sha2_password | $A$005$<GM_2Qt]cy{4xi(./16Jeq5NEc7SYsP0UIEaw.4kBJBNGa8NEpmaD3IbF5hzB |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
5 rows in set (0.00 sec)

之后就解决了这类问题

猜你喜欢

转载自blog.csdn.net/qq_39507327/article/details/84870013