SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

wjm989

已经在 config/bootstrap.php 中加了 support\bootstrap\db\Heartbeat::class

<?php
/**
 * This file is part of webman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author    walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @link      http://www.workerman.net/
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
 */

return [
    support\bootstrap\Container::class,
    support\bootstrap\Session::class,
    support\bootstrap\db\Laravel::class,
    support\bootstrap\Redis::class,
    support\bootstrap\Log::class,
    support\bootstrap\Translation::class,
    support\bootstrap\db\Heartbeat::class
];
3082 5 0
5个回答

wjm989

晕, 是不是最后一行少个逗号?最后一行一定要有逗号吗?看着是返回数组,没逗号也行吗?

  • 暂无评论
wjm989

default.ERROR: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away {"exception":"PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away in

  • 暂无评论
wjm989

bootstrap.php 和 start.php 中都加了 DB::query('select 1'); 还是报这个错,这怎么办?

  • 暂无评论
six

看源码心跳默认是主连接定时发了心跳。如果你用了多个数据库连接,需要改下support\bootstrap\db\Heartbeat类,让每个连接都发送心跳。

  • 暂无评论
wjm989

默认心跳类时间间隔太长了,要改成 10 秒才行

年代过于久远,无法发表回答
🔝