How to fix max_user_connections problem

The “max_user_connections” limit it set to prevent a single account from creating a ton of connections to the database and overloading the server, causing problems for everyone else.

Increasing the maximum number of connections would be the easy solution. But unless you host your own database server, you can’t change that limit. Note that this is a MySQL restrictions, not a PHP restriction.

Instead, there are some other things you could try:

  • If you have multiple websites on the same account, try moving them to separate accounts.
  • If you’ve written the code yourself, make sure that you’re only creating one database connection for every request. I’ve seen scripts which create a new database connection for every database query, and never close connections, which makes it easy to have a lot of connections open at the same time.
  • Especially if you have slow running code, it might be a good idea to manually close connections and reopen connections after your queries. This should also help reduce the number of active connections.
  • If you’re using off the shelf software, you may want to looking into caching more things, which might help reduce database load as well.

If none of the things above help (or are simply impossible), then you might just need a bigger hosting plan which allows for more database connections.

1 Like