10

I have tried to install magento, but when I am trying to install magento from browser, it shows "Database connection error" during Magento installation.

enter image description here

9

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.

  • still have database connection error. – Darshan Patel Sep 30 '15 at 18:37
5

This is a pretty old question but I came across it recently and I hope this answer helps someone else. My issue came down to an old version of Magento on top of a new WAMP installation. Since MySQL 5.6.1, the have_innodb variable has been removed. However, the Magento installer checks for that variable and throws an error if it doesn't find it. If you actually check the exception log you'll see an error that the database server does not support InnoDB. Yet in the catch handler it only logs that exception and throws a generic "Database connection error" message.

The simplest fix, if you're sure your DB supports InnoDB, is to simply edit app\code\core\Mage\Install\Model\Installer\Db.php, find the checkDatabase method, and comment out the portion at the end of the try block that checks for have_innodb. Normally, I would not advocate editing core files, but this is only to get the installer working, so I'd say it's safe enough.

4

First create a db http://localhost/phpmyadmin

let assume DB Name : testdb

Configuration page db name : testdb username : root password : empty(don't enter any value)

4
  • Go to app/code/core/Mage/Install/Model/Installer/Db.php
  • Find the checkDatabase($data) function
  • At the end of this function, there is the following code:

    Mage::throwException(Mage::helper('install')->__('Database connection error.'));
    
  • Change it to the following:

    Mage::throwException(Mage::helper('install')->__($e->getMessage()));
    
  • Go to your browser, where you are installing Magento, click the Continue button

  • Now, you should be able to see some proper error message

In my case, I got the following error message:

Database server does not support the InnoDB storage engine.

So, to solve this, I commented the InnoDB check in the same checkDatabase function.

// check InnoDB support
/*if (!isset($variables['have_innodb']) || $variables['have_innodb'] != 'YES') {
    Mage::throwException(Mage::helper('install')->__('Database server does not support the InnoDB storage engine.'));
}*/

After that, I was able to install Magento.

1

You can try to use this code to find more details about what kind of database connection error it is or to check if the username and password is correct

<?php
      $mysqli=mysqli_connect("host","user","password","database name");

      if(mysqli_connect_errno()){
          printf("Connect failed: %s\n", mysqli_connect_error());
          exit();
      }else{
          echo "Connection succesfull!";
      }
?>

Save this script as a php file and put it on the server. The output will be connection error, or if no error the output will be "Connection successful!". "host" - you can enter here "localhost", "user" - here you must enter database user name, "password" - here you must enter database password, "database name" - here you must enter the database name.

0
  1. You have given the database name as magento
  2. So, please check whether you created that magento named database or not.
  3. If not, You need to create a blank db called magento first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.