Error: Database connection failed.

Error: Database connection failed.

by Winter Quan -
Number of replies: 26

While I install my Moodle, such error occur:

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

However, I'm sure my system has a perfect coonection to database, for I could use "phpMyAdmin" to manage my database.
and in config.php of Moodle, my set is as follows:

$CFG->dbtype    = 'mysql';       // mysql or postgres7 (for now)
$CFG->dbhost    = 'localhost';   // eg localhost or db.isp.com
$CFG->dbname    = 'moodle';      // database name, eg moodle
$CFG->dbuser    = 'root';    // your database username
$CFG->dbpass    = '123456';    // your database password
$CFG->prefix    = 'mdl_';        // Prefix to use for all table names

$CFG->dbpersist = false;         // Should database connections be reused?
                 // "false" is the most stable setting
                 // "true" can improve performance sometimes

I'm using WinXP.
What's wrong with me?

Thanks a lot.

Average of ratings: -
In reply to Winter Quan

Re: Error: Database connection failed.

by Winter Quan -

I've added script "phpinfo() " in config.php and got the following information:

mysql

MySQL Supportenabled
Active Persistent Links 0
Active Links 0
Client API version 3.23.49


DirectiveLocal ValueMaster Value
mysql.allow_persistentOnOn
mysql.connect_timeout6060
mysql.default_hostno valueno value
mysql.default_passwordno valueno value
mysql.default_portno valueno value
mysql.default_socketno valueno value
mysql.default_userno valueno value
mysql.max_linksUnlimitedUnlimited
mysql.max_persistentUnlimitedUnlimited
mysql.trace_modeOffOff


I thought my database connection is OK.
then what is my problem?

Please help me!!!!

In reply to Winter Quan

Re: Error: Database connection failed.

by Brian Burger -
I am getting the same thing with Server 2003 and II6.  My MySQL works fine.  So does my PHP.  Which install of PHP did you use?
In reply to Winter Quan

Re: Error: Database connection failed.

by Jameson Fitzpatrick -

Find out where moodle tries to connect
Go to your moodle base directory and edit the file
lib/setup.php   .

search for the follwing lines
    $CFG->libdir   = "$CFG->dirroot/lib";

    require_once("$CFG->libdir/adodb/adodb.inc.php"); // Database access functions

    $db = &ADONewConnection($CFG->dbtype);

after this line add the folliwing command
$db->debug=1;
 
save the file.

use your html browser and load the page that produced the error message again.
The first line will show you the result of the debug. It will show you where Moodle expects the socket.

If the two socket location are not the same no database connection will be established

In reply to Jameson Fitzpatrick

Re: Error: Database connection failed.

by Marlen Harrison -

ummm, ok, I did this, what's an "html browser" and where do I get one...I can't get past the database, username, etc page in the initial set-up of moodle...so frustrated!

marlen

In reply to Marlen Harrison

Re: Error: Database connection failed.

by James Phillips -
It is a little hard to say with such scant details, but you may need to prefix the username and password for your database with local host username (somebody correct me if I'm wrong!).
i.e.

"username" becomes "localhostusername_username", and
"password" becomes "localhostusername_password"
etc.
In reply to James Phillips

Re: Error: Database connection failed.

by Marlen Harrison -

Thx, gonna uninstall and have fantastico install for me...a little birdy told me this was light years easier!

marlen

In reply to Winter Quan

Re: Error: Database connection failed.

by Ed MacDonald -

Hi....Were you able to resolve this issue? I'm having the same problem, Database works fine for a while and then I get the error message "database connection failed". I'm not really seeing a solution posted in here.

Has anyone been able to resolve this issue?

I can provide all the details you like.....

Any assitance would be greatly appreciated,

Ed.

In reply to Ed MacDonald

Re: Error: Database connection failed.

by Andrew Wojtowicz -
your mysql service might have stopped.  check it.
In reply to Andrew Wojtowicz

Re: Error: Database connection failed.

by Ed MacDonald -
My hosting provider informs me that it was still running. Also, I was able to connect to the database through MySQL Control Center, just not the moodle application. Its very strange because the symptoms are always the same.....first it slows down then stops, then it comes back slowly like something is starting up again, restarting so to speak.
In reply to Ed MacDonald

Re: Error: Database connection failed.

by Marshal Morse -

Are you still having this problem.  A couple of days ago mine started doing the same.  I was running normal for over 6 weeks without any problems, and usage was probably dropping off rather than increasing at the time.  Oh, it  may be helpful to note that rebooting the server temporarily fixes it...strange.

Thanks, 

Marshal

In reply to Marshal Morse

Re: Error: Database connection failed.

by Iande Coutinho -

Hi Marshal,

  I only happen to have had this problem during the install. I installed all php5, Apache2, PostGres 8.0 and Moodle from scratch. I found that I didn't uncommended the extention for pgsql.dll in the php.ini file... Perhaps, your  system has lost the configuration file. After reading a few questions on the subject, most of the answers seemed to be DB access reladed. Check if your SGDB is running fine smile

Best of luck!

Iandé

In reply to Iande Coutinho

Re: Error: Database connection failed.

by Malcolm Slade -
Hmmm, as of Friday 15th April 2005 all I get through Moodle is a "Database Connection Failed, maybe overloaded etc. etc. error". sad

The database exists and is browseable and all the settings are there in config.php.  Everything has been great for the last 4 months but sods law that now I come to finish my dissertation it all goes belly up. angry
In reply to Winter Quan

Re: Error: Database connection failed.

by raju malav -
hi dear....
i got ur problem...
but i will only say its far better if u use linux in place of windows...anyhow if u still interested in windows then tell me back soon i may give u a link from where u have to do nothing all will be done itself...
so just tell me
i installed moodle 1.4 on linux faedora so if uchange ur plan let me know...
i will be giving tips for ur every problem..as i also faced lot many problems whil installing moodle..
hope now u dont need to face any problem..
regards raju...
In reply to raju malav

Re: Error: Database connection failed.

by Billy Browne -

This also happens for us, and I have noticed it only happens when accessing the main page (index.php).

So if anyone has any input into the problem I would be greatful.

Cheers

In reply to Billy Browne

Re: Error: Database connection failed.

by brad winchester -

I had the problem while using cPanel.  I checked the server status from the admin panel and it said the disk was at max 100% and mySQL had failed. I contacted the hosting company and they resolved the server.

I sent in a snapshot along with my help ticket request.  I attached it to this message for your viewing.

Attachment diskmax.png
In reply to brad winchester

Re: Error: Database connection failed.

by Nick Martinez - Meakins -
Hi I appear to be having the same problem here, i have installed moodle 1.9.3+ on to a usb pen-drive and running it on windows. Now it works fine in the computer at home but when i try running it on one of the uni computers i get the error!

Any ideas guys?

this is my congig.php file, hope its of some help smile

<?php /// Moodle Configuration File

unset($CFG);

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

$CFG->wwwroot = 'http://localhost';
$CFG->dirroot = 'E:\moodle1\server\moodle';
$CFG->dataroot = 'E:\moodle1\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.
?>

thank you again!

nick
In reply to Nick Martinez - Meakins

Re: Error: Database connection failed.

by Richard Enison -
NMM,

I am assuming that the pen drive includes MySQL and all the settings (like database name, username, and p/w) that are included in the config.php file that you show in your post, so that's not the problem. The only thing I can think of is: did you start up MySQL on the uni computer before running Moodle? Is there a copy of MySQL already running on it, or on a LAN it is part of, that might interfere with doing that?

RLE
In reply to Nick Martinez - Meakins

Re: Error: Database connection failed.

by Luis de Vasconcelos -

I don't know if this is the cause of any of your problems, but shouldn't:

$CFG->dataroot = 'E:\moodle1\server/moodledata';

be:

$CFG->dataroot = 'E:\moodle1\server\moodledata';

You have a forward slash between server and moodledata. It should be a back slash.

In reply to Luis de Vasconcelos

Re: Error: Database connection failed.

by Richard Enison -
LdV,

No. PHP, on Windows systems, treats both types of slashes in pathnames interchangeably. See http://us.php.net/manual/en/function.dirname.php. In fact, it is better to use forward slashes, because backslashes are used as escape characters in PHP, so that if one uses backslashes in pathnames, it is best to escape them by doubling them, e.g., E:\\moodle1\\server\\moodledata. It is common to see pathnames with both types of slashes, as in NMM's post, in Moodle, because when Moodle generates pathnames by concatenating a filename and/or one or more directory names to $CFG->dirroot, it uses forward slashes.

RLE
Average of ratings: Useful (1)
In reply to Nick Martinez - Meakins

Re: Error: Database connection failed.

by Jon Witts -
Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Hi Nick,

Can you get a basic php script to connect to your database at uni?

e.g.:
<?php
$dbconnect = @mysql_connect('localhost', 'root', 'mypassword');
if (!$dbconnect) {
echo '<p>Unable to connect to the database server!</p>' ;
exit();
} else {
echo '<p>Successfully connected to the database server!</p>';
}
?>

N.B. replace db user name and password with your own!

If this does not run on the uni machine then there is definitely something with the configuration on the uni machine, possibly as RLE suggests that MySQL is already running on the uni machine. The other option is that the uni security settings will not allow the MySQL service to run...
In reply to Winter Quan

Re: Error: Database connection failed.

by Moodle Geek -

Has any one been able to fix the following problem:

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

In our case, the website has been running fine for a very long time until recently when the above message started to popup from time to time. The problem occurs at any time during the day. Interestingly whenever this happens, our moodle site goes offline/online repeatedly for a few minutes until it goes offline completely displaying the above message. Restarting the machine seems to be the only fix at the moment.

I have looked at all possible places to get a clue but without any success. I looked into Event Viewer, Apache Logs, MySQL Logs, Moodle Logs but nothing seems to be disturbing. By the way, we are using Windows Server 2003. Is it possible that any windows service (running in the background) can mess up things.

Thanks...

In reply to Moodle Geek

回复: Re: Error: Database connection failed.

by yuliang xu -

you said your config.php is:

......

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

$CFG->dbuser    = 'root';    // your database username
$CFG->dbpass    = '123456';    // your database password

.....

in my case , " root " are NOT allowed in config file, it just don't work . I added a new database user 'moodle' and let him has permission to schema 'moodle'

In reply to yuliang xu

Re: 回复: Re: Error: Database connection failed.

by Marco De Martino -

Hi All,

I had the same problem also with the latest version (2.3+) and it was just a problem of password to reach the database (I'm using XAMPP).

Just adapt the config.php in the moodle folder with dbpass = 'correctpassword'

And that's it.

BR,

  Marco

In reply to Moodle Geek

Re: Error: Database connection failed.

by Brandan Jones -

I got this after a crash in Moodle 3.3.  I was unable to connect to mysql through any means: Moodle, phpmyadmin, or SQuirreL.  

When Moodle crashed, it appears that it left a mysql.pid file.  I renamed this, restarted Moodle/MySQL, and all worked well.  It created a new mysql.pid file.