A MySQL connection error usually means your website can’t reach the database due to incorrect login credentials, a full connection limit, a stopped database service, or network issues. The solution depends on the exact error message: first check the user permissions and password, then check the number of active connections, and finally verify whether the database server itself is running.
Common MySQL error messages
Before you can fix the problem, you need to know which error you’re dealing with. The most common messages are:
- Error establishing a database connection β often seen with WordPress, indicates incorrect login credentials or an unresponsive database.
- Too many connections β the maximum number of simultaneous connections has been reached.
- Access denied for user β the username, password, or permissions are incorrect.
- Can’t connect to MySQL server β the database server is unreachable, for example due to an incorrect hostname or a stopped service.
- Lost connection to MySQL server during query β the connection drops during a heavy or long-running query, often due to a timeout.
Each message points to a different cause, so always start by reading the exact text in your error log or on your website.
Causes of connection errors
Connection errors usually arise from a combination of configuration and load issues. The most common causes are:
- Incorrect login credentials in your CMS configuration file (e.g., wp-config.php), for example after a migration or manual edit.
- Too many simultaneous connections, often caused by a visitor spike, a plugin that doesn’t close connections properly, or a stuck cronjob.
- Expired or missing permissions for the database user, for example after creating a new database without correctly linking the user.
- A stopped or restarting database service on the server, sometimes due to maintenance or a crash.
- Long-running or inefficient queries that hold the server and block other connections.
Step-by-step troubleshooting
Go through the steps below in order. In many cases, the problem is already found by step two or three.
Check the login credentials
Open your website’s configuration file and compare the database name, username, password, and hostname with the details in your control panel. A single typo or an expired password is a common cause.
Check the number of active connections
Check via your hosting panel or phpMyAdmin how many connections are open. In case of a ‘too many connections’ error, you can temporarily close outdated processes and structurally investigate the cause of the spike.
Check user permissions
Make sure the database user has full permissions on the correct database. This often goes wrong after moving a website or restoring a backup.
Check whether the database service is running
Check in your control panel whether the MySQL service is active. If it’s off or showing an error, contact your hosting provider to have the service restarted.
Analyze slow queries
Use the slow query log to see which queries take a long time or get stuck. Optimize these queries or add indexes to reduce the load on the database.
Preventing connection errors
After resolving an acute error, it’s wise to take structural measures to prevent the problem from recurring:
- Keep plugins, themes, and CMS versions up to date, so they don’t needlessly keep connections open.
- Monitor the number of database connections regularly, especially after growth in visitor numbers.
- Use caching to reduce the number of database queries per page view.
- Ensure daily backups, so you can quickly fall back on a working version in case of a serious issue.
- Choose a hosting environment with sufficient capacity, such as NVMe storage and LiteSpeed servers, which handle load better than outdated infrastructure.
At Tandata, you manage your databases via Plesk, where you can view users, permissions, and active connections in a clear dashboard. If you’re unsure whether your environment has sufficient capacity, check out the options for web hosting or read more about switching to Tandata if your current provider doesn’t resolve structural issues.
If you get stuck analyzing an error message, check the knowledge base for more background articles or contact support.
Frequently Asked Questions
Why do I get ‘too many connections’ when my site has few visitors?
This usually indicates connections that aren’t being closed properly, for example due to a plugin, cronjob, or faulty script. Check active processes and close stuck connections.
Can I increase the maximum number of connections myself?
This depends on your hosting environment and package type. If in doubt, contact your provider so they can assess whether an increase fits within the server resources.
What does ‘access denied for user’ mean?
This error means the username, password, or permissions don’t match the database. Check the configuration file and the user settings in your control panel.
How do I prevent connection errors after a migration?
After a migration, always check whether the database user is reconnected to the correct database and whether the login credentials in the configuration file have been updated correctly.
Is a connection error harmful to my data?
Usually not directly, but prolonged errors can lead to failed transactions. Always make sure you have up-to-date backups.
Conclusion
You solve MySQL connection errors step by step: check login credentials, review the number of active connections, verify user permissions, and check whether the database service is running. By monitoring and applying caching, you prevent the problem from recurring.