Platform.sh User Documentation

Troubleshoot MySQL

Sign up for Upsun

Get your free trial by clicking the link below.

Get your Upsun free trial

For more general information, see how to troubleshoot development.

Lock wait timeout Anchor to this heading

If a process running in your application acquired a lock from MySQL for a long period of time, you receive MySQL error messages like this:

SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded;

This is typically caused by one of the following:

  • There are multiple places acquiring locks in different order. For example, code path 1 first locks record A and then locks record B, while code path 2 first locks record B and then locks record A.
  • There is a long running background process executed by your application that holds the lock until it ends.

If you’re using MariaDB 10+, use the SQL query SHOW FULL PROCESSLIST \G to list DB queries waiting for locks. To determine where to debug, find output like the following:

< skipped >
Command: Query
Time: ...
State: Waiting for table metadata lock
Info: SELECT ...
< skipped >

To find active background processes, run ps aufx on your application container.

Make sure that locks are acquired in a pre-defined order and released as soon as possible.

Definer/invoker of view lack rights to use them Anchor to this heading

There is a single MySQL user, so you can not use “DEFINER” Access Control mechanism for Stored Programs and Views.

When creating a VIEW, you may need to explicitly set the SECURITY parameter to INVOKER:

CREATE OR REPLACE SQL SECURITY INVOKER
VIEW `view_name` AS
SELECT

Server has gone away Anchor to this heading

Disk space issues Anchor to this heading

Errors such as PDO Exception 'MySQL server has gone away' are usually the result of exhausting your available disk space. Get an estimate of current disk usage using the CLI command platform db:size. Just keep in mind it’s an estimate and not exact.

Allocate more space to the service in .platform/services.yaml. As table space can grow rapidly, it’s usually advisable to make your database mount size twice the size reported by the db:size command.

You may want to add a low-disk warning to learn about low disk space before it becomes an issue.

Packet size limitations Anchor to this heading

MySQL server has gone away errors may be caused by the size of the database packets. If so, the logs may show warnings like Error while sending QUERY packet before the error.

One way to resolve the issue is to use the max_allowed_packet parameter.

Worker timeout Anchor to this heading

MySQL server has gone away errors may be caused by server timeouts. MySQL has a built-in timeout for idle connections, which defaults to 10 minutes. Most typical web connections end long before that’s ever approached, but a long-running worker may idle and not need the database for longer than the timeout, leading to a “server has gone away” message.

The best approach is to wrap your connection logic in code that detects a “server has gone away” exception and tries to re-establish the connection.

Alternatively, if your worker is idle for too long it can self-terminate. Platform.sh automatically restarts the worker process and the new process can establish a new database connection.

Is this page helpful?