Error: Database connection failed

Error: Database connection failed

by Rachel Dilts -
Number of replies: 6

Okay, I've got past the installation phase, and was actually on my new course, and this morning I get this error message trying to get back on.

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

Any ideas on where to go from here?

Average of ratings: -
In reply to Rachel Dilts

Re: Error: Database connection failed

by Matt Molloy -

Hi Rachel,

The fact that you were already able to use your new installation suggests that you were able to connect to the database, using some username and password.

So, is it possible that today, MySQL is not running, and just needs to be started? Checking this depends on what installation package you used, and what sort of system you are running. It may be as simple as accessing the XAMPP control panel and starting MySQL.

Post some more information on what package you used to install - xampp or whatever, your platform, your server (IIS or Apache) and are you trying to connect on localhost, from another machine on the same network, or on the internet?

Stick to posting on the one forum, this one is probably the most suitable. Don't cross post, it is a bit of a no no!

Post the additional information, and I'm sure someone will be able to help.

Regards,

Matt

In reply to Rachel Dilts

Re: Error: Database connection failed

by collingwood college -
Hi l am having the same probs and despite the fact that after some playing around with xammp l got mysql going but the error still persist?  Any suggestions?
In reply to Rachel Dilts

Re: Error: Database connection failed

by collingwood college -
Hi l am having the same probs and despite the fact that after some playing around with xammp l got mysql going but the error still persist?  Any suggestions?
In reply to collingwood college

Re: Error: Database connection failed

by Matt Molloy -

Hi,

The config.php file in the moodle folder is where you tell moodle where your database is, and how to connect to it. Bottom line is that if you have MySQL installed correctly,

  • and you have it running (remember, some of the install packages require that you manually start MySQL. Others you can start by clicking on the xampp control panel).
  • and you have set up an empty database ready to receive your Moodle site
  • and you have specified the correct path to the database
  • and you have set the username and password correctly

then moodle will be able to connect to the database unless it is being prevented by a firewall or anti-virus software. The other possibility is that some other service may be already listening on the port that MySQL needs to use, and is blocking it.

How do your settings compare to these:

$CFG->dbtype = 'mysql';

$CFG->dbhost = 'localhost';
//use this if the database is running on the same machine as your moodle installation. Otherwise, you must specify the full path to wherever the database lives.

$CFG->dbname = 'moodle'; //(assuming this is what you called it)

$CFG->dbuser = 'your_username'; //(whatever username you configured. The default is 'root', and this is what it will be unless you have changed it.

$CFG->dbpass = 'your_password'; The default is blank, no password, and this is what it will be unless you changed it.

Matt

In reply to Matt Molloy

Re: Error: Database connection failed

by Zahra E -
Hi,
I have the same problem and occasionally this error is shown. it is strange because sometimes by a refresh it be fixed and sometimes at the same time one user has no problem while the other one see the error!
my config.php is the same as Matt said
I don't know what should I do!
In reply to Zahra E

Re: Error: Database connection failed

by Anu Kajla -

Hi I got same problem ,yesterday i successfully install moodle software, i can log on to my user account to but when i came back today and want to start it again than it shows me this error

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

Even I check my XAMPP control panel it shows me that Appache and Mysql are not running but i am also unable to run both of them.My config.php configuration is :-

 ca<?php  /// Moodle Configuration File

unset($CFG);

$CFG->dbtype    = 'mysql';
$CFG->dbhost    = 'localhost';
$CFG->dbname    = 'moodle';
$CFG->dbuser    = 'root';
$CFG->dbpass    = 'P@ssword123';
$CFG->dbpersist =  false;
$CFG->prefix    = 'mdl_';

$CFG->wwwroot   = 'http://localhost';
$CFG->dirroot   = 'C:\Moodle\server\moodle';
$CFG->dataroot  = 'C:\Moodle\server/moodledata';
$CFG->admin     = 'admin';

$CFG->directorypermissions = 00777;  // try 02777 on a server in Safe Mode

require_once("$CFG->dirroot/lib/setup.php");
// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,
// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.
?>n

 Help me , if you got the solution plz