Migrating Moodle from MySQL backend to MariaDB

We have restored the Original MySQL DB in MariaDB, and have made changes in config.php file as follows.

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

  $CFG->dbtype    = 'mariadb';
  $CFG->dblibrary = 'native';
  $CFG->dbhost    = 'xxxx.rds.amazonaws.com';
  $CFG->dbname    = 'xxx_lms';
  $CFG->dbuser    = 'admin';
  $CFG->dbpass    = 'uAnaxxxxxxxx';
  $CFG->prefix    = 'mdl_';
  $CFG->dboptions = array (
       'dbpersist' => 0,
       'dbport' => '',
       'dbsocket' => '',
       'dbcollation' => 'utf8mb4_unicode_ci',
  );

  $CFG->wwwroot   = 'http://xx.xxx.xxx.23';
  $CFG->dataroot  = '/var/www/moodledata';
  $CFG->admin     = 'admin';
  $CFG->directorypermissions = 0777;

  require_once(__DIR__ . '/lib/setup.php');

But whole trying access my Moodle, I’m getting the following error.

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

Did I missed any steps in between?
Is there a way to solve the issue?

Any pointers would be helpful

Hi @kallada

Welcome to the NethServer community!

Are you running Moodle on Windows or something?
This here is the NethServer Forum, for the NethServer system, not for Moodle running on anything else…

I do not see ANY reference to NethServer in your post, and AFAIK, there’s NO MySQL used in NethServer…

And this line is an absolute give-away:

$CFG->dataroot  = '/var/www/moodledata';

/var/www exists in NethServer, but is ONLY used for the default webpage…

My 2 cents
Andy

@Andy_Wismer Sorry for making any confusion.
You are right, currently my Moodle instance is running from an Ubuntu/MySQL AWS EC2. But based on a client request, we are planning to tryout NS (EC2) with MariaDB (RDS) . As the first step we are trying to migrate from MySQL to MariaDB, and hence got this error. So thought of asking my issue here though I haven’t started using NS.

Once again sorry for making any confusion.

Hi @kallada

I’d suggest asking the Moodle guys on their Forum about the specifics of migrating MySQL → MariaDB.
When forked from MySQL, MariaDB was binary, API and file compatible with MySQL, but there are probably quite a few differences since then, as both have different development and focus.

The guys there probably have a suitable script to migrate the data and whatever needs to be adapted.

There IS a Moodle module for NethServer, whch works more or less out of the box, and uses MariaDB like almost all other applications on NethServer. There are actually often several different versions of MariaDB running concurrently on NethServer. NextCloud uses the latest in NethServer, it’s running on 10.5…

My 2 cents
Andy

1 Like

Here’s the link for Moodle as a module on NethServer. The Integrator (Dev) is known as very helpful…

https://wiki.nethserver.org/doku.php?id=moodle

My 2 cents
Andy

2 Likes

This is an example of the Nethserver Moodle DB config using Mariadb 10.3.

$CFG->dbtype    = 'mariadb';
$CFG->dblibrary = 'native';
$CFG->dbhost    = '127.0.0.1';
$CFG->dbname    = 'moodle';
$CFG->dbuser    = 'moodle';
$CFG->dbpass    = 'secret';
$CFG->prefix    = 'mdl_';
$CFG->dboptions = array (
  'dbpersist' => false,
  'dbport' => '3313',
  'dbsocket' => false,
  'dbcollation' => 'utf8mb4_unicode_ci',
);

Maybe you need to define the right port or change the dbsocket to false…

2 Likes

I’d opt for doing a clean moodle install on NethServer. Export all data from the existing Ubuntu server and import them in NethServer-moodle…