MySQL為什么要set names

大家都知道
SET NAMES x
相當于
SET character_set_client = x;
SET character_set_results = x;
SET character_set_connection = x;

以下從MySQL5.0官方文檔上摘錄了相關內容,并翻譯,說明了相關系統變量的用處:

What character set is the statement in when it leaves the client?
statement離開客戶端的時候是什么字符集?

The server takes the character_set_client system variable to be the character set in which statements are sent by the client.
客戶端送過來的statement,服務器認為它的字符集是系統變量character_set_client的值。

What character set should the server translate a statement to after receiving it?
服務器收到一個statement后,會把它轉換成什么字符集?

For this, the server uses the character_set_connection and collation_connection system variables. It converts statements sent by the client from character_set_client to character_set_connection (except for string literals that have an introducer such as _latin1 or _utf8). collation_connection is important for comparisons of literal strings. For comparisons of strings with column values, collation_connection does not matter because columns have their own collation, which has a higher collation precedence.
為了這一用途,服務器使用系統變量character_set_connection和collation_connection。它把客戶端傳來的statement,從character_set_client字符集轉換成character_set_connection字符集(除非字符串中有類似_latin1或者_utf8的字符集聲明)。collation_connection對于字符串的比較是非常重要的。對于字符類型的字段值的比較,collation_connection是不起作用的。因為字段有自己的collation,有更高的優先級。

What character set should the server translate to before shipping result sets or error messages back to the client?
在結果集由服務器傳遞給客戶端之前,需要轉換成什么字符集?

The character_set_results system variable indicates the character set in which the server returns query results to the client. This includes result data such as column values, and result metadata such as column names.
character_set_results系統變量表明了服務器返回查詢結果時使用的字符集。返回的數據,有比如字段的值和元數據(例如字段名)。

If you are using the mysql client with auto-reconnect enabled (which is not recommended), it is preferable to use the charset command rather than SET NAMES. For example:
如果你使用mysql客戶端的自動重連(不推薦使用),最好用charset命令,而不是SET NAMES。例如:

mysql> charset utf8
Charset changed

The charset command issues a SET NAMES statement, and also changes the default character set that is used if mysql reconnects after the connection has dropped.
charset命令發出了一個SET NAMES語句,并且連接斷開后自動重連時使用的缺省字符集也被修改了。

The database character set and collation are used as default values if the table character set and collation are not specified in CREATE TABLE statements. They have no other purpose.
如果CREATE TABLE中沒有明確指出字符集和collation,那么database字符集和collation將做為缺省值,它們沒有其他的用處。

The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables. The server sets these variables whenever the default database changes. If there is no default database, the variables have the same value as the corresponding server-level system variables, character_set_server and collation_server.
缺省database的字符集和collation可以通過系統變量character_set_database和collation_database查看。服務器當缺省database改變時設置這些變量的值。如果沒有缺省的database,這些變量的將與對應的服務器級的系統變量-character_set_server和collation_server的值相同。

The table character set and collation are used as default values if the column character set and collation are not specified in individual column definitions. The table character set and collation are MySQL extensions; there are no such things in standard SQL.
表的字符集和collation會作為缺省值,如果列的定義中沒有指明字符集和collation的話。

Every “character” column (that is, a column of type CHAR, VARCHAR, or TEXT) has a column character set and a column collation.
每個“字符”字段(即CHAR、VARCHAR或者TEXT類型的字段)都有一個字段字符集和字段校驗(collation)。

Every character string literal has a character set and a collation.
每個字符串有一個字符集和一個較驗。

A character string literal may have an optional character set introducer and COLLATE clause:
每個字符串有一個可選的字符集introducer和COLLATE子句:

[_charset_name]'string' [COLLATE collation_name]

Examples:

SELECT 'string';
SELECT _latin1'string';
SELECT _latin1'string' COLLATE latin1_danish_ci;?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/535707.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/535707.shtml
英文地址,請注明出處:http://en.pswp.cn/news/535707.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

MySql日期處理系列-常用的日期推算處理

以下都是我平時用的一些日期推算處理方法,方法并不一定是最有效率的.全部均通過測試!轉載請注明來自[phpchina.com] #title: 常用的日期推算處理#auther: 小強(占卜師) #date: 2007-12-25 #取得當前日期set dtCURDATE();select dt; #當前日期這個月的第一天selec…

Java集合:Set集合

一、Set接口的特點 一個不包含重復元素的collection。更確切地講,Set不包含滿足e1.equals(e2)的元素對 e1和e2,并且最多包含一個null元素。 Set集合由Set接口和Set接口的實現類組成,Set接口繼承了Collection接口,因此包含了Coll…

談談我對MYSQL亂碼的解決辦法

經常更換虛擬主機,而各個服務商的MYSQL版本不同,當導入數據后,總會出現亂碼等無法正常顯示的問題,查了好多資料,總結出自己的一點技巧: WINDOWS 下導入應該這樣使用MYSQL的命令在DOS命令下進入mysql的bin目錄下,輸入mysql -uroot -p密碼 數據庫名稱<要恢復的數據庫, 例如我們…

Java集合:Map集合

一、簡述 public interface Map<K,V>將鍵映射到值的對象。一個映射不能包含重復的鍵&#xff1b;每個鍵最多只能映射到一個值。 注意&#xff1a;Map中的集合不能包含重復的鍵&#xff0c;值可以重復。每個鍵只能對應一個值。 Map集合是鍵值對形式存儲值的&#xff0c…

用離線編輯器Zoundry寫zblog日志

Zoundry是免費的離線網志發布工具&#xff0c;由于家里的網絡很差&#xff0c;寫了一半的日志經常因為掉線而丟失&#xff0c;這樣一款軟件的確是很必要的。今天下載試用了一下&#xff0c;感覺的確不錯。使用起來也很簡單&#xff1a; 1.下載并安裝zoundry軟件&#xff1a;現…

MySQL:基本命令

一、數據庫操作 1、查詢數據庫&#xff0c;命令如下: SHOW DATABASES;2、我們可以在登陸 MySQL 服務后&#xff0c;使用 create 命令創建數據庫&#xff0c;命令格式: CREATE DATABASE 數據庫名;3、使用 drop 命令刪除數據庫&#xff0c;命令格式&#xff1a; drop databas…

CentOS 5打造全功能Web服務器

轉&#xff1a;主要做為歷史記錄&#xff0c;以后用。另外很少見這么好的編譯的文章&#xff0c;其實我不推薦用編譯安裝。但這個文章不錯.V3.0 2007年11月11日 將搭建教程劃分階段以適應不同需要。加入程序優化&#xff0c;程序安全&#xff0c;加入memcache&#xff0c;squid…

MySQL:查詢條件

查詢條件 1、使用 WHERE 子句從數據表中讀取數據的通用語法&#xff1a; SELECT field1, field2,...fieldN FROM table_name1, table_name2... [WHERE condition1 [AND [OR]] condition2.....查詢語句中你可以使用一個或者多個表&#xff0c;表之間使用逗號**,** 分割&#x…

linux下的ImageMagick安裝

檢查系統有無安裝ImageMagick官方網址是&#xff1a; www.imagemagick.org 從官方不好下載&#xff0c;提供 sourceforge的下載地址&#xff1a; imagemagick.sourceforge.net shell> rpm -qa | grep ImageMagick 沒有就開始安裝ImageMagickshell> rpm -Uvh ImageMagi…

MySQL:進階應用

一、進階應用 1、可以在 SELECT, UPDATE 和 DELETE 語句中使用 Mysql 的 JOIN 來聯合多表查詢。 JOIN 按照功能大致分為如下三類&#xff1a; INNER JOIN&#xff08;內連接,或等值連接&#xff09;&#xff1a;獲取兩個表中字段匹配關系的記錄。**LEFT JOIN&#xff08;左連…

Hive-常用操作

一. 數據庫操作 1、創建數據庫 //用戶可以用 IF NOT EXISTS 選項來忽略這個異常。create database [ if not exists ] myhive ;2、創建數據庫并指定hdfs存儲位置 create database myhive2 location /myhive2;3、修改數據庫&#xff0c;可以使用alter database 命令來修改數據…

linux下nmap工具的使用

nmap NMap&#xff0c;也就是Network Mapper&#xff0c;是Linux下的網絡掃描和嗅探工 具包&#xff0c;其基本功能有三個&#xff0c;一是探測一組主機是否在線&#xff1b;其次是掃描主機端口&#xff0c;嗅探所提供的網絡服務&#xff1b;還可以推斷主機所用的操作系統 。N…

Hive-分區分桶概述

一、分區 簡介 為了對表進行合理的管理以及提高查詢效率&#xff0c;Hive可以將表組織成“分區”。 分區是表的部分列的集合&#xff0c;可以為頻繁使用的數據建立分區&#xff0c;這樣查找分區中的數據時就不需要掃描全表&#xff0c;這對于提高查找效率很有幫助。 分區是…

定時提醒你休息的腳本

本文來源于阿里西西WEB開發社區http://www.alixixi.com收集整理&#xff0c;歡迎訪問。 定時彈窗提醒功能腳本..把以下代碼存為.vbs運行即可. 以下是引用片段&#xff1a;set WshShell WScript.CreateObject("WScript.Shell") ’對話框標題 alerttitle "你的…

Hive-分區分桶操作

在大數據中&#xff0c;最常用的一種思想就是分治&#xff0c;我們可以把大的文件切割劃分成一個個的小的文件&#xff0c;這樣每次操作一個小的文件就會很容易了&#xff0c;同樣的道理&#xff0c;在hive當中也是支持這種思想的&#xff0c;就是我們可以把大的數據&#xff0…

ubuntu好文收集

ubuntu全程配置手冊 http://ljlau.blogdriver.com/ljlau/1220277.html ubuntu下向系統日志寫記錄 http://linux0818.bokee.com/viewdiary.14153197.html aptitude 使用快速參考 http://linuxtoy.org/archives/aptitude_quick_reference.html

Flume簡單介紹

在一個完整的離線大數據處理系統中&#xff0c;除了HDFSMapReduceHive組成分析系統的核心之外&#xff0c;還需要數據采集、結果數據導出、任務調度等不可或缺的輔助系統&#xff0c;而這些輔助工具在hadoop生態體系中都有便捷的開源框架&#xff0c;在此&#xff0c;我們首先來…

linux系統優化篇之---top

top命令是Linux下常用的性能分析工具&#xff0c;能夠實時顯示系統中各個進程的資源占用狀況&#xff0c;類似于Windows的任務管理器。下面詳細介紹它的使用方法。 top - 01:06:48 up 1:22, 1 user, load average: 0.06, 0.60, 0.48Tasks: 29 total, 1 running, 28 sleeping, …

Flume安裝部署

1.安裝部署 1、解壓tar -zxvf apache-flume-1.9.0-bin.tar.gz 2、改名mv apache-flume-1.9.0-bin flume-1.9.0 3、配置環境變量 vi /etc/profile,source /etc/profile #flume export FLUME_HOME/usr/local/apps/flume-1.9.0 export PATH$PATH:$FLUME_HOME/bin4、將conf下的…

ubuntu學習摘要-ubuntu root用戶

在我安裝好后root的密碼是什么&#xff1f;我怎樣使用root帳號&#xff1f; 當你第一次安裝好Ubuntu后&#xff0c;root帳號不能用。在安裝期間創建的第一個用戶對系統有管理權&#xff0c;通過“sudo”能象root運行程序.使用時僅需它的普通用戶密碼。例如: sudo apt-get updat…