php 无法访问moodle中的数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9921091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 07:55:34  来源:igfitidea点击:

can not access to database in moodle

phpmysqldatabasemoodle

提问by aya

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

我正在使用moodle并且更改了我的网站的位置,但是我遇到了这个错误。

My config.php is:

我的 config.php 是:

<?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

错误:数据库连接失败。

数据库可能过载或运行不正常。

站点管理员还应检查 config.php 中是否正确指定了数据库详细信息

回答by aya

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.

我的问题解决了。我没有为我的用户设置正确的数据库权限,当我这样做时,我的问题就解决了。

回答by Mark Fraser

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
  • mysql 服务器未在本地主机(指定的服务器)上运行
  • config.php 中的任何其他参数(数据库名称、登录名、密码)都是错误的

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

您可以通过 mysql 命令行客户端(或 phpmyadmin 或类似程序)使用这些凭据连接到 mysql 吗?

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

您可能想发布有关您的服务器环境的更多信息。

回答by SAIDI Hamza

I had the same problem.

我有同样的问题。

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

我编辑了数据库端口,因为我没有使用默认的 MySQL 端口 3306。

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

如果您使用的是默认端口,请将其保留为空字符串。