mysql server has gone away error during installing migration (laravel)
Solution 1
This is not a Laravel issue, but a general MySQL Issue. Maybe the server is not running. Are you sure you're running MySQL in the background?
Check this link: MySQL Gone Away
Do the following checks in your system:
- The Database Engine is running
- You have created your database
- You have created an user and granted permissions to the database
- You have setup the user and the database in your Laravel's .env file.
After this, try to run the migrations command again, which is:
php artisan migrate
As explained Here
Let us know if that helps :).
Solution 2
You have Lost SQL connection to server during query. It is temporally issue. This is because of very low default setting of max_allowed_packet
.
Raising max_allowed_packet
in my.cnf
(under [mysqld]) to 8 or 16M usually fixes it.
[mysqld]
max_allowed_packet=16M
NOTE: This can be set on your server as it's running. You need to restart
the MySQL service once you are done.
Use: set global max_allowed_packet=104857600
. My value sets it to 100MB.
Solution 3
I encountered the same problem. The solution was to delete the mysql port number from 3306 or 80, and leave it empty In files
.env DB_PORT=3306
to DB_PORT=
and on
database.php 'port' => env('DB_PORT', '3306'),
to 'port' => env('DB_PORT', ''),
Solution 4
For me the problem seemed to be that I assigned the wrong port to my Laravel project's .env
file. Later, when I matched it with the my.cnf
file, it worked.
I'm using Ubuntu 16.04 + nginx + MariaDB + Laravel project.
Solution 5
In my case the problem was I changed DB_HOST
to localhost
but it was fixed by keeping it default
ie 127.0.0.1
and the port to default 3306
.
Here is the configuration for localhost in xampp:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=hmb
DB_USERNAME=root
DB_PASSWORD=
Although I use localhost:8081/phpmyadmin
to access my db
Mackinley
Updated on December 21, 2020Comments
-
Mackinley over 3 years
So I am using my cmd on my laravel folder and I tried to do (php artisan migrate:install). 2 errors came up.
[PDOException] SQLSTATE[HY000] [2006] MySQL server has gone away
[ErrorException] PDO::__construct(): MySQL server has gone away
Can anyone please explain what I did wrong?
-
Takao Baltazar over 3 yearsSame Issue. I assigned a wrong port for my DB connections in ENV.