Change The Default Character Set in MySQL/MariaDB to utf8

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:

  1. Open the MySQL configuration file at /etc/my.cnf:
vi /etc/my.cnf
  1. 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.

  1. Under [mysqld] add (please note this is [mysqld] not [mysql]):
default-character-set=utf8
init_connect='SET NAMES utf8'
  1. 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.

Important
The utf8 charset has been deprecated in MySQL 8:

utf8has been used by MySQL is 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.

Leave a Comment