Database troubleshooting

Published

Updated

🔧

Fix database problems.

Fixes for common MySQL errors on fortrabbit: no connection without an SSH tunnel, missing INSERT privileges on a full database, max_user_connections, and SUPER privilege errors on import.

Can't connect from local

The database is reachable through an SSH tunnel only. Enter both the SSH and the MySQL details in the client. The MySQL settings of the environment in the dashboard show all of them.

See the MySQL access guides.

Missing INSERT privileges

When INSERT fails, the grants of the user look like this:

GRANT SELECT, UPDATE, DELETE, DROP, ALTER ON `{{app-env-id}}`.* TO `{{app-env-id}}`@`%`
sql

The database of the environment is full. It reached the storage of its MySQL plan, and autoscaling is off. Logs, sessions and caches in tables often grow without anyone noticing. Options:

  • Scale the MySQL plan, or turn on autoscaling
  • Query large tables, see below
  • Reduce the database size by removing table rows
-- Delete table rows with conditions
DELETE FROM table_name WHERE condition;

-- Remove all rows from a table
TRUNCATE TABLE table_name;

-- Drop a table entirely
DROP TABLE table_name;
mysql

See our MySQL scaling section for some more details.

Query large tables

This query lists the tables by size, largest first:

SELECT
  TABLE_NAME AS `Table`,
  ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)`
FROM
  information_schema.TABLES
WHERE
  TABLE_SCHEMA = '{{app-env-id}}'
ORDER BY
  (DATA_LENGTH + INDEX_LENGTH)
DESC;
mysql

max_user_connections error

The app or a client opened more connections at once than allowed:

SQLSTATE[HY000] [1226] User 'xxxxxx' has exceeded the 'max_user_connections' resource (current value: 10)
sql

The PHP plan sets the limit: one connection per PHP process, plus some for jobs and clients. Typical causes:

  • Many PHP requests at the same time
  • Each request opens more than one connection
  • A cron or worker keeps connections open
  • Slow queries hold their connection
  • A database GUI opens many connections, see below

Find what keeps connections open and remove the cause, or scale the PHP plan.

GUI clients eating MySQL connections

Some GUIs, such as Navicat, Workbench or Sequel Ace, open a connection per tab or query window. Each one counts against the limit of the app. Close tabs, or limit the connections in the client settings. Each connection also opens an SSH tunnel, which counts against the SSH rate limits.

Access denied; missing SUPER privileges

Importing a dump from a recent mysqldump can fail with:

#1227 - Access denied; you need (at least one of) the SUPER privilege(s) for this operation
raw

The dump contains GTID statements, or functions, procedures and triggers with a DEFINER, which need the SUPER privilege. Create the dump again with --set-gtid-purged=OFF, and with --no-tablespaces when it complains about tablespaces. GUIs that run mysqldump have a checkbox for GTID. This applies to MariaDB dumps too.

Large imports

A large import can break off when the tunnel drops. Split the dump into smaller files, or upload it by SFTP and import it in an SSH session with mysql. For the export, --single-transaction gives a consistent snapshot without locking the tables.

Encoding issues

  • Add --default-character-set=utf8mb4 to both export and import commands
  • Ensure your dump file is saved with UTF-8 encoding

Frequently asked

Why can't I insert rows into my fortrabbit database?

The database is full. When it reaches the storage of its MySQL plan without autoscaling, the user loses the INSERT privilege. Scale the plan, turn on autoscaling, or delete data.

#
What does the max_user_connections error mean on fortrabbit?

The app or a client opened more MySQL connections at once than allowed. The PHP plan sets the limit. Look for workers, long queries or GUI clients that keep connections open, or scale the PHP plan.

#

Written by humans and AI in collaboration.

AI use & editorial processEdit on GitHub ↗