简体   繁体   中英

Connecting Laravel to XAMPP MySQL (MariaDB) database SQLSTATE[HY000] [2006] MySQL server has gone away

I'm trying to set up Laravel 6 to connect to my XAMPP MySQL (MariaDB) database and I am receiving the following error:

SQLSTATE[HY000] [2006] MySQL server has gone away (SQL: create table `migrations` (`id` int unsigned not null auto_increment primary key, `migration` varchar(255) not null, `batch` int not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

Exception trace:

  1   PDOException::("Packets out of order. Expected 0 received 1. Packet size=71")
      /Users/myname/.bitnami/stackman/machines/xampp/volumes/root/htdocs/testSite/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  2   PDO::__construct("mysql:host=192.168.64.2;port=3306;dbname=testSite", "root", "", [])
      /Users/myname/.bitnami/stackman/machines/xampp/volumes/root/htdocs/testSite/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

My .env file has the following setup:

DB_CONNECTION=mysql
DB_HOST=192.168.64.2
DB_PORT=3306
DB_DATABASE=testSite
DB_USERNAME=root
DB_PASSWORD=

DB_HOST= 127.0.0.1

You can do it like this should work fine. just replace your IP with localhost or 127.0.0.1 .

The issue was a difference between versions of MySQL.

I reinstalled XAMPP and was able to resolve the issue.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM