mysql 服务器在安装迁移过程中消失了错误 (laravel)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35036547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mysql server has gone away error during installing migration (laravel)
提问by Mackinley
So I am using my cmd on my laravel folder and I tried to do (php artisan migrate:install). 2 errors came up.
所以我在我的 Laravel 文件夹上使用我的 cmd 并且我尝试这样做(php artisan migrate:install)。出现了2个错误。
[PDOException] SQLSTATE[HY000] [2006] MySQL server has gone away
[ErrorException] PDO::__construct(): MySQL server has gone away
[PDOException] SQLSTATE[HY000] [2006] MySQL 服务器已经消失
[ErrorException] PDO::__construct(): MySQL 服务器已经消失
Can anyone please explain what I did wrong?
谁能解释一下我做错了什么?
采纳答案by Andrés Smerkin
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?
这不是 Laravel 问题,而是一般的 MySQL 问题。可能服务器没有运行。你确定你在后台运行 MySQL 吗?
Check this link: MySQL Gone Away
检查此链接: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.
- 数据库引擎正在运行
- 你已经创建了你的数据库
- 您已创建用户并授予数据库权限
- 您已经在 Laravel 的 .env 文件中设置了用户和数据库。
After this, try to run the migrations command again, which is:
在此之后,尝试再次运行迁移命令,即:
php artisan migrate
As explained Here
正如这里所解释的
Let us know if that helps :).
如果这有帮助,请告诉我们:)。
回答by Hassaan
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
.
您在查询期间失去了与服务器的 SQL 连接。这是暂时的问题。这是因为max_allowed_packet
.
Raising max_allowed_packet
in my.cnf
(under [mysqld]) to 8 or 16M usually fixes it.
提高max_allowed_packet
在my.cnf
(下的[mysqld])至8或16M通常修复它。
[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.
注意:这可以在您的服务器运行时设置。完成后,您需要restart
使用 MySQL 服务。
Use: set global max_allowed_packet=104857600
. My value sets it to 100MB.
使用:set global max_allowed_packet=104857600
。我的值将其设置为 100MB。
回答by 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.
对我来说,问题似乎是我为 Laravel 项目的.env
文件分配了错误的端口。后来,当我将它与my.cnf
文件匹配时,它起作用了。
I'm using Ubuntu 16.04 + nginx + MariaDB + Laravel project.
我正在使用 Ubuntu 16.04 + nginx + MariaDB + Laravel 项目。
回答by Black Mamba
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_HOST
为,localhost
但通过将其default
ie127.0.0.1
和端口保持为 default 来解决3306
。下面是 xampp 中 localhost 的配置:
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
虽然我localhost:8081/phpmyadmin
用来访问我的db
回答by Serhii Cho
If someone is looking for a solution, try to clean all cache you have, you can manually delete cache files in bootstrap/cachefolder.
如果有人正在寻找解决方案,请尝试清理您拥有的所有缓存,您可以手动删除bootstrap/cache文件夹中的缓存文件。
回答by Saleh Mahmood
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.
- 尝试将
localhost
域更改为127.0.0.1
in.env
和config/database.php
。 - 此外,如果您正在使用,请
git
检查git status
并查看是否有任何不需要的文件已更改。
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.
因为在我的情况下options
,文件中用于 mysql 连接配置的config/database.php
数组以某种方式是空白数组。我检出git checkout config/database.php
文件,它开始正常工作。
回答by rowad
I faced this problem in my laravel application, and even when i was trying to connect with vanilla PHP, I got this error messages
我在 Laravel 应用程序中遇到了这个问题,即使当我尝试连接普通 PHP 时,我也收到此错误消息
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
使用 mysqli
PHP 警告:mysqli::__construct():在执行 caching_sha2 auth 时出现意外的服务器响应:109
使用 PDO
PHP 警告:未捕获的 PDOException:PDO::__construct():在执行 caching_sha2 auth 时意外的服务器响应:php shell 代码中的 21:1
I believe that PHP still dose not support this way of authentication
我相信PHP仍然不支持这种身份验证方式
Laravel version 5.6 My PHP version 7.2.10 MySQL version 8.0.13
Laravel 版本 5.6 我的 PHP 版本 7.2.10 MySQL 版本 8.0.13
to solve this I removed MySQL and then install it
and choose this option
为了解决这个问题,我删除了 MySQL,然后安装它并选择了这个选项
use legacy authentication method ( Retain MySQL 5.x compatibility )
使用旧的身份验证方法(保留 MySQL 5.x 兼容性)