PDOException::(“PDO::__construct(): Unexpected server respose while doing caching_sha2 auth: 109”) with MySQL 8 / PHP 7.2 / Laravel

混江龙づ霸主 提交于 2019-12-23 14:41:01

问题


I just installed my dev environnement.

When I try to connect mysql db via SequelPro, I get:

Authentication plugin 'caching_sha2_password' cannot be loaded

As stated in: Authentication plugin 'caching_sha2_password' cannot be loaded, I ran:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';

Then I could connect my DB via SequelPro

But when I execute Laravel Command:

php artisan migrate

I get:

PDOException::("PDO::__construct(): Unexpected server respose while doing caching_sha2 auth: 109")

What should I do now ?

PD: I use Laravel Valet on Mac, and Laravel 5.6.


回答1:


You must alter use in your laravel app via shell with mysql command

ALTER USER 'user'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'your password';
ALTER USER 'user'@'%' IDENTIFIED WITH caching_sha2_password BY 'your password';



回答2:


the problem is good for safety, mybe.

but I use the command solve the problem:

  1. ALTER USER root@localhost IDENTIFIED WITH caching_sha2_password BY 'password';
  2. restart mysql
  3. try now

Hope you will not see this error again.




回答3:


After using $ mysql -uUser -pPa$$w0rd the MySQL connection could be opened with PHP using mysqli_real_connect() or PDO

Make sure that the User has caching sha2 password active, not a native password. (PHP 7.2.9-1, MySQL 8.0.12)

When changing to a native password PHP says

mysqli::real_connect(): Unexpected server respose while doing caching_sha2 auth: 109

With caching sha2 password active i always get:

mysqli::real_connect(): (HY000/1045): Access denied for user 'User'@'localhost' (using password: YES)

So tried to login from Shell using $ mysql, which succeeded, after this, i was able to connect with PHP. Seems like a Bug in the PHP mysqlnd.

Implementing a shell_exec('mysql -u'.$user.' -p"'.$password.'" -e quit > /dev/null 2>&1'); right before opening the MySQL connection, solves the issue, by now, for me.

Rebooting or restarting the MySQL Service, resets the cached password and the access denied message will pop again.

Hope this helps.

Greetings




回答4:


there is a way to solve this,

  1. remove MySQL
  2. Install it and choose use legacy authentication method ( Retain MySQL 5.x compatibility )



来源:https://stackoverflow.com/questions/51844962/pdoexceptionpdo-construct-unexpected-server-respose-while-doing-cachin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!