How to set character encoding UTF8 in Mysql

Posted By : Raman Joshi | 18-Jun-2015

In this blog we are going to understand that how we can support other languages in our Mysql DB. We have to set character encoding UTF-8 in Mysql config file.
So First of all we need to find and edit mysql config file which is my.cnf and in the /etc/mysql directory in many cases. You can edit it and add below lines

 [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
 

And then restart the Mysql server with below command.

sudo /etc/init.d/mysql stop  
sudo /etc/init.d/mysql start 
 

Now after configuration you can check this character encoding setup with the below commands.

 show variables like “collation_database”;  
   
+--------------------+-----------------+  
| Variable_name      | Value           |  
+--------------------+-----------------+  
| collation_database | utf8_unicode_ci |  
+--------------------+-----------------+  
  
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.12 sec)  
  
+----------------------+-----------------+  
| Variable_name        | Value           |  
+----------------------+-----------------+  
| collation_connection | utf8_general_ci |  
| collation_database   | utf8_unicode_ci |  
| collation_server     | utf8_unicode_ci |  
+----------------------+-----------------+  
3 rows in set (0.00 sec)  
 

Thanks
 

 

About Author

Author Image
Raman Joshi

Raman is a bright web app developer with experience in Java , Groovy and Grails frameworks

Request for Proposal

Name is required

Comment is required

Sending message..