# Common MySQL errors and how to fix them

> Fix "MySQL server has gone away", "max_user_connections", "max_connections_per_hour", error 1064 and other common database errors.

Source: https://helpcenter.ruachost.com/cpanel/databases/common-mysql-errors/

## "User already has more than 'max_user_connections' active connections"

Each database user can have **20** connections open at the same time on shared hosting. This error means your site tried to open more, usually because:

- traffic spiked, or bots are crawling the site heavily
- slow queries keep connections open longer than they should
- a plugin or script opens connections and doesn't close them (for example, persistent connections)

**To fix it:**

1. **Turn on caching.** With WordPress, use LiteSpeed Cache: cached pages don't touch the database at all.
2. **Block bad bots** and limit login attempts. See [WordPress security](https://helpcenter.ruachost.com/ssl-security/website-security/wordpress-security/).
3. **Find slow queries.** In WordPress, [Query Monitor](https://helpcenter.ruachost.com/wordpress/guides/monitoring-the-mysql-database-for-wordpress-using-query-monitor/) shows which plugins run slow or many queries.
4. **Avoid persistent connections.** In PHP, don't use `mysqli_pconnect` or `PDO::ATTR_PERSISTENT`.
5. **Use separate database users** for separate sites, so one busy site doesn't use up another's connections.

The connections close on their own, so the error usually clears within a few minutes. If it keeps happening, your site may have outgrown shared hosting. A [Managed VPS](https://ruachost.com/vps) lets you set your own limits.

## "has exceeded the 'max_connections_per_hour' resource" (or max_questions / max_updates)

These limits cap how many connections or queries a user can make in an hour. They aren't normally set on Ruachost shared hosting. If you see this error, it's usually because an app has a very high, unusual level of database activity, often caused by a bot attack, a loop in a script, or a misbehaving plugin.

Fix the cause as above, then [open a support ticket](https://dashboard.ruachost.com/submitticket.php) if the error doesn't clear within the hour.

## "MySQL server has gone away" (error 2006)

The connection to the database closed before the query finished. Common causes:

- **A very large import or query.** A single query or row is bigger than the 256 MB packet limit. Split large imports into smaller files. See [Importing a large database](https://helpcenter.ruachost.com/cpanel/databases/importing-a-large-database/).
- **The connection sat idle too long.** Idle connections close after 8 hours. Long-running scripts and workers should reconnect when needed.
- **A script ran too long.** Break long jobs into smaller batches, or run them from a [cron job](https://helpcenter.ruachost.com/cpanel/advanced/setting-up-cron-jobs-in-cpanel/).

## "Access denied for user"

The username, password or host is wrong, or the user hasn't been added to the database. See [Fixing "Error establishing a database connection"](https://helpcenter.ruachost.com/cpanel/databases/error-establishing-a-database-connection/).

Connecting from outside your hosting account? You also need to allow your IP address. See [Configuring remote MySQL access](https://helpcenter.ruachost.com/cpanel/databases/configuring-remote-mysql-access-in-cpanel/).

## Error 1064: "You have an error in your SQL syntax"

The SQL query itself is wrong: a typo, a missing quote, or a reserved word used as a name. See [Understanding MySQL error 1064](https://helpcenter.ruachost.com/developers/databases/understanding-mysql-error-1064/).

## Error 1044 or 1227: "Access denied; you need the SUPER privilege"

This usually happens when importing a database exported from another server. It contains `DEFINER` statements or settings that need administrator rights. See [Troubleshooting MySQL definer issues](https://helpcenter.ruachost.com/developers/databases/troubleshooting-mysql-definer-issues/).

## "Table is marked as crashed and should be repaired"

Repair the table. See [Optimizing and repairing MySQL databases using phpMyAdmin](https://helpcenter.ruachost.com/cpanel/databases/optimizing-and-repairing-mysql-databases-using-phpmyadmin/).

## Related articles

- [Database limits and versions](https://helpcenter.ruachost.com/cpanel/databases/database-limits-and-versions/)
- [Enabling the slow query log in MySQL](https://helpcenter.ruachost.com/developers/databases/enabling-the-slow-query-log-in-mysql/)
