Many websites use MySQL databases to store information and settings. However, there are some reasons why the connection to the database may fail. This article describes some commonly seen error messages when connecting to a database, as well as some general tips to keep in mind when setting up a database connection.
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. Here are some commonly seen error messages and reasons which cause them.
Unable to connect to database / Error connecting to database
This error message means that your software is unable to setup a working database connection for some reason. What reason is that? That’s information that your software is hiding to protect sensitive information.
If you’re using off the shelf software, you should check if your software has some kind of error log or debug functionality that can show the real error message.
With WordPress, this is done with the WP_DEBUG option. You can learn more about that option in the official WordPress support article: https://wordpress.org/support/article/debugging-in-wordpress/
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.
It’s also a good idea to enable Display Errors in your control panel, which will ensure that any errors from PHP are shown. You can find this option under Alter PHP Config in your control panel.
No such file or directory
The message No such file or directory
is shown when you’re using localhost
as your database hostname. Using localhost
means your script will look for the database on the same server as your website, which does 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
. The easiest way to make sure you have the right database name is to go to the MySQL Databases section in your control panel. If you haven’t created your database yet, you can also do it through this menu.
It could also mean that your database password is incorrect. The database password is the same as your hosting account password (which is different from your client area password!). You can find your hosting account password by logging in to your client area, click Manage next the account, scroll down to MySQL Details and click Show next to the Password field.
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
.
Make sure you are connecting from within hosting account
InfinityFree databases are only accessible from within your InfinityFree hosting acounts. Our database servers are not accessible from other locations, like developer tools on your own computer, websites on other hosting providers, game software, mobile apps and so on. Remote database access is only available with premium hosting.
I’m sure I’m using the right database credentials
If you’re absolutely 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!