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

发布于 2025-01-11 04:52:46 字数 464 浏览 3 评论 0原文

我们已使用远程数据库配置 Moodle 应用程序连接。我收到数据库连接错误。当我使用 localhost 而不是远程 ip 时,它就可以工作了。有人可以帮忙吗。提前致谢。 下面是我的 config.php 文件

$CFG->dbtype = 'mysqli';
$CFG->dlibrary = '本机';
$CFG->dbhost = '3.92.37.127';
$CFG->dbname = 'rtalms';
$CFG->dbuser = 'rta_user';
$CFG->dbpass = 'AbZyyh546^%paSS';
$CFG->前缀='mdl_';
$CFG->dboptions = 数组 (
'dbpersist' => 0,

We have configured moodle application connection using remote Database.I'm getting Database connection error. When i'm use localhost instead of remote ip its working. Can anybody help. Thanks in advance.
the below is my config.php file

$CFG->dbtype    = 'mysqli';
$CFG->dblibrary = 'native';
$CFG->dbhost    = '3.92.37.127';
$CFG->dbname    = 'rtalms';
$CFG->dbuser    = 'rta_user';
$CFG->dbpass    = 'AbZyyh546^%paSS';
$CFG->prefix    = 'mdl_';
$CFG->dboptions = array (
'dbpersist' => 0,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪花飘飘的天空 2025-01-18 04:52:46

要使用远程数据库,您需要在 config.php 中设置此值。

$CFG->dbhost    = 'localhost';  // eg 'localhost' or 'db.isp.com' or IP

有关详细信息,请参阅 Moodle 文件夹中的 config-dist.php

//=========================================================================
// 1. DATABASE SETUP
//=========================================================================
// First, you need to configure the database where all Moodle data       //
// will be stored.  This database must already have been created         //
// and a username/password created to access it.                         //

$CFG->dbtype    = 'pgsql';      // 'pgsql', 'mariadb', 'mysqli', 'auroramysql', 'sqlsrv' or 'oci'
$CFG->dblibrary = 'native';     // 'native' only at the moment
$CFG->dbhost    = 'localhost';  // eg 'localhost' or 'db.isp.com' or IP
$CFG->dbname    = 'moodle';     // database name, eg moodle
$CFG->dbuser    = 'username';   // your database username
$CFG->dbpass    = 'password';   // your database password
$CFG->prefix    = 'mdl_';       // prefix to use for all table names
$CFG->dboptions = array(
    'dbpersist' => false,       // should persistent database connections be
                                //  used? set to 'false' for the most stable
                                //  setting, 'true' can improve performance
                                //  sometimes
    'dbsocket'  => false,       // should connection via UNIX socket be used?
                                //  if you set it to 'true' or custom path
                                //  here set dbhost to 'localhost',
                                //  (please note mysql is always using socket
                                //  if dbhost is 'localhost' - if you need
                                //  local port connection use '127.0.0.1')
    'dbport'    => '',          // the TCP port number to use when connecting
                                //  to the server. keep empty string for the
                                //  default port
    'dbhandlesoptions' => false,// On PostgreSQL poolers like pgbouncer don't
                                // support advanced options on connection.
                                // If you set those in the database then
                                // the advanced settings will not be sent.
    'dbcollation' => 'utf8mb4_unicode_ci', // MySQL has partial and full UTF-8
                                // support. If you wish to use partial UTF-8
                                // (three bytes) then set this option to
                                // 'utf8_unicode_ci', otherwise this option
                                // can be removed for MySQL (by default it will
                                // use 'utf8mb4_unicode_ci'. This option should
                                // be removed for all other databases.
    // 'fetchbuffersize' => 100000, // On PostgreSQL, this option sets a limit
                                // on the number of rows that are fetched into
                                // memory when doing a large recordset query
                                // (e.g. search indexing). Default is 100000.
                                // Uncomment and set to a value to change it,
                                // or zero to turn off the limit. You need to
                                // set to zero if you are using pg_bouncer in
                                // 'transaction' mode (it is fine in 'session'
                                // mode).
    /*
    'connecttimeout' => null, // Set connect timeout in seconds. Not all drivers support it.
    'readonly' => [          // Set to read-only slave details, to get safe reads
                             // from there instead of the master node. Optional.
                             // Currently supported by pgsql and mysqli variety classes.
                             // If not supported silently ignored.
      'instance' => [        // Readonly slave connection parameters
        [
          'dbhost' => 'slave.dbhost',
          'dbport' => '',    // Defaults to master port
          'dbuser' => '',    // Defaults to master user
          'dbpass' => '',    // Defaults to master password
        ],
        [...],
      ],

    Instance(s) can alternatively be specified as:

      'instance' => 'slave.dbhost',
      'instance' => ['slave.dbhost1', 'slave.dbhost2'],
      'instance' => ['dbhost' => 'slave.dbhost', 'dbport' => '', 'dbuser' => '', 'dbpass' => ''],

      'connecttimeout' => 2, // Set read-only slave connect timeout in seconds. See above.
      'latency' => 0.5,      // Set read-only slave sync latency in seconds.
                             // When 'latency' seconds have lapsed after an update to a table
                             // it is deemed safe to use readonly slave for reading from the table.
                             // It is optional. If omitted once written to a table it will always
                             // use master handle for reading.
                             // Lower values increase the performance, but setting it too low means
                             // missing the master-slave sync.
      'exclude_tables' => [  // Tables to exclude from read-only slave feature.
          'table1',          // Should not be used, unless in rare cases when some area of the system
          'table2',          // is malfunctioning and you still want to use readonly feature.
      ],                     // Then one can exclude offending tables while investigating.

    More info available in lib/dml/moodle_read_slave_trait.php where the feature is implemented.
    ]
     */
// For all database config settings see https://docs.moodle.org/en/Database_settings
);

To use a remote database, you'll need to set this value in config.php

$CFG->dbhost    = 'localhost';  // eg 'localhost' or 'db.isp.com' or IP

See config-dist.php in your Moodle folder for details

//=========================================================================
// 1. DATABASE SETUP
//=========================================================================
// First, you need to configure the database where all Moodle data       //
// will be stored.  This database must already have been created         //
// and a username/password created to access it.                         //

$CFG->dbtype    = 'pgsql';      // 'pgsql', 'mariadb', 'mysqli', 'auroramysql', 'sqlsrv' or 'oci'
$CFG->dblibrary = 'native';     // 'native' only at the moment
$CFG->dbhost    = 'localhost';  // eg 'localhost' or 'db.isp.com' or IP
$CFG->dbname    = 'moodle';     // database name, eg moodle
$CFG->dbuser    = 'username';   // your database username
$CFG->dbpass    = 'password';   // your database password
$CFG->prefix    = 'mdl_';       // prefix to use for all table names
$CFG->dboptions = array(
    'dbpersist' => false,       // should persistent database connections be
                                //  used? set to 'false' for the most stable
                                //  setting, 'true' can improve performance
                                //  sometimes
    'dbsocket'  => false,       // should connection via UNIX socket be used?
                                //  if you set it to 'true' or custom path
                                //  here set dbhost to 'localhost',
                                //  (please note mysql is always using socket
                                //  if dbhost is 'localhost' - if you need
                                //  local port connection use '127.0.0.1')
    'dbport'    => '',          // the TCP port number to use when connecting
                                //  to the server. keep empty string for the
                                //  default port
    'dbhandlesoptions' => false,// On PostgreSQL poolers like pgbouncer don't
                                // support advanced options on connection.
                                // If you set those in the database then
                                // the advanced settings will not be sent.
    'dbcollation' => 'utf8mb4_unicode_ci', // MySQL has partial and full UTF-8
                                // support. If you wish to use partial UTF-8
                                // (three bytes) then set this option to
                                // 'utf8_unicode_ci', otherwise this option
                                // can be removed for MySQL (by default it will
                                // use 'utf8mb4_unicode_ci'. This option should
                                // be removed for all other databases.
    // 'fetchbuffersize' => 100000, // On PostgreSQL, this option sets a limit
                                // on the number of rows that are fetched into
                                // memory when doing a large recordset query
                                // (e.g. search indexing). Default is 100000.
                                // Uncomment and set to a value to change it,
                                // or zero to turn off the limit. You need to
                                // set to zero if you are using pg_bouncer in
                                // 'transaction' mode (it is fine in 'session'
                                // mode).
    /*
    'connecttimeout' => null, // Set connect timeout in seconds. Not all drivers support it.
    'readonly' => [          // Set to read-only slave details, to get safe reads
                             // from there instead of the master node. Optional.
                             // Currently supported by pgsql and mysqli variety classes.
                             // If not supported silently ignored.
      'instance' => [        // Readonly slave connection parameters
        [
          'dbhost' => 'slave.dbhost',
          'dbport' => '',    // Defaults to master port
          'dbuser' => '',    // Defaults to master user
          'dbpass' => '',    // Defaults to master password
        ],
        [...],
      ],

    Instance(s) can alternatively be specified as:

      'instance' => 'slave.dbhost',
      'instance' => ['slave.dbhost1', 'slave.dbhost2'],
      'instance' => ['dbhost' => 'slave.dbhost', 'dbport' => '', 'dbuser' => '', 'dbpass' => ''],

      'connecttimeout' => 2, // Set read-only slave connect timeout in seconds. See above.
      'latency' => 0.5,      // Set read-only slave sync latency in seconds.
                             // When 'latency' seconds have lapsed after an update to a table
                             // it is deemed safe to use readonly slave for reading from the table.
                             // It is optional. If omitted once written to a table it will always
                             // use master handle for reading.
                             // Lower values increase the performance, but setting it too low means
                             // missing the master-slave sync.
      'exclude_tables' => [  // Tables to exclude from read-only slave feature.
          'table1',          // Should not be used, unless in rare cases when some area of the system
          'table2',          // is malfunctioning and you still want to use readonly feature.
      ],                     // Then one can exclude offending tables while investigating.

    More info available in lib/dml/moodle_read_slave_trait.php where the feature is implemented.
    ]
     */
// For all database config settings see https://docs.moodle.org/en/Database_settings
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文