Changing default charset in MySQL

In order to change the default character set in MySQL follow the given steps:

First login to the server as root

Open the file /etc/my.cnf

vi /etc/my.cnf

Add the following lines below [client] section:

default-character-set=utf8

Add the following lines below [mysqld] section:

default-character-set=utf8
init_connect=’SET NAMES utf8′

Once done restart your mysql service.

service mysql restart

Now check with the following command:

mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1554730
Server version: 5.0.91-community MySQL Community Edition (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
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)

mysql>quit

Now you can see the default charset set to utf8.