docker -mysql服务设置远程连接 解决1251 client does not support ..问题

  前提:

  安装MYSQL实例

docker pull mysql

  

  启动mysql(做了端口映射)

[root@localhost ~]# docker run -p 3306:3306 --name mysql02 -e MYSQL_ROOT_PASSWORD=123456 -d mysql
5cf11b6647da2f4d301020934cb8ef750d7215d3c25fb81a56d30fbfd1a24530

  

  言归正传:解决方案如下:

   在docker创建mysql容器后使用Navicat远程连接事报错:

  操作起来:

 

  先查看user表中的信息:

 

select host,user,plugin,authentication_string from mysql.user;  

 

  

 

  host 列中的 % 表示不限制IP ; localhost表示的是本机使用   plugin非mysql_native_password 则需要修改密码

alter user 'root'@'% 'IDENTIFIED WITH mysql_native_password BY '123';  
// (注意SQL语句最后加上 ;)

//其中 root用户 密码为123  (按照你的用户 密码对应设置既可)

//最后刷新生效 

 flush privileges;

  

[root@localhost ~]# docker run -it --link mysql02:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$M
YSQL_ENV_NYSQL_ROOT_PASSWORD"'
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.11 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$*@A<}'C_C7%M4i3c3Qmow5Vpi7OWL0v..KqLCIzI5ai7tvBGkXxE7K6 |
| localhost | mysql.infoschema | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |
| localhost | mysql.session    | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |
| localhost | mysql.sys        | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |
| localhost | root             | caching_sha2_password | $A$005$vU(<0Km/fNjY\IW8Ma8ktz5xLyByDbtiEVsGqaIa5B/JzXfuXe9ez0d15VC |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
5 rows in set (0.03 sec)
mysql> Alter user 'root'@'% 'IDENTIFIED WITH mysql_native_password BY '123';
Query OK, 0 rows affected (0.06 sec)

mysql> flush privileges;

  

posted @ 2018-06-12 21:00  赵小叔  阅读(807)  评论(0编辑  收藏  举报