【问题标题】:Mysql error PDOStatement::execute(): MySQL server has gone away using Laravel and curl requestMysql 错误 PDOStatement::execute(): MySQL server has gone away using Laravel and curl request
【发布时间】:2020-05-19 20:23:36
【问题描述】:

我正在使用第 3 方 API 在数据库中插入数据。我已经在我的本地计算机中遇到了这个问题,我将max_allowed_packet 设置为其他帖子所说的,它对我有用。但现在我正在使用我们的 linux 远程服务器来插入数据。我找不到my.ini 或一些配置文件,但有类似的文件,这里命名为50-server.cnf 是其中的一些内容

#
# * Fine Tuning
#
key_buffer_size     = 16M
max_allowed_packet  = 1024M
thread_stack        = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam_recover_options  = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10

#
# * Query Cache Configuration
#
query_cache_limit   = 32M
query_cache_size        = 1024M


我还在我们的 linux 远程终端中编写了一堆查询来设置全局变量。以下是部分内容

sudo mysql

SET SESSION wait_timeout = 999999;

SET SESSION net_read_timeout = 1000

SET GLOBAL connect_timeout = 1000;

之后我跑 sudo /etc/init.d/mysql restart 然后我执行我的控制器功能,但我仍然得到 PDOStatement::execute(): MySQL server has gone away

我正在使用

Mysql: mysql Ver 15.1 Distrib 10.1.43-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Linux: Linux ip-172-31-16-16 4.15.0-1054-aws #56-Ubuntu SMP Thu Nov 7 16:15:59 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

PHP: Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.11-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

玛丽亚数据库: mariadb Ver 15.1 Distrib 10.1.43-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

谁能告诉我这是什么问题?

【问题讨论】:

  • query_cache_size = 1024M 太高了; QC 不能很好地扩展。将其降低到 50M。
  • 请提供所涉及的具体陈述。

标签: php mysql linux laravel mariadb


【解决方案1】:

评论太长了。

  1. 您的设置无用 - 重启后将使用 my.cnf 配置文件中的默认值。 SET SESSION 还会更改当前连接的值。

  2. 检查以下事项:

    • 这是服务器错误(例如服务器崩溃)吗? .错误发生后, 通过mysql命令行客户端登录并检查正常运行时间 使用\sstatus 命令的服务器。

    • 打开MariaDB服务器的错误日志文件到最后看看有没有有用的信息。

    • 尝试在 mysql 命令行客户端中执行该语句(传递给 PDO::execute)。
    • 如果是 SELECT 语句,请确保结果集的大小不超过 max_allowed_packet 大小。
    • 使用 tcpdump 捕获流量,使用 wireshark 打开文件,将过滤器设置为 mysql 并检查是否可以找到更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-04
    • 2019-10-13
    • 2013-12-16
    • 2011-12-11
    • 2020-06-15
    • 1970-01-01
    • 2011-02-04
    • 2016-02-15
    相关资源
    最近更新 更多