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

screwtape_mk's avatar

SQLSTATE[HY000] [2006] MySQL server has gone away laravel mysql and xampp

i am using laravel 7 with a xampp installation. php artisan migrate fails and gives the error: SQLSTATE[HY000] [2006] MySQL server has gone away

my .env file:

APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=****_db
DB_USERNAME=root
DB_PASSWORD=*******

i have tried localhost in the env file isntead of 127.0.0.1. Worth mentioning that my xampp application launches at this address: http://192.168.64.2/

i have started and restated the xampp server and i have been php artisan cache:clear each time i make changes to the .env file

0 likes
17 replies
screwtape_mk's avatar

i used php artisan config:clear and now the error became SQLSTATE[HY000] [2002] No such file or directory

screwtape_mk's avatar

actually the error right now has changed to : SQLSTATE[HY000] [2002] Connection refused.

screwtape_mk's avatar

So i made some of the changes suggested here and the error now is: SQLSTATE[HY000] [2002] Connection refused.

tomasosho's avatar

run php artisan serve instead of opening it directly

screwtape_mk's avatar

i have now gone back to using localhost instead of 127.0.0.1 and my error has now become:

SQLSTATE[HY000] [2002] No such file or directory

im slowly discovering that im suppose to have a mysql socket file in /opt/lampp/var/mysql and i dont have it. any ideas on how to create it? i suspect in config/database.php i must also change this here 'unix_socket' => env('DB_SOCKET', ''),

kalemdzievski's avatar

@screwtape_mk still not sure what the problem is, but when u had the error SQLSTATE[HY000] [2002] Connection refused. it looked to me like the port for mysql is incorrect.

Maybe try to confirm that mysql is listening on port 3306?

screwtape_mk's avatar

i ended up changing 127.0.0.1 to localhost and the error became No such file or directory . it turns out the mysql socket file is missing and i have not found a satisfctory solution to recreating it except that there must be something wrong with my xampp installation

screwtape_mk's avatar

I ended up ditching connecting to my local xampp installation and connected to an AWS RDS instance and it worked.

ush's avatar

@screwtape_mk , can you give me a guide on how to connect to AWS RDS, i ham hit with the same challenge on macoc bigsur, i am new to laravel as well. Thanks in advance

screwtape_mk's avatar

Wow This has been such a very long time ago that i cannot recall the specific steps except to say just go ahead and spin off a web server on AWS and run the commands for laravel installation.

Best starting point would be for you to ask chat gpt what the steps are and begin troubleshooting errors from there. ChatGPT has been super useful in terms of instructions and basic steps - you can keep us posted on the specific errors encountered

ush's avatar

I still get this error when running on AWS RD, it's the same as and when i was using the Xampp on mac, any help will be most welcome

Illuminate\Database\QueryException

SQLSTATE[HY000] [2002] Operation timed out (SQL: select * from information_schema.tables where table_schema = firstapp and table_name = migrations and table_type = 'BASE TABLE') ... catch (Exception $e) { throw new QueryException( $query, $this->prepareBindings($bindings), $e ); } }

Please or to participate in this conversation.