duanpasi6287 2018-08-04 08:00 采纳率: 100%
浏览 140
已采纳

Homebrew升级后,MySQL服务器已经消失

I just did a brew upgrade to PHP 7.2.8 and MySQL 8.0.12. After this, trying to connect to MySQL from a PHP script (from Bash) times out after 10 seconds (the default MySQL timeout value).

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

[2006] MySQL server has gone away

Everything in my environment seems to be normal. I haven't changed anything else in my setup. Connecting to MySQL from Bash works fine. How do I regain MySQL access from PHP?

$ 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  |
+-----------------------------------------+------------------+
  • 写回答

2条回答 默认 最新

  • douyun3631 2018-08-04 09:29
    关注

    The solution: Add this to your MySQL configuration file (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.

    I hope this will save others some headache and time.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器