Question
How to change MySQL servers default charset from “utf8_unicode_ci” to “utf8mb4_unicode_ci”?
Answer
This feature is not yet implemented in Plesk.
If you would like to see this feature in Plesk, please vote for it on Plesk UserVoice:
By default, Plesk databases are created with the following command:
MYSQL_LIN: CREATE DATABASE
/*!40101 default charset=utf8 */
databasename
Â
As a workaround, apply the following solution:
 Â
Â
-
Connect to a Plesk server via SSH.
-
Create the fileÂ
/root/dbscript.sh
with the following content:#!/bin/sh
db=${NEW_DATABASE_NAME}
plesk db "ALTER DATABASE $db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci" -
Set the correct permissions:
# chmod 0775 /root/dbscript.sh
- In Plesk, go to Tools & Settings > Event Manager and click Add Event Handler.
-
Choose the event type to be Database created, put the following in the command section and press OK:
/root/dbscript.sh
Â
Warning: The solution works only in database creation in MySQL directly.
-
Log into the server via SSH.
-
Open the /etc/my.cnf file with the vi text editor and add the following lines under the corresponding sections:
Note: for example if the default-character-set line already specified replace its value with utf8mb4.
CONFIG_TEXT: [client]
default-character-set = utf8mb4[mysql]
default-character-set = utf8mb4[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci -
Restart the MariaDB service to apply the changes:
# service mariadb restart
Â
Â