6

I am using moodle and I change location of my web site, but I am facing this error.

My config.php is:

<?php  /// Moodle Configuration File 

unset($CFG);

$CFG->dbtype    = 'mysql';
$CFG->dbhost    = 'localhost';
$CFG->dbname    = 'lightsys_test';
$CFG->dbuser    = 'lightsys_test';
$CFG->dbpass    = '123456a';
$CFG->dbpersist =  false;
$CFG->prefix    = 'mdl_';

$CFG->wwwroot   = 'http://www.lightsystem.ir/aya/moodle';

$CFG->dirroot   = '/home/lightsys/public_html/aya/moodle';
$CFG->dataroot  = '/home/lightsys/public_html/aya/moodledata';
$CFG->admin     = 'admin';

$CFG->directorypermissions = 00777;  // try 02777 on a server in Safe Mode

require_once("$CFG->dirroot/lib/setup.php");
// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,
// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.
// /home/lightsys/public_html/aya/moodle/
?>

And my error is:

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

Community
  • 1
  • 1
aya
  • 1,597
  • 4
  • 29
  • 59
  • Did you tried to connect to that database with another client? Eg MySql Workbench or something like that? – Gian Mar 29 '12 at 08:03

4 Answers4

9

Thanks to everyone.

My problem is solved. I had not set the right permission to my database, for my user, and when I did it my problem was solved.

franzlorenzon
  • 5,845
  • 6
  • 36
  • 58
aya
  • 1,597
  • 4
  • 29
  • 59
1

This error message could mean:

  • mysql server is not running on localhost (the indicated server)
  • any of the other parameters (db name, login, password) in config.php are wrong

Can you connect to mysql using those credentials through the mysql command line client (or phpmyadmin or similar)?

You may want to post more info about your server environment.

Mark Fraser
  • 3,160
  • 2
  • 29
  • 48
0

I had the same problem.

I edited the database port because I'm not using the default MySQL port which is 3306.

If you are using the default port, leave it as an empty string.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
0
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO username@localhost;

Use the following query to grant permissions to your user. Remember to change username with your db user that you've created.

Mahi
  • 1,164
  • 17
  • 24