Common MySQL Connection Errors

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!

1 Like
Error establishing a database connection
INSERT not working
PHP sql connect not working
'Warning: mysqli_real_connect(): (HY000/1045): Access denied for user' Error
How to connect DB with Bedrock WP?
Can not connect to my database
Database connection
My website is returning: Error 520 Web server is returning an unknown error
Error creating a MYSQL function
Access denied for user 'epiz_31263592'@'192.168.0.64' (using password: YES)
Having a data base issue
The MySQL Connection could not be established
Website is not loading
I've uploaded admin folder but when I check in url it's showing no such file or directory
Database link failed
My PHP will not connect with my SQL
SQLSTATE[HY000] [2002] No such file or directory
Sql down
Error establishing a database connection
My database is not connecting
Site Keeps Getting Redirect to ww01.site.com
Error establishing a database connection
Why i cant reached my website?
Impossible connection on mysql
Error establishing a database connection
Warning: mysqli::__construct(): (HY000/2002): No such file or directory in /home/vol1000_5/epizy.com
Access Denied when accessing database
SQL connection timeout
SQL Connection Error PDO PHP
Pages with mysql won't load
Cannot connect to MySql DB from PHP code?
PHPAdmin Page Not Found
Multiple sites having database connection errors
Unable to connect db
A problem during making back up
Access denied to Mysql database
Http error 500
Error establishing a database connection
How to output latvian symbols?
My website doesnt work as it should idk
Website suspension
Error establishing a database connection wp admin
Database servers are Down!
Error-Report: Access denied for user 'epiz_xxx'@'192.168.0.%' to database 'epiz_xxx_xxx'
Mysql
Can't migrate Laravel database
Sql207.epizy.com doesn't load
How to solve Failed: No such file or directory problem
My MysQL Database Removed
Not Connected Problem
Error connecting to database
Can I Open DB Using MySQL Workbench?
Sqlstate[hy000] [1045
Mysql Databasses
Sqlstate[hy000] [1045
Troubleshooting error returning json when acessing db table
Database Corrupted
Cannot connect to mysql database
"Random" Error establishing a database connection error on TMAC PowerStore
Error establishing a database connection

A post was split to a new topic: Failed to connect to Mysql