Installing Drupal with Mysql utf8mb4 character encoding

Drupal installation usually does not take into account Mysql utf8mb4 capabilities to provide true unicode character storage in Mysql databases. This is due to the reason that Mysql by default does not allow large indexes and dynamic row format required by Drupal to install database objects in utf8mb4 character encoding. So we will see how to install Drupal in utf8mb4 encoding directly instead of converting the database to utf8mb4 format post installation.
So before beginning to install Drupal, we need to make some changes to our Mysql startup configuration. Add the below to your Mysql .cnf file and then restart Mysql server.
Under [mysqld]
innodb_large_prefix=true
innodb_file_format=barracuda
innodb_file_per_table=true
Now login to Mysql and create a database and user with required privileges on the database.

Start Mysql installation as usual and go screen by screen as mentioned here, do not overstep else your installation will go without utf8mb4 database objects being created. Choose the profile of your choice as shown and click 'Save and continue'.

Choose the language as shown in this screen and click on 'Save and continue'.

Stop at this screen and donot go any further. We will need to perform some manual steps to continue. By this time you can see a settings.php file under <drupal root>/sites/default directory.
Open settings.php file in an editor and go to a blank $databases array variable. Now change this variable as follows.
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => '<name of the database you created>',
'username' => '<user you created>',
'password' => '<password of the user>',
'host' => '<host like localhost>',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
);
Save and close this file.
Now start Drupal installation again by typing this url on your browser - http://<your host like localhost>/install.php
Complete the installation by providing the required details in the installation screens. Your Drupal will now be installed with utf8mb4 character encoding and all subsequent changes to the database will be made with the same encoding.
Photo credits
https://cdn-1.wp.nginx.com/wp-content/uploads/2016/02/drupal_v2_1920x120...
https://blog.templatetoaster.com/install-drupal-7-8-step-by-step/
- Log in to post comments