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?
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 :).
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.
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.
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
If someone is looking for a solution, try to clean all cache you have, you can manually delete cache files in bootstrap/cache folder. Don't touch packages.php and services.php.
In addition to other answers:
- Try changing
localhost
domain to127.0.0.1
both in.env
andconfig/database.php
. - Also If you're using
git
then checkgit status
and see if any unwanted files have been changed.
Because In my case options
array for mysql connection configuration in file config/database.php
was blank array somehow. I checked out git checkout config/database.php
file and it starting to work fine.
I faced this problem in my laravel application, and even when i was trying to connect with vanilla PHP, I got this error messages
using mysqli
PHP Warning: mysqli::__construct(): Unexpected server respose while doing caching_sha2 auth: 109
using PDO
PHP Warning: Uncaught PDOException: PDO::__construct(): Unexpected server respose while doing caching_sha2 auth: 21 in php shell code:1
I believe that PHP still dose not support this way of authentication
Laravel version 5.6 My PHP version 7.2.10 MySQL version 8.0.13
to solve this I removed MySQL and then install it
and choose this option
use legacy authentication method ( Retain MySQL 5.x compatibility )
来源:https://stackoverflow.com/questions/35036547/mysql-server-has-gone-away-error-during-installing-migration-laravel