Fix: Database Connection Error (2): Could not Connect to MySql
When you render a Joomla hosted website, you might see the following message indicating either you reached the maximum SQL connections or your SQL Database has crashed or become unavailable.
Database connection error (2): Could not connect to MySQL.
Here are some things that COULD have happened to cause this error:
- A table in your database memory leaked, choked your database, and crashed it.
- At the point in time you rendered your web page, you went over the maximum allowed connections to your SQL database.
- The database was somehow mapped incorrectly in configuration.php (Doubtful, if your website is older)
- Your database was hacked by repeated attacks to it
- SQL Server has crashed entirely
What you can do to PREVENT or FIX this error:
Ensure your CMS (Joomla or Wordpress) is connecting to your database via localhost host name and NOT 127.0.0.1. Connecting with an IP creates unnecessary duplicate connections to your database that can cause it to crash.
Increase MySQL database connections in the backend in my.cnf MySQL configuration file.
Increase MySQL Timeout wait_timeoute in my.cnf MySQL configuration file.
Stay on the latest MySQL server version
Repair your MySQL database using the built-in repair function tool