Error establishing a database connection - new install of 2.3.10+

Error establishing a database connection - new install of 2.3.10+

by T JR -
Number of replies: 11

i,

I have moodle 1.9 installed and working through dreamhost ´one click´ install but
as they dont provide this service for more recent versions, I am trying to self
install a newer version.

My server is running: PHP Version 5.3.27 & MySql 5.1.66 ...so I am trying Moodle 2.3.10+.

I have copied 2.3.10+ into a seperate folder: /lab/moodle23/moodle and have set
up the data folder and a MySql database. On web install I get through the
database settings fine, Accept Installation T&C´s, In server check, everything is OK except for a Check status against the 1st entry "php_extension - intl - should be installed and enabled for best results´ then when I click continue (after some time) get the message "Error establishing a database connection".

I´ve searched the forum but not found anyway to fix this. Can anybody help?

Many thanks,

Joe

Average of ratings: -
In reply to T JR

Re: Error establishing a database connection - new install of 2.3.10+

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

Is this an upgrade or a completely new install?

You can ignore the intl thing. This usually means the database credentials are wrong. Are you 100% sure the username and password for the database are correct in config.php?

In reply to Howard Miller

Re: Error establishing a database connection - new install of 2.3.10+

by T JR -

This is a completely new install. Absolutely, 100% sure that the database username and password are correct - I´ve double and triple checked it.

In reply to T JR

Re: Error establishing a database connection - new install of 2.3.10+

by T JR -

The config file that was created during webinstall (not the config-dist file) is as below. I have checked that all these details are correct.

<?php // Moodle configuration file

unset($CFG);
global $CFG;
$CFG = new stdClass();

$CFG->dbtype = 'mysqli';
$CFG->dblibrary = 'native';
$CFG->dbhost = 'mysql.teflspain.co';
$CFG->dbname = 'moodle23dbase';
$CFG->dbuser = 'teflmoodle';
$CFG->dbpass = '***';
$CFG->prefix = 'mdl_';
$CFG->dboptions = array (
'dbpersist' => 0,
'dbsocket' => 0,
);

$CFG->wwwroot = 'http://www.teflspain.co/lab/moodle23/moodle';
$CFG->dataroot = '/home/thoreb/moodle23data';
$CFG->admin = 'admin';

$CFG->directorypermissions = 0777;

$CFG->passwordsaltmain = 'DDK(rphZV)3>?HuE9.UONW:~UsN';

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

// There is no php closing tag in this file,
// it is intentional because it prevents trailing whitespace problems!

 

In reply to T JR

Re: Error establishing a database connection - new install of 2.3.10+

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 am looking suspiciously at the dbhost setting (mysql.teflspain.co). Is this a different host to the web server? If so, are you absolutely sure your GRANT command is correct? It's very easy to get it wrong. It should probably look something like...

GRANT select, ... ON moodle23base.* TO teflmoodle@'www.teflspain.co' IDENTIFIED BY '***';

Assuming the database is running and there is nothing (firewall?) blocking the connect then the grant permission being wrong is really the only thing left. 

I checked those two hostnames and they are on completely different subnets. Are you completely happy that MySQL traffic can pass from one to the other? Seems like an unusual setup to me. 

In reply to Howard Miller

Re: Error establishing a database connection - new install of 2.3.10+

by T JR -

Hi Howard,

Many thanks for your continued assistance.

Both the sql and webserver are hosted by dreamhost. The dbase setup gives me limited options, but specifies "You MUST always use your hostname to connect to your database... "localhost" WILL NOT WORK." The hostnames specified are "mysql.teflspain.co" or "welcomehome.teflspain.co" I´m afraid that once you start talking about GRANT commands, it all gets a bit too technical for me. Under my users database permissions there is a section for allowable hosts which contains "%.dreamhost.com", is this related to what you mention with regard to the two subnets?

Many thanks,

Joe

In reply to T JR

Re: Error establishing a database connection - new install of 2.3.10+

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

If you don't know about GRANT commands, how are you sure that your database username and password are correct?

In reply to Howard Miller

Re: Error establishing a database connection - new install of 2.3.10+

by T JR -

Because I have can see the username and password in my Dreamhost panel and I can access it through there and I can also see that these are the same in the Moodle config.php file. Is there another place I should be looking?

In reply to T JR

Re: Error establishing a database connection - new install of 2.3.10+

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

You can see them in the panel but as what? I don't know anything about Dreamhost so I am getting out of my depth. But, however it does it, the database you are using needs permission for that user, with that password to be accessed from the host that your web server is running on. The host bit may be invisible if you don't have a choice about it, however I would expect that there is some place you can say "that username can access that database with those permissions (ALL maybe), and that username has that password". All you are seeing is that the username has a password associated. Are you absolutely sure that the username has permission to access the *particular* database?

I'm rambling a bit, but MySQL has quite finely grained access control - my point is that there's more to go wrong than the username and the password. 

As regards 'allowable hosts' (reading back to your previous message). You should really see an entry for the hostname you are using. 

Have you considered asking Dreamhost support? Might be a simple one. 

In reply to Howard Miller

Re: Error establishing a database connection - new install of 2.3.10+

by T JR -

Hi Howard,

I have copied the Dreamhost panel permission screen below. The database name is not appearing there as I have changed the setup since my first message (various times!). I realise that I can´t get by running newer versions of moodle without either a webhost who supports it or a better understanding of UNIX CLI. I am therefore going to continue with 1.9 for the time being and study up on all these terms that I don´t understand (GRANT, Cron, etc.) so that I can come back to it better prepared. 

Many thanks for all your help.

Joe

Attachment dhost.png
In reply to T JR

Re: Error establishing a database connection - new install of 2.3.10+

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

But... that screen relates to a different database. The database in your config.php is 'moodle23dbase'. The one in the screen above is teflspain_co_3. Does the database 'moodle23dbase' actually exist and if it does what are its permissions?

In reply to T JR

Re: Error establishing a database connection - new install of 2.3.10+

by Bastien H -

I had the same problem, it was a DOS attack. First, you need to check if you are a victim of this attack in the access log file, then set up fail2ban to prevent further attacks :

I wrote a detailed solution about this issue here