mysql server has gone away error during installing migration (laravel)

断了今生、忘了曾经 提交于 2019-11-29 14:22:25

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:

  1. The Database Engine is running
  2. You have created your database
  3. You have created an user and granted permissions to the database
  4. 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.

Mill3r

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 to 127.0.0.1 both in .env and config/database.php.
  • Also If you're using 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.

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 )

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!