Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

KLM113's avatar

SQLSTATE[HY000] [2006] MySQL server has gone away

I know this is usually caused by very large queries however in my dev server the errors pops immediately after the request is executed.

This is the query causing the problem (the error appears on other queries that work fine if I don't run this one)

$pdo = DB::connection()->getPdo();
$pdo->exec("
	LOAD DATA LOCAL INFILE '".storage_path('data.txt')."' INTO TABLE raw FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n' 
	(my_fields_here)
");

Data file is under 100k

And just in case the my.cfn

[mysqld]
default_storage_engine=innodb
# character-set-server=utf8
innodb_file_per_table=ON
#innodb_file_format=Barracuda
innodb_flush_log_at_trx_commit=1
max_sp_recursion_depth=255
max_allowed_packet=1000M
query_cache_size=0
query_cache_type=OFF
sql-mode=""
wait_timeout = 28800
innodb_log_file_size = 128MB

Server version: 10.3.22-MariaDB-1 Debian buildd-unstable

Thanks in advance for any help.

0 likes
7 replies
KLM113's avatar

Thanks, I tried that but made no difference. I have executed 20x bigger queries on this server, I doubt is that kind of issue.

jlrdw's avatar

Is that data.txt well formed data. I'm just wondering if there are errors in that file.

Edit: log the query.

jlrdw's avatar

You might want to write a stored procedure to handle it.

KLM113's avatar

Digging on the debugging info I found the exception is thrown before the query , just here

$pdo = DB::connection()->getPdo();

Maybe there is a way to do this on eloquent?

KLM113's avatar

Now that I check even the simplest query causes this issue

SHOW VARIABLES

Returns the same problem

Either with

$pdo->exec()

or

DB::statement()
KLM113's avatar

It seems it's being caused by the mysql option I had to add to allow LOCAL IN FILE.

[PDO::MYSQL_ATTR_LOCAL_INFILE => true]

Not sure what's wrong with it tho.

Please or to participate in this conversation.