Webhosting Blog

Changing default charset in mysql


In order to change the default character set in mysql follow following steps:

1) Login to the server as root .

2) Open the file /etc/my.cnf

[root@server~]# vi /etc/my.cnf

3)Add the following lines below [client] section:

default-character-set=utf8

4) Add the following lines below [mysqld] section:

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

5) Once done restart your mysql service.

[root@server~]# service mysql restart

6) Now check with the following command:

[root@server~]#  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

7) You can find the default charset set to utf8.

Advertisements

One response

  1. Great Post! Thanks for giving detailed description about blog.

    August 11, 2011 at 5:21 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s