Moodle database connection error

I am trying to set up moodle and work with connection problem. See below configuration:

<?php  // Moodle configuration file

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

$CFG->dbtype    = 'mysqli';
$CFG->dblibrary = 'native';
$CFG->dbhost    = 'localhost';
$CFG->dbname    = 'gs_vle';
$CFG->dbuser    = 'root';
$CFG->dbpass    = 'root';
$CFG->prefix    = 'mdl_';
$CFG->dboptions = array (
 'dbpersist' => 0,
 'dbport' => '',
 'dbsocket' => '',
);

$CFG->wwwroot   = 'http://localhost/~ryanme/work/vle/';
$CFG->dataroot  = '/Users/ryanme/sites/work/moodledata';
$CFG->admin     = 'admin';

$CFG->directorypermissions = 0777;

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

      

I am getting a database connection error. See the error below:

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::mysqli(): (HY000/2002): No such file or directory in /Users/ryanme/Sites/work/vle/lib/dml/mysqli_native_moodle_database.php on line 79

      

What I've done

  • Login with root user via terminal and check. I can see the database with show databases;

    . This works great.
  • Checking if the settings are correct over and over again.
  • Compares the config file with the command settings, and it's pretty much the same.
  • Make sure the mysqli module is enabled for PHP. It.

What can I do to find out what is causing the database connection error?

+3


source to share


2 answers


After further research. I found this was due to "mysql on OS X getting places in the correct sock file a little bit wrong". Once I created the sim links needed for the mysql sock file everything worked.



For details see.

+1


source


I had the same problem. To solve this problem, I put the server name instead of localhost



$CFG->dbhost = '<name-of-the-server>'

;

0


source







All Articles