Introduction
How do I change the default Character set within MySQL/MariaDB to utf8?
Procedure
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:
vi /etc/my.cnf
- Under the [client] section, add the following entry:
default-character-set=utf8
Note: 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]):
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 :: 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:
Setting Character Sets and Collations
Important
The utf8 charset has been deprecated in MySQL 8:
utf8
has been used by MySQL is an alias for theutf8mb3
character set, but this usage is being phased out; as of MySQL 8.0.28,SHOW
statements and columns of Information Schema tables displayutf8mb3
instead.
Comments
0 comments
Article is closed for comments.