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
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Raman Joshi
Raman is a bright web app developer with experience in Java , Groovy and Grails frameworks