运行报如下错误是因为docker默认安装mysql是8.0以上最新版本,需要修改mysql密码验证规则

SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

解决方法:

#进入mysql容器
docker exec -it mysql /bin/bash
#登陆数据库
mysql -u root -p
use mysql;
#开启root远程访问权限
grant all on *.* to 'root'@'%';
#修改加密规则
alter user 'root'@'localhost' identified by '123456' password expire never;
#更新密码
alter user 'root'@'%' identified with mysql_native_password by '123456';
#刷新权限
flush privileges;