How do I change the default Character set within MySQL/MariaDB to utf8?
In order to set change the default character set within MySQL/MariaDB follow the steps below:
- Open the MySQL configuration file at /etc/my.cnf:
- Under the [client] section, add the following entry:
default-character-set=utf8Note: If the [client] section does not exist, add it to the top of the configuration file.
- Under [mysqld] add (please note this is [mysqld] not [mysql]):
init_connect='SET NAMES utf8'
- Once complete, you'll need to issue a restart to the MySQL server:
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 :: MySQL 5.6 Reference Manual :: 10.5 Character Set Configuration
- MySQL :: MySQL 5.6 Reference Manual :: 10.1.3.3 Database Character Set and Collation
MariaDB also provides a useful document on setting the character set for your databases: