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:
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.
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', ''),
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
如果有人正在寻找解决方案,请尝试清理您拥有的所有缓存,您可以手动删除bootstrap/cache文件夹中的缓存文件。
In addition to other answers:
localhost
domain to 127.0.0.1
both in .env
and config/database.php
.git
then check git 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.
My solution is due to fix the DB_HOST parameter. Indeed I use PHPStorm and I set the public url in .env in order to use DB tools from the IDE and this broken Laravel. So I changed DB_HOST to localhost and Laravel now works 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 )
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.