Skip to main content

The Problem:

It is required that you store all your data in Unicode format (UTF-8). New installations must be performed into databases that have their default character set as Unicode. If you are upgrading, you should perform the UTF-8 migration process (see the Admin page).

The current setup of MySQL or MariaDB is using ‘utf8’. This character set does not support four byte characters which include some emoji. Trying to use these characters will result in an error when updating a record, and any information being sent to the database will be lost Please consider changing your settings to ‘utf8mb4’. See the documentation for full details.

 

 

The Solution:

Login to mysql/mariadb via SSH using root user or the user associated with moodle db:

(All code snippets below are editable)

mysql -u moodle_user -p 123456

use moodle;

SHOW LOCAL VARIABLES LIKE 'character_set_database';

--# In my case I got this:

+------------------------+---------+
| Variable_name          |  Value  |
+------------------------+---------+
| character_set_database | utf8mb3 |
+------------------------+---------+
1 row in set (0.001 sec)

--# Run the following to change to utf8mb4

ALTER DATABASE moodle CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

--# Verify again to make sure the change took effect

SHOW LOCAL VARIABLES LIKE 'character_set_database';

+------------------------+---------+
| Variable_name          |  Value  |
+------------------------+---------+
| character_set_database | utf8mb4 |
+------------------------+---------+
1 row in set (0.001 sec)

 

Make sure in your ./config.php ‘dbcollation’ is set to ‘utf8mb4_unicode_ci’

//...

$CFG->dboptions = array (
  'dbpersist' => 0,
  'dbport' => '',
  'dbsocket' => '',
  'dbcollation' => 'utf8mb4_unicode_ci',  // 'utf8_general_ci' doesn't work
);

//...

 

If the above doesn’t work or errors, you may need to add the following to my.cnf and/or mariadb.cnf

sudo nano /etc/mysql/my.cnf

#... append to the bottom

#Moodle required
[ client]
default-character-set = utf8mb4

[mysqld]
innodb_file_format = Barracuda
innodb_file_per_table = 1
innodb_large_prefix = true

character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
skip-character-set-client-handshake

[mysql]
default-character-set = utf8mb4

 

Restart mariadb:

systemctl restart mariadb

 

Refresh the page and you should now be able to proceed with the installation:

Let me know how it goes or if you have other solutions. Good luck!

 

P.S. Also, check my article on updating MariaDB since Moodle requires 10.5.6 or greater I think. Ignore the part that is about Plesk if you’re not using it — the process is exactly the same except the last step 9. is not necessary on vanilla Ubuntu or CentOS.

Leave a Reply