Error: Moodle could not connect to the database.

Error: Moodle could not connect to the database.

by Ori Wallenstein -
Number of replies: 3

 Hi,

We had moodle installed and running for months, and then suddenly one morning we get this message whenever we try to access our moodle site -

Error: Moodle could not connect to the database.

It's possible the database itself is just not working at the moment.

The admin should also check that the database details have been correctly specified in config.php

Database host: localhost
Database name: moodle
Database user: MyDBUser

MySQL is running and has the user and password. In fact, when I tried to install Moodle on a different server that is running MySQL, and copied the moodle tables to that server, I got the same error.

Any suggestions?

Thanks,

Ori

Average of ratings: -
In reply to Ori Wallenstein

Re: Error: Moodle could not connect to the database.

by Timothy Takemoto -

Dear Ori,

When there are too many people trying to access the database at once, or perhaps when some script, such as perhaps a glossary autolinking script is taxing connections to the database too fiercely (you can control the number of connections), or for other reasons unknown, moodle installations have been known to throw a a "could not connect to the database." This is usually (always?) temporary, and often cured by setting the "database persist" (or similar) variable to false in config.php. But this was set to false by default some time back I believe. In any event you will find quite a lot on this problem if you search for "could not connect to the database" here on the forums.
Tim 

In reply to Ori Wallenstein

Re: Error: Moodle could not connect to the database.

by Pau Bofill -
Hi,

I'm having exactly the same problem, database connection failed after running moodle for a long time.

Previous posts within this forum suggest setting up  config.php properly but I don't think this is the problem.  When I restart the server, moodle seems to work ok, but mysqld is using up 99% of CPU !!! After 30 mins or so mysql drops down and cron.php takes most of the CPU time.

Thanks
Pau
In reply to Pau Bofill

Re: Error: Moodle could not connect to the database.

by Pau Bofill -
There seems to be something the matter with cron.php. When it was on (or when I executed admin/cron.php) the whole o.s. (linux) went down. Now, I've removed cron.php from my crontab and the system has been holding alright for 48 hours.

Any ideas?

Thanks,
Pau