How to change mysql default character set to UTF8 in my.cnf?

April 3rd, 2012 by Manoj Chauhan Leave a reply »

You can change the default character set to UTF8 in mysql 5.5 using below steps

1. Check current character set

mysql> show variables like “collation_database”;
+——————–+——————-+
| Variable_name      | Value             |
+——————–+——————-+
| collation_database | latin1_swedish_ci |
+——————–+——————-+
1 row in set (0.00 sec)

mysql> show variables like “%character%”;show variables like “%collation%”;

+————————–+—————————-+
| 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/ |
+————————–+—————————-+

2. added below variables in my.cnf

[mysqld]
init_connect=’SET collation_connection = utf8_unicode_ci’
init_connect=’SET NAMES utf8′
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

3. Restarted Mysql

4. Check the default character set using below commands

mysql> show variables like “%character%”;show variables like “%collation%”;

+————————–+—————————-+
| 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)

+———————-+—————–+
| Variable_name        | Value           |
+———————-+—————–+
| collation_connection | utf8_unicode_ci |
| collation_database   | utf8_unicode_ci |
| collation_server     | utf8_unicode_ci |
+———————-+—————–+
3 rows in set (0.00 sec)

5. Create database and check the default character set

mysql> SHOW CREATE DATABASE manoj;
+———-+—————————————————————————————-+
| Database | Create Database                                                                        |
+———-+—————————————————————————————-+
| manoj    | CREATE DATABASE `manoj` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */ |
+———-+—————————————————————————————-+
1 row in set (0.00 sec)

Thanks
Manoj

Advertisement
  • MineMine

    thanks a lot

blog comments powered by Disqus