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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!