Trouble with MySQL on Lumen php

February 7, 2018 426 views
PHP Frameworks MySQL Ubuntu 16.04
ZaneJev
By:
ZaneJev

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);"

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 127.0.0.1 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.

Have another answer? Share your knowledge.