Unable to connect to MySQL Database
This article helps to troubleshoot common issues when using MySQL.
Common Error Messages
Using MySQL is great, but the error message returned if there is an issue logging in to your database can be quite confusing. This article explains a few common error messages as well as methods to resolve them.
Unable to connect to database / Error connecting to database
Many applications hide the real error messages from MySQL for security reasons, as the error messages themselves may reveal sensitive information. If you see a generic message like "Unable to connect to the database" or "Error connecting to database", it means your software is hiding the real error message from you.
If you wrote the software yourself, you should use something like mysqli_error or mysqli_connect_error (if you're using MySQLi) or mysql_error (if you're using the outdated MySQL library). Using the PDO library should throw a PDOException which you can print for more information.
If you're using a premade script, you should check if the script has any error logs or debug mode so you can see the actual error message.
You can also enable Display Errors in your control panel (under Alter PHP Config) to ensure PHP errors are shown.
No such file or directory
The message No such file or directory
is shown when you're trying to use localhost
as your database hostname. Using localhost
means your script will look for the database on the same server as your website, which will not work on InfinityFree.
The database hostname should look like sql123.epizy.com
, but the exact value depends on your account. You can find your database hostname in your control panel under MySQL Databases.
Access denied for user
You can see an error message which looks like Access denied for user 'epiz_12345678'@'192.168.0.*' (using password: YES)
. This message means that the user was able to connect, but does not have access to the provided database name.
This could mean one of two things.
This generally means that the database name is not correct. If you entered the database name my_database
when creating the database, the full database name looks like epiz_12345678_my_database
. You can find the database name in the MySQL Databases menu as well.
It could also mean that your database password is incorrect. The database password is the same as your hosting account password (which is generally different from your client area password!). You can find your hosting account password by logging in to your client area, select the account, scroll down to Account Password and click Show.
General Tips
Here is a short checklist to go through which should help solve most common issues.
Make sure you are using your hosting account password.
The most common issue is that people are not using the right database password. You should use the hosting account password in your script configuration.
Important: the hosting account password is not your client area password!The hosting account password is randomly generated when you create an account, and you can find or change it in your client area (click the account in the accounts list).
Make sure you are using the right database hostname (not localhost).
Most hosting providers use localhost
for the database hostname. This does not work for InfinityFree. The database hostname should look like sql123.epizy.com
. You can find your database hostname in your control panel in the MySQL Databases section.
Make sure you are using the right database name and username.
Your database name and database username can be found in the MySQL Databases in the Control Panel of your hosting account. The database username typically looks like epiz_12345678
and the database name looks like epiz_12345678_mydb
.
I'm sure I'm using the right database credentials.
If you're completely sure you are using the right database password, database hostname, database name and database username, but you are still unable to connect to your database, you can get help by opening a new forum discussion. When doing so, please don't forget to include the full error message returned by the database connection code.