According to this post in drupal.org, multi-byte UTF-8 support for MySQL and other database drivers, allows emojis, Asian symbols, mathematical symbols, etc with your Drupal 7 installation. The only caveat to this is that your Drupal installation must be at least Version 7.50 or higher.
- Drupal: Version 7.50 or above
In order to allow for large indexes, MySQL must be set up with the following my.cnf settings:
[mysqld] innodb_large_prefix=true innodb_file_format=barracuda innodb_file_per_table=true
After editing the my.cnf file (often located at /etc/mysql/my.cnf), don't forget to restart the mysql service (for example, with the command sudo service mysql restart) in order to load the new configuration.
2. The PHP MySQL driver must support the utf8mb4 charset (libmysqlclient 5.5.3 and up, as well as mysqlnd 5.0.9 and up).
3. The MySQL server must support the utf8mb4 charset (5.5.3 and up).
Run the command mysql --version to see your current MySQL version.
Steps to enable
- First, back up your database and convert all existing tables to utf8mb4, such as by using the drush command provided by the utf8mb4_convert contrib project.
- Set the "charset" and "collation" keys on the database connection array in settings.php to "utf8mb4" and "utf8mb4_general_ci" respectively:
$databases['default']['default'] = array( 'driver' => 'mysql', 'database' => 'databasename', 'username' => 'username', 'password' => 'password', 'host' => 'localhost', 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_general_ci', );
For new Drupal installations
- Prior to running the installer, edit settings.php and manually add in the full database settings array code, with 'charset' as 'utf8mb4', and 'collation' as 'utf8mb4_general_ci', and with the actual values for 'database', 'username', 'password', 'host', as shown below:
databases['default']['default'] = array( 'driver' => 'mysql', 'database' => 'databasename', 'username' => 'username', 'password' => 'password', 'host' => 'localhost', 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_general_ci', );
- Then run the installer specifically by accessing install.php, as in http://example.com/install.php (not just http://example.com/)
Other database systems
- PostgreSQL and SQLite support 4-byte UTF-8 out-of-the-box, so no special changes are needed for these.
- MariaDB and other MySQL equivalents should likely work with similar instructions as above for MySQL.
- Database drivers provided by contributed modules may or may not support this feature. The best place to look for answers is the issue queue of the contributed module which provides the database driver you are using.
Converting Characterset & Collation to utf8mb4:
ALTER DATABASE db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; ALTER TABLE tablename CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci; ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Easier way using Drush:
Now to convert all your database tables to utf8mb4 characterset and utf8mb4_general_ci collation, you may make use of the following Drush command called UTF8MB4 Convert. Please find detailed instructions of this command here: https://www.drupal.org/project/utf8mb4_convert.
The conversion process in your terminal after executing the above commands should be as below:
Click image to enlarge
|Click image to enlarge|
|Click image to enlarge|