Introduction
How do I change the default Character set within MySQL/MariaDB to UTF-8?
Procedure
The UTF-8 charset has been deprecated in MySQL 8:
'utf8' has been used by MySQL as an alias for the 'utf8mb3' character set, but this usage is being phased out. As of MySQL 8.0.28, 'SHOW' statements and columns of Information Schema tables display 'utf8mb3' instead. For new applications, 'utf8mb4' should be implemented.
MySQL Reference Manual: The utf8 Character Set (Deprecated alias for utf8mb3)
To change the default character set within MySQL/MariaDB, follow the steps below.
- Open the MySQL configuration file at /etc/my.cnf:
vi /etc/my.cnf
- Under the [client] section, add the following entry:
default-character-set=utf8
If the [client] section does not exist, add it to the top of the configuration file. - Under the [mysqld] section, add your desired encoding:
Please note this is [mysqld], not [mysql]!
default-character-set=utf8
init_connect='SET NAMES utf8' - Once complete, you'll need to issue a restart to the MySQL server:
/scripts/restartsrv_mysql
If you would like to validate that the changes have been applied, you may pass the following command via MySQL CLI:
show variables like 'char%';
Please note that existing databases are not affected unless you alter their character sets. You can review MySQL documentation on this topic for more information on how this works:
MySQL Reference Manual: Character Set Configuration
MySQL Reference Manual: Database Character Set and Collation
MariaDB also provides a useful document on setting the character set for your databases:
MariaDB Documentation: Setting Character Sets and Collations
Comments
0 comments
Article is closed for comments.