關於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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SQLServer的排序規則(字符集編碼)SQLServer排序
- 【MySQL】批次修改排序規則MySql排序
- MySQL字符集和校對規則(character set & collation)MySql
- MySQL 關於Table cache設定MySql
- mysql字符集和字元排序MySql字元排序
- 資料庫建庫時字符集和排序規則的選擇資料庫排序
- 從根上理解 MySQL 的字符集和比較規則MySql
- 字符集和比較規則
- MySQL索引選擇及規則整理MySql索引
- mysql關於字符集character set的總結MySql
- 2021-2-18:請你說說MySQL的字符集與排序規則對開發有哪些影響?MySql排序
- 對於同步的規則定義
- MySQL:關於排序order by limit值不穩定的說明(1)MySql排序MIT
- ACCESS 關於表設計中,驗證規則的使用技巧
- javascript關於toFixed的計算規則JavaScript
- 關於laravel使用自定義驗證規則後某些規則不生效Laravel
- MySQL 字符集與亂碼與collation設定的問題?MySql
- Mysql之儲存引擎及字符集MySql儲存引擎
- 為Zabbix MySQL修改字符集排序utf8_binMySql排序
- 在Linux中,如何設定防火牆規則?Linux防火牆
- CI4路由設定規則路由
- 2.2.2 關於字符集選擇
- MySQL 不同版本預設字符集MySql
- 關於 MySQL 時區設定的一個常用 sql 命令MySql
- PostgreSQL 字符集烏龍導致資料查詢排序的問題,與 MySQL 穩定 "PG不穩定"排序MySql
- 關於mysql查詢字符集不匹配問題的解決方法MySql
- MySQL運維實戰(5.6) 字符集設定對mysqldump的影響MySql運維
- linux mysql5.7以上設定中文字符集不在/mysql/my.cnf下面了LinuxMySql
- linux系統中檢視己設定iptables規則Linux
- Mysql-基本的規則與規範MySql
- MySQL字符集MySql
- MySQL修改表預設字符集行為MySql
- MySQL 檢視與修改預設字符集MySql
- Linux字符集環境變數設定Linux變數
- css中關於table的相關設定CSS
- 最佳化配置Little Snitch for Mac的規則和設定Mac
- nginx location匹配及rewrite規則Nginx
- 關於MySql 設定一個間隔時間 執行一個事件MySql事件