How to change MySQL character set to UTF8

Change the default character set

Edit the file “/etc/my.cnf”. Add the following description to the [mysqld] section.

[mysqld]
..
.....
.....
default-character-set=utf8
character-set-server=utf8

Restart MySQL after the modification.

/etc/rc.d/init.d/mysqld restart

Change the current character set

mysql> set names utf8;
Query OK, 0 rows affected (0.00 sec)

Check the modified character set

mysql> show variables like "char%";
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
This post is also available in other languages.