[英]SQLSTATE[HY000]: General error: 2006 MySQL server has gone away creating temporary table
Everything I've seen is due to plugins or "weird" configurations or data sets. 我所看到的一切都是由于插件或“怪异”的配置或数据集造成的。
I'm trying to do something very simple with PHP, MySQL, and PDO. 我正在尝试使用PHP,MySQL和PDO做一些非常简单的事情。
$table_name = 'TEMP_' . time();
$sql_commands = "CREATE TEMPORARY TABLE {$table_name} (X CHAR(1));";
$conn = Database::factory();
$stmt = $conn->prepare($sql_commands);
$stmt->execute();
Database::factory() is essential returning a PDO object created from: Database :: factory()对于返回从以下位置创建的PDO对象是必不可少的:
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET time_zone = '" . TIME_ZONE . "';",
PDO::MYSQL_ATTR_INIT_COMMAND => "SET SESSION group_concat_max_len = 10485760;",
];
$dsn = "mysql:dbname=$database;host=$hostname;port=$port;charset=utf8";
Every time I try to create temporary tables I get this error: 每次尝试创建临时表时,都会出现此错误:
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
However the table does get created (At least, if I rerun too quick I get another error stating the table already exists.) 但是,确实会创建该表(至少,如果我重新运行得太快,则会收到另一个错误,指出该表已存在。)
Contents of /etc/my.cnf /etc/my.cnf的内容
max_allowed_packet=128MB # tried various values from 8MB up to 4GB
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
secure_file_priv=""
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
For brevity of this post SHOW VARIABLES DUMP is pastebin'd. 为了简短起见, SHOW VARIABLES DUMP已粘贴。
Should your PREPARE and EXECUTE be followed by CLOSE to complete typical cycle? 您应该在PREPARE和EXECUTE之后紧跟CLOSE以完成典型周期吗?
max_allowed_packet=128MB should be max_allowed_packet=128M in your cnf cnf中的max_allowed_packet = 128MB应该为max_allowed_packet = 128M
please post your error log into the question. 请将您的错误日志发布到问题中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.