MySQL和UTF-8 [英] MySQL and UTF-8

查看:106
本文介绍了MySQL和UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MySQL中,这样做有什么区别?

In MySQL, what is the difference between doing:

SET NAMES 'utf8'

并且:

SET CHARACTER SET 'utf8'

我看过连接字符集和整理MySQL文档页面,但我还是有点困惑...是否需要同时发出两个命令才能使MySQL UTF-8知道?或设置名称是否足够?

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?

推荐答案

设置名称

SET NAMES指示客户端将使用什么字符集将SQL语句发送到服务器.这意味着SET NAMES 'cp1251'告诉服务器此客户端的将来传入消息位于字符集cp1251中."它还指定服务器用于将结果发送回客户端的字符集.

SET NAMES

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 SETSET NAMES相似,但是将character_set_connectioncollation_connection设置为character_set_databasecollation_database. SET CHARACTER SET x语句等效于以下三个语句:

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;


是否需要同时发出两个命令才能使MySQL UTF-8知道?还是SET NAMES够了?

Do both commands need to be issued in order to make MySQL UTF-8 aware? Or is SET NAMES enough?

设置名称就足够了.

这篇关于MySQL和UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆