gpt4 book ai didi

php - Homebrew 升级后 MySQL 服务器消失了

转载 作者:行者123 更新时间:2023-11-29 01:35:14 24 4
gpt4 key购买 nike

我刚刚对 PHP 7.2.8 和 MySQL 8.0.12 进行了 brew 升级。在此之后,尝试从 PHP 脚本(从 Bash)连接到 MySQL 会在 10 秒(默认的 MySQL 超时值)后超时。

new PDO("mysql:host=localhost;dbname=foo;charset=utf8", "user", "pass");

[2006] MySQL server has gone away

我环境中的一切似乎都很正常。我没有改变我的设置中的任何其他内容。从 Bash 连接到 MySQL 工作正常。我如何从 PHP 重新获得 MySQL 访问权限?

$ php -i | grep php.ini
Configuration File (php.ini) Path => /usr/local/etc/php/7.2
Loaded Configuration File => /usr/local/etc/php/7.2/php.ini

$ tail /usr/local/etc/php/7.2/php.ini
mysql.default_socket = /tmp/mysql.sock
pdo_mysql.default_socket = /tmp/mysql.sock

$ ls /tmp/mysql*
srwxrwxrwx 0 /tmp/mysql.sock
-rw------- 5 /tmp/mysql.sock.lock
srwxrwxrwx 0 /tmp/mysqlx.sock
-rw------- 6 /tmp/mysqlx.sock.lock

$ mysql
Welcome to the MySQL monitor.
mysql> show variables like '%socket%';
+-----------------------------------------+------------------+
| mysqlx_socket | /tmp/mysqlx.sock |
| socket | /tmp/mysql.sock |
+-----------------------------------------+------------------+

最佳答案

解决方案:将此添加到您的 MySQL 配置文件 (my.cnf):

[mysqld]
default_authentication_plugin=mysql_native_password

PHP manual :

MySQL 8 defaults to caching_sha2_password, a plugin that is not recognized by the older PHP releases. Instead, change it by setting default_authentication_plugin=mysql_native_password in my.cnf. The caching_sha2_password plugin will be supported in a future PHP release.

我希望这会为其他人省去一些麻烦和时间。

关于php - Homebrew 升级后 MySQL 服务器消失了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51683676/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com