Databases: Database connection failed. (split from pre-historic thread)

Databases: Database connection failed. (split from pre-historic thread)

by Pranay Karwa -
Number of replies: 2

Hello all!


I have been trying to install Moodle 2.4 on my website and at the 'Database settings step', I keep getting this error every time I try to go forward:


"Error: Database connection failed
It is possible that the database is overloaded or otherwise not running properly.
The site administrator should also check that the database details have been correctly specified in config.php

Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'seniorwa_pranay'@'localhost' (using password: YES) in /home/seniorwa/public_html/moodle/lib/dml/mysqli_native_moodle_database.php on line 76"


Contrary to what they say on the documentation page, the setup does not create a config.php file.

I did edit the config-dist.php file to enter all the required details like my database name, the database username, the password etc.


Upon reading suggestions on the Installation support page, I tried 2 approaches:

i. Renaming the config-dist.php file to config.php, which leads to the installation not starting at all and a database connection error at the outset.

ii. Tried keeping both files, config-dist.php and config.php in the Moodle directory, which leads to the same error as I've mentioned above in orange.


I have set the following parameters in my config.php and config-dist.php (they are identical)


$CFG->dbtype    = 'mysqli';      // 'pgsql', 'mysqli', 'mssql', 'sqlsrv' or 'oci'

$CFG->dblibrary = 'native';     // 'native' only at the moment

$CFG->dbhost    = 'localhost';  // eg 'localhost' or 'db.isp.com' or IP

$CFG->dbname    = 'seniorwa_moodle';     // database name, eg moodle

$CFG->dbuser    = 'seniorwa_pranay';   // your database username

$CFG->dbpass    = '<system generated password>';   // your database password

$CFG->prefix    = 'mdl_'; 

CFG->dboptions = array(

    'dbpersist' => false,       

    'dbsocket'  => false,       

    'dbport'    => '', 

);

$CFG->wwwroot   = 'http://seniorsoncall.co.in/moodle';

$CFG->dataroot  = '/home/seniorwa/moodledata';

$CFG->directorypermissions = 02777;

$CFG->admin = 'admin';

require_once(dirname(__FILE__) . '/lib/setup.php');


Can anyone share a working config.php or config-dist.php file with me and tell me how to get this config vs config-dist issue sorted?


I have been at this since a couple of days now and would really appreciate any kind of help or guidance from anyone on this.


Thank you!

Average of ratings: -
In reply to Pranay Karwa

Re: Databases: Database connection failed.

by Colin Fraser -
Picture of Documentation writers Picture of Testers

mmm too much information here... we didn't need to see the wwwroot or dataroot variables... and you may have compromised security to your site, so be careful... 

This is a major error and there are usually only a few causes. Often it relates to the information you put into your installer, when it asks for passwords and such. 

First is that the database has not been properly installed. So can you access it from the command line or its own interface? Create tables and such? The cofig.php file will generate automagically, if you have everything installed properly, and it is really easy to miss something. 

Second PHP has not been properly installed. If you run a php page called info.php with nothing but 

<?php

info()  

?>

in it, do you get the full list of information. Check it right through as PHP will sometimes run until it gets an error, if the error is minor, but then it stops. This kept me guessing for a day once and I still have no idea why it did run it all, but once fixed, it worked. 

Third, have you created a database shell first? Create a database without anything in it, make sure you can access it.  

Fourth, have you made sure you are referring to the database in the Moodle installer properly? It MUST point to the right db. 

Fifth, are you using the exact same password for dbpass as the root password for the db installation? If these are different, you will get that error message. 

These are the five most common errors, believe it or not, that will generate that message. I have found that no matter how often I install a Moodle, I will sometimes get it wrong, by a moment's inattentiveness, or just careless "I know what I am doing," and going on autopilot while installing. These are the things to try first... and 99% of the time, it is one of them.  

In reply to Pranay Karwa

Re: Databases: Database connection failed. (split from pre-historic thread)

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I moved this to Installation help and please don't resurrect ancient threads. Start a new one with a proper subject and description. Thanks smile