I've been looking into this for a friend and going through forums to investigate this error. After you've checked your database connection details, I find what FisherC said below is the most probable cause for the error.
FisherC says:
I have the same problem, but I'm not sure for the same reasons. I installed the standard 1.5 installation package. I have uninstalled and reinstalled once just to make sure everything was OK. Basically after I use my website (using the default Joomla welcome template with NO modifications whatsoever) I start to get the "cannot connect to MYSQL." I contacted my webhost, and the problem is the number of MYSQL database queries. It goes up to about 200,000 in the first few minutes of use and then after that every page load is a few hundred to few thousand queries (per page). The webserver limits me to 50,000 queries an hour and I am blowing past that quickly with just 1 person (me!) on the site so they just refuse the connnection after a while. Obviously something is not right. I am searching the forums for an answer and if I don't find one I'll repost. I just thought I'd share this with you in case this your problem too.
Source: Joomla Forum: http://forum.joomla.org/viewtopic.php?f=433&t=198257
My Solution
I have over 20 joomla websites on my virtual server and I haven't had this problem.
- I setup a website with about 20 3rd-party components installed, 15 modules and about 15 plugins (excluding the core modules/plugins) and managed to recreate this error.
- I disabled half of these but still got the error.
- Cleared the expired cache but still got the error.
- I then uninstalled half of these (including Kunena and Agora forums), specifically database intensive plugins and the error happened less...
- I then went through the menus and installation screen to get rid of anything that was not visibly used on the website. The website was working fine and I was able resume my click-happy habits.
It's a given that in my test, there was only 1 user (me). There are reports though that some people set up websites with NO 3rd-party items whatsoever... For those of you with this issue, I'd double-check your website host allows Joomla and if they don't, look for either an upgrade or a different host.
If your website has been LIVE for a while and it's returning this error despite having little installed, then check your logs to see if anyone has been trying to hack your website. There are a number of components I have found that even with captcha features, still get hacked with viagra emails and what have you (eg. JoomlaBook). If you don't want to go through the logs, try setting up a test joomla site with a different database and user and see if that behaves the same way.
Virtual Hosts
I used to have an account with 1&1 (oneandone.co.uk) and I would strongly urge Joomla developers to avoid them like the plague. They have been less than helpful and when I only had one Joomla site with them, they still would block me thinking I was trying to hack into their servers because of the number of queries Joomla does and the number of times I refresh the page and upload files. Why they think that developers should not be able to send a 1000 queries a minute or why a developer has to refresh the page, make a change, upload, etc. well it's beyond a joke and no one should waste their time with such companies.