關於mysql字符集及排序規則設定
How Can I Change the Default Character Set and Collation for a Database in MySQL? (Doc ID 1023320.1)
To determine the default character set and collation for a database, enter this SQL statement:
查詢:
Beginning with MySQL 5.0, you can also obtain this information from the INFORMATION_SCHEMA using a query such as this:
SELECT SCHEMA_NAME,
DEFAULT_CHARACTER_SET_NAME,
DEFAULT_COLLATION_NAME
FROM INFORMATION_SCHEMA.SCHEMATA
WHERE SCHEMA_NAME='database1';
SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
utf8mb4設定:
[client]
default-character-set=utf8mb4
[mysqld]
character-set-server = utf8mb4 ### 伺服器字符集
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4' 設定所有字符集為utf8mb4,即:client、connection、results為utf8(o´ω`o)ノ
skip-character-set-client-handshake = true
[mysql]
default-character-set = utf8mb4
關於排序規則,參考:
What Is The Difference Between utf8mb4_unicode_ci And utf8mb4_general_ci collations? Choose One For Asian Languages With Particular Characters (Doc ID 2230559.1)
* What is the difference between utf8mb4_unicode_ci and utf8mb4_general_ci collations?
These two collations are both for the utf8mb4 character encoding. The differences are in how text is sorted and compared:
1) Accuracy
utf8mb4_unicode_ci is based on the Unicode standard for sorting and comparison, which sorts accurately in a very wide range of languages.
utf8mb4_general_ci fails to implement all of the Unicode sorting rules, which will result in undesirable sorting in some situations, such as when using particular languages or characters.
2) Performance
utf8mb4_general_ci is faster at comparisons and sorting, because it takes a bunch of performance-related shortcuts.
utf8mb4_unicode_ci, which uses the Unicode rules for sorting and comparison, employs a fairly complex algorithm for correct sorting in a wide range of languages and when using a wide range of special characters. These rules need to take into account language-specific conventions; not everybody sorts their characters in what we would call 'alphabetical order'.
On modern servers, this performance consumption will be almost negligible.
* Which one should we use if we store lots of Asian Languages characters?
You should use utf8mb4_unicode_ci.
The reason is:
utf8mb4_unicode_ci provides much more accurate for Asian languages (e.g. Chinese) than utf8mb4_general_ci does. Using utf8mb4_general_ci for Asian languages with particular characters could be inadequate.
Be advised that when migrating from general_ci to unicode_ci, there are some differences in results expected.
General_ci is a simplified set of sorting rules which aims to do as well as it can while taking many short-cuts designed to improve speed. It does not follow the Unicode rules and will result in undesirable sorting or comparison in some situations, such as when using particular languages or characters.
One example is that some characters from Asian languages modifiers like accents can be treated differently in General_ci and Unicode_ci, so when filtering results you should expect different results.
For this specific example and if you want to maintain similar behaviour from general_ci you should consider using utf8mb4_0900_as_ci in MySQL 8.0
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29863023/viewspace-2716846/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【勝通 】mysql字符集與校驗規則的設定MySql
- SQLServer的排序規則(字符集編碼)SQLServer排序
- MySQL中的排序規則MySql排序
- 【MySQL】批次修改排序規則MySql排序
- mysql的字符集校對規則MySql
- MySQL字符集和校對規則(Collation)MySql
- 設定Mysql字符集MySql
- mysql字符集設定MySql
- MySQL 關於Table cache設定MySql
- MySql Order By 多個欄位 排序規則MySql排序
- MySQL字符集和校對規則(character set & collation)MySql
- ORACLE 【字符集正確設定及相關操作】_41Oracle
- 資料庫建庫時字符集和排序規則的選擇資料庫排序
- MySQL索引選擇及規則整理MySql索引
- MySQL字符集概念及設定方法MySql
- mysql字符集檢視與設定MySql
- mysql字符集和字元排序MySql字元排序
- 對於同步的規則定義
- 從根上理解 MySQL 的字符集和比較規則MySql
- SQL Server排序規則SQLServer排序
- SERVER的排序規則Server排序
- 關於OCLint自定義規則
- MySQL:關於排序order by limit值不穩定的說明(1)MySql排序MIT
- MySQL字符集設定及字元轉換(latin1轉utf8)MySql字元
- mysql關於字符集character set的總結MySql
- 【勝通】mysql連線通道中的字符集和校驗規則MySql
- javascript關於toFixed的計算規則JavaScript
- ACCESS 關於表設計中,驗證規則的使用技巧
- 告急:關於檔案的定義格式與命名規則的問題
- 關於laravel使用自定義驗證規則後某些規則不生效Laravel
- 關於Linux字符集的檢視及修改Linux
- mysql 基於規則的執行計劃MySql
- 2021-2-18:請你說說MySQL的字符集與排序規則對開發有哪些影響?MySql排序
- 關於mysql5.6 的排序問題.MySql排序
- List資料多重規則排序排序
- MySQL字符集基本概念和詳細設定MySql
- 檢視和設定MySQL資料庫字符集MySql資料庫
- 關於Oracle,作業系統,客戶端字符集的最佳設定(zt)Oracle作業系統客戶端