laravel5.8 中迁移文件在mysql8.0中遇到坑

最近要重构项目,开发环境用laravel5.8+php7.1+mysql8.0+nginx 。目前数据库设计好了,并且做好了迁移文件,打算在本地环境中尝试迁移文件。但不小心进入了一个坑。

运行迁移命令:

php artisan migrate

 出现异常如下:

Illuminate\Database\QueryException  : SQLSTATE[HY000] [2054] The server 
requested authentication method unknown to the client (SQL: select * from 
information_schema.tables where table_schema = data and table_name =data_migrations and table_type = 'BASE TABLE')

 后来在网上搜索到 这个错误与mysql8.0是有关系。

 原因:MySQL8.0的首选默认认证插件是caching_sha2_password, 而不是mysql_native_password

    解决方式有二种:

 1. 想使用之前的密码认证方式请使用  

  在mysql的配置文件my.cnf(或my.ini)中添加 default-authentication-plugin=mysql_native_password 

  重启mysql 

  ALTER USER 'user'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

       mysql官方文档

    2.将认证用caching_sha2_password插件 ,目前不建议使用。因为php的pdo 和myqli扩展不支持caching_sha2_password 身份验证

  以后升级后可以考虑这种方式

 

posted @ 2021-03-31 02:23  coder菜鸟玩家  阅读(37)  评论(0)    收藏  举报