简体   繁体   中英

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.

    $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:

$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

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.

Should your PREPARE and EXECUTE be followed by CLOSE to complete typical cycle?

max_allowed_packet=128MB should be max_allowed_packet=128M in your cnf

please post your error log into the question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM