Setting UTF-8 as the default encoding for MySQL

Edit the MySQL configuration file from the following path /etc/mysql/my.cnf and set the below configuration:

#/etc/mysql/my.cnf
[client]
default-character-set = utf8
 
[mysql]
default-character-set = utf8
 
[mysqld]
collation-server = utf8_unicode_ci
init-connect = 'SET NAMES utf8'
character-set-server = utf8

Restart the mysql server using the following command

/etc/init.d/mysql restart

Enjoyed this post? Share it!