Reputation: 154673
In MySQL, what is the difference between doing:
SET NAMES 'utf8'
And:
SET CHARACTER SET 'utf8'
I've taken a look at Connection Character Sets and Collations MySQL documentation page but I'm still a bit confused... Do both commands need to be issued in order to make MySQL UTF-8 aware? Or is SET NAMES enough?
Upvotes: 4
Views: 703
Reputation: 332731
SET NAMES
indicates what character set the client will use to send SQL statements to the server. That means that SET NAMES 'cp1251'
tells the server “future incoming messages from this client are in character set cp1251.” It also specifies the character set that the server should use for sending results back to the client.
SET CHARACTER SET
is similar to SET NAMES
, but sets character_set_connection
and collation_connection
to character_set_database
and collation_database
. A SET CHARACTER SET x
statement is equivalent to these three statements:
SET character_set_client = x;
SET character_set_results = x;
SET collation_connection = @@collation_database;
Do both commands need to be issued in order to make MySQL UTF-8 aware? Or is SET NAMES enough?
SET NAMES is enough.
Upvotes: 3
Reputation:
SET NAMES has encoding for connection, and SET CHARACTER SET is encoding for table. Using both command is highly recomment, to avoid terrible charter problems...
Upvotes: 0