moodle installation - Configuring DB

moodle installation - Configuring DB

by Geethan Samarawickrama -
Number of replies: 6

I'm getting the below error while running the moodle installation on ubuntu 20.04. This happens during the configuration of DB settings.


"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



Warning: mysqli::__construct(): (HY000/2002): No such file or directory in /var/www/html/moodle/lib/dml/mysqli_native_moodle_database.php on line 83 "


Average of ratings: -
In reply to Geethan Samarawickrama

Re: moodle installation - Configuring DB

by Ken Task -
Picture of Particularly helpful Moodlers

A mysql database server on same server as code set to localhost would not use TCP/IP port for DB server, but it would use 'socket' by default.  So do not fill in the port ... leave blank.

IF there is already a config.php file in moodle code directory, edit the config.php file with a text editor and in the section for DB variables, set both the following as shown:

  'dbport' => '',
  'dbsocket' => '',

Also ... you've posted in Developers forum ... don't think this is a developer question.    There is a forum for installing and upgrading.   So, next time you post, please pick an appropriate forum for the problem.  Plus it does help to have some info about Moodle version as well.

'SoS', Ken

In reply to Ken Task

Re: moodle installation - Configuring DB

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
...strange error, don't you think?
In reply to Howard Miller

Re: moodle installation - Configuring DB

by Ken Task -
Picture of Particularly helpful Moodlers

Thanks for moving ...

Not so 'strange' if not familiar with MySQLDB server on localhost ...

* That line in that file:

        ob_start();
*        $conn = new mysqli($dbhost, $dbuser, $dbpass, '', $dbport, $dbsocket); //  Connect without db
        $dberr = ob_get_contents();
        ob_end_clean();
        $errorno = @$conn->connect_errno;

Am assuming OP did create the DB and knows creds prior to trying install.  MySQLD service has to be running to do that.

Am also assuming that OP has followed:

https://docs.moodle.org/311/en/Step-by-step_Installation_Guide_for_Ubuntu

'SoS', Ken

In reply to Ken Task

Re: moodle installation - Configuring DB

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
To be fair - I never set up Moodle any other way than by creating my own config.php so I don't really know what that form does. Normally 'localhost' means 'use the socket' and any IP address means 'use TCP/IP'. It doesn't hurt to try 127.0.0.1 in place of localhost - just in case it works.

Having said that - the culprit is more often than not misuse of the GRANT command.
In reply to Geethan Samarawickrama

Re: moodle installation - Configuring DB

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Wild guess: Are you sure that you are not running MariaDB? MariaDB has its own driver (the previous screen).

Also try without entering the database port. Moodle will take the default.