The third command simply saves it and exits.My system runs on Linux Mandriva, RDBMS - MySQL 5. This converts all tables from using latin1 to using UTF8. The second command replaces all instances of DEFAULT CHARSET=latin1 with DEFAULT CHARSET=utf8mb4. This is used to fix up the database's default charset and collation. The first command replaces all instances of DEFAULT CHARACTER SET latin1 with DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci. ( I choose VIM for this only because every linux user is/should be familiar with it).įirst we open the file using VIM, and then run the three commands. I have chosen to do this with VIM however you can use any search+replace editor or program. Now we need to edit the dump and correct the incorrect charsets that have been used. We will make the desired changes within dump-fixed.sql and we will keep dump.sql as it is as a backup just in case. Next step is to copy dump.sql to dump-fixed.sql achieved by When you run this command a database dump will be generated into dump.sql dbname The name of the database to convert. B We use this option so that our dump will contain drop table and create table syntax (which we will change the syntax for). add-drop-database Required so we can restore over the top of our existing database.
skip-set-charset Obviously not wanted or needed as we are changing it anyway. single-transaction To reduce our workload if anything goes wrong. default-character-set=utf8mb4 To set the default character set. e Extended inserts for better performance. c Complete inserts for better compatibility.
password The password for the above user. Username The username to access your database.
We do however need to set several arguments in order to clean up the charsets and provide a dump that is not going to cause you any problems if you are moving this database to a different database server or find yourself having to restore on a reverted system. The first step is of course to dump out the database and of course we will use mysqldump for this. Sed -i.bak -e 's/DEFAULT CHARACTER SET latin1/DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci/' -e 's/DEFAULT CHARSET=latin1/DEFAULT CHARSET=utf8mb4/' dump.sql
%s/DEFAULT CHARACTER SET latin1/DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci/ %s/DEFAULT CHARSET=latin1/DEFAULT CHARSET=utf8mb4/ wq Mysqldump -uusername -ppassword -c -e -default-character-set=utf8mb4 -single-transaction -skip-set-charset -add-drop-database -B dbname > dump.sql If you have previously installed Moodle and are now getting the error the following process will allow you to convert your database. You can simply run the below query in your database to resolve the issue.Īlter database mydatabasename charset=utf8mb4 If you have created your database schema and are receiving the error during your initial installation your Moodle database will still be empty. The difference is described in the unicode documentation page. Utf8mb4_unicode and utf8mb4_general are not the same but similar. skip-character-set parameter, will restore the database with your new default character set of utf8mb4. Having made your default character set utf8mb4, a mysqldump restore of your database with the (This was good for ubuntu server lucid 10.04 2.6.32-24-server Jan 2011)
To make mysql default to utf8 you can edit /etc/my.cnf as follows. The descriptions elsewhere in this section cover making the utf8 database versions using mysqldump. It is a database engine that is very widely used in open source projects and it contains details of all the stuff in your Moodle such as usernames etc and pointers to all the files that have been uploaded to it.ġ) Change your mysql to have utf8mb4 as its character set and It is perhaps worth noting that Mysql is nothing to do specifically with Moodle. Details about four byte UTF-8 can be found at MySQL_full_unicode_support. Since Moodle 3.1 we now use four byte UTF-8 by default.
However the UTF8 check during install and upgrade was only been implemented in Moodle 2.0 and you may find you are unable to upgrade because your database was not set up originally as utf8 when you first installed Mysql or because you have been running Moodle since before 1.8 and haven't previously converted your database. Moodle requires UTF8 in order to provide better multilingual support and has done since Moodle 1.8. If you are upgrading, you should perform the UTF-8 migration process (see the Admin page). New installations must be performed into databases that have their default character set as Unicode. It is required that you store all your data in Unicode format (UTF-8). You may see the following error when upgrading your Moodle. 4.3 Special chars won't import correctly.4 Converting a database containing tables.