Trouble with MySQL on Lumen php

Posted February 7, 2018 3.5k views
MySQLPHP FrameworksUbuntu 16.04

Then I try to migrate artisan, I have a message MySQL server has gone away and “in connector.php in line 68” it’s lumen db file.

Line: “return new PDO($dsn, $username, $password, $options);”

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

This line creates the connection between your php script and your MySQL server. The two most common reasons for this error are:

  • The MySQL service is not running or crashed. You can restart it with service mysql restart and check the logs in /var/log/mysql/error.log

  • Your MySQL server configuration that was migrated does not match with what is configured on the server. Make sure to use localhost or for the local MySQL service. If you configure this with your public IP address it will not work since MySQL does not listen publicly by default for security reasons.

  • Your code is opening and reusing a connection without checking it’s status. If you create a connection to a MySQL server and leave it open it may eventually time out. When the PHP script attempts to use it again it will return this error.

Because you are seeing this error on a new PDO() call I would guess that it is one of the first two possibilities and since you are migrating I would check your configuration first to make sure it specifies the correct db information.