Magento Tutorials

How to Solve Database Connection Error in Magento 1 & 2

What is Magento “Database Connection Error”?

Database Connection Error happens during Magento installation, at the Database Connection step (Magento 1) or Add a Database step (Magento 2).

database connection error magento 1

In Magento 2, the error message is different, and also does a better job of explaining the problem: “Database does not exist or specified database server user does not have privileges to access this database.

database connection error magento 2

Why does this happen?

There are several reasons why the Database Connection Error happens:

  • Database does not exist
  • Invalid username or password
  • Specified database server user does not have permission to access the database

How to solve it?

  • First of all, check your database user name and password. Before you proceed to this step, you should have already set up the database in MySQL. You need to create a user and grant access privileges to that user.
  • Then check your MySQL server configuration. The default port number is 3306. However, your system admin might change it to something else. Or if you are using software packages such as MAMP/WAMP, the port number may be set to something other than 3306. In these cases, you need to explicitly put the port number in the Host field.
  • If all these are correct and you still have database connection error, you can try to use root account to access the database. If root works out, that means there are problems with the privileges in your MySQL settings. Although it is not recommended to use root account for future production deployment as it adds security risks to the server.

Further Reading:

Magento Database Structure with EAV Pattern: How It Will “Take Over” Your Job?
How to use Magento Database Repair Tool
How to Create the Magento Database Schema