Docker环境-连接MySQL数据库

1.问题描述

在虚拟机中,安装好LNMP环境之后,然后使用本地的navicat软件连接虚拟机的mysql时,出现【1251 - Client does not support authentication protocol requested by server; consider upgrading MySQL client】错误。

2.问题图解


3 问题解决

1) 首先,登录mysql容器,然后查看mysql信息,具体操作如下:

# 登录mysql容器
docker exec -it c_mysql /bin/bash

# 进入Mysql,密码是123456
mysql -u root -p

# 查看mysql信息
select host,user,plugin,authentication_string from mysql.user;


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

2) 接着,修改mysql密码,其具体操作如下:

mysql> use mysql;
mysql> alter user 'root'@'%' identified with mysql_native_password by '123456789';
mysql> flush privileges;
mysql> select host,user,plugin,authentication_string from mysql.user;


注意:从图中可以知道,有两个root用户,分别为第1个和第4个,这两个用户的区别主要看host处:%表示允许所有IP连接该mysql服务器,该root用户用于客户端连接虚拟机的mysql;而localhost表示在本地虚拟机中,若要连接docker的mysql,要使用该root账号。

3)接着,退出mysql容器,然后重启mysql容器:

docker restart c_mysql

4)到此,mysql设置完成!

4.问题验证



相关推荐

  • 生成图片

    from PIL import Image, ImageColor, ImageDraw, ImageFont, ImageFilterdef create_image_with_text(size, color, text, font_path, font_size, text_color, shadow_color, output_path): """ Create a new image of specified size and color with centered text that has a border and shadow. :param size: A tuple con

  • 获取指定目录下的所有图片信息

    1 获取指定目录下的所有图片信息// 获取指定目录下的所有图片信息 public function getImagesInfo($directory) { $images = []; // 创建递归目录迭代器 $iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY ); // 遍历目录中的每个文件 foreach (

  • Thinkphp各版本的PHP要求

    ThinkPHP 8.0:运行环境要求PHP8.0+,兼容PHP8.3ThinkPHP 6.1:运行环境要求PHP7.2+,兼容PHP8.1ThinkPHP 6.0:运行环境要求PHP7.2+,兼容PHP8.1ThinkPHP 5.1:运行环境要求PHP5.6+,兼容PHP8.0ThinkPHP 5.0:运行环境要求PHP5.4+,兼容PHP7.3