Currently we are using the following commands in PHP to set the character set to UTF-8 in our application.
Since this is a bit of overhead, we'd like to set this as the default setting in MySQL. Can we do this in /etc/my.cnf or in another location?
SET NAMES 'utf8'
SET CHARACTER SET utf8
I've looked for a default charset in /etc/my.cnf, but there's nothing there about charsets.
At this point, I did the following to set the MySQL charset and collation variables to UTF-8:
skip-character-set-client-handshake
character_set_client=utf8
character_set_server=utf8
Is that a correct way to handle this?
Change MySQL character:
Client
mysqld
We should not write
default-character-set=utf8
in mysqld, because that could result in an error like:At last:
If you are confused by your setting for client and conn is reseted after restart mysql service. Try these steps (which worked for me):
vi /etc/my.cnf
:wq [client] character-sets-dir=/usr/local/mysql/share/mysql/charsets
status;
, you'll find the character-set for 'client' and 'conn' is set to 'utf8'.Check the reference for more info.
For the recent version of MySQL,
causes a problem. It's deprecated I think.
As Justin Ball says in "Upgrade to MySQL 5.5.12 and now MySQL won’t start, you should:
Remove that directive and you should be good.
Then your configuration file ('/etc/my.cnf' for example) should look like that:
Restart MySQL.
For making sure, your MySQL is UTF-8, run the following queries in your MySQL prompt:
First query:
The output should look like:
Second query:
And the query output is:
I also have found out that after setting
default-character-set = utf8
under[mysqld]
title, MySQL 5.5.x would not start under Ubuntu 12.04 (Precise Pangolin).Note: my.cnf file is located at
/etc/mysql/
After adding these lines:
Don't forget to restart server:
MySQL 5.5, all you need is:
collation_server
is optional.