Applicable to:
- Plesk for Linux
Question
How to change the MySQL/MariaDB default charset from "utf8_unicode_ci" to "utf8mb4_unicode_ci" in MySQL in Plesk for Linux?
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
databasename
/*!40101 default charset=utf8 */
As a workaround, apply the following solution:
-
Connect to a Plesk server via SSH.
-
Create the file
/root/dbscript.sh
with the following content:CONFIG_TEXT: #!/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:
CONFIG_TEXT: /root/dbscript.sh
Additionally, you could also set the UTF8mb4 charset directly within the configuration file of your database server by using the information below:
Change the charset directly in MySQL/MariaDB configuration (via SSH)
Warning: These changes affect in database creation that is done directly in MySQL/MariaDB and is not done via Plesk interaction.
-
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:
# systemctl restart mariadb
Additional information
Best way to make sure a MySQL database is fully in UTF8 - Server Fault
sql - How to convert a big MySQL Database from utf8 to utf8mb4? - Stack Overflow
mysql - Trouble with UTF-8 characters; what I see is not what I stored - Stack Overflow
Comments
0 comments
Please sign in to leave a comment.