久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

MySQL命令行表列寬與utf8

MySQL command-line table column width with utf8(MySQL命令行表列寬與utf8)
本文介紹了MySQL命令行表列寬與utf8的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

為什么 mysql 命令行輸出 utf8 列的寬度是非 utf 列的兩倍?示例:

Why mysql command-line outputs utf8 columns twice as wide compared to non-utf columns? Example:

$ mysql -u user --default-character-set=utf8
mysql> select "αβγαβγαβγαβγαβγαβγαβγ";
+--------------------------------------------+
| αβγαβγαβγαβγαβγαβγαβγ                      |
+--------------------------------------------+
| αβγαβγαβγαβγαβγαβγαβγ                      |
+--------------------------------------------+
1 row in set (0.00 sec)

mysql> select "abcabcabcabcabcabcabc";
+-----------------------+
| abcabcabcabcabcabcabc |
+-----------------------+
| abcabcabcabcabcabcabc |
+-----------------------+
1 row in set (0.00 sec)

如您所見,第一個表格的列寬是第二個表格的兩倍,當行開始超過半個屏幕時,這通常會破壞格式.

As you can see, first table has column twice as wide compared to second table, and this often breaks formatting when lines start to get more than half-screen wide.

我在 MySQL 14.14 和 MariaDB 15.1 上試過這個.

I tried this on MySQL 14.14 and MariaDB 15.1.

有沒有辦法輸出與非utf寬度相同的utf8列?

Is there a way to output utf8 columns with the same width as non-utf?

MariaDB [(none)]> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

推薦答案

mysql.cc 的源代碼(mysql 客戶端的源代碼)的注釋塊中有對函數的解釋get_field_disp_length() 用于結果集輸出的格式化.

In the source code for mysql.cc (the source for the mysql client) there is an explanation in the comment block for function get_field_disp_length() which is used in the formatting of result set output.

返回一個字段被渲染后的長度文本.

Return the length of a field after it would be rendered into text.

這不知道也不關心多字節字符.假設我們是使用這樣的字符集.我們無法知道所有即將到來的行對于此列將有字節,每個字節都呈現為某個分數的一個字符.至少有可能一行的字節數全部渲染為一個字符,因此最大長度為仍然是字節數.(假設 1:這再好不過了因為我們永遠無法知道 DB 的字符數將要發送——只有字節數.2:字符 <= 字節.)

This doesn't know or care about multibyte characters. Assume we're using such a charset. We can't know that all of the upcoming rows for this column will have bytes that each render into some fraction of a character. It's at least possible that a row has bytes that all render into one character each, and so the maximum length is still the number of bytes. (Assumption 1: This can't be better because we can never know the number of characters that the DB is going to send -- only the number of bytes. 2: Chars <= Bytes.)

換句話說,由于UTF8可以存儲每個字符1個字節的字符(如拉丁字符),結果在獲取數據之前無法知道數據是什么,它必須假設任何或所有字符可能是每個字符一個字節.

In other words, since UTF8 can store characters that are 1 byte per character (like Latin characters), and the result can't know what the data is before it fetches it to display, it must assume any or all characters may be one byte per character.

如果您使用的字符集每個字符使用常量 2 個字節,則情況可能會有所不同,例如 UCS-2.但我從未聽說有人使用 UCS-2,因為 MySQL 支持可變長度的 Unicode 編碼.

The story might be different if you used a character set that uses a constant 2 bytes per character, like UCS-2. But I have never heard of anyone using UCS-2, since MySQL supports variable-length Unicode encodings.

這篇關于MySQL命令行表列寬與utf8的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節 [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數據)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
Convert multiple sub-queries to on join(將多個子查詢轉換為 on join)
How do I get the minute difference between 2 times in T SQL?(如何獲得 T SQL 中 2 次之間的微小差異?)
主站蜘蛛池模板: 久久久精品网 | 国产精品视频一二三区 | 亚洲天堂一区二区 | 国产视频精品区 | 欧美久久久久久 | 亚洲一区二区在线电影 | 成人精品一区二区三区中文字幕 | 久久久久资源 | 日韩欧美三区 | 91麻豆精品国产91久久久更新资源速度超快 | 在线免费亚洲视频 | 国产日韩欧美中文 | 免费毛片网站 | 午夜在线小视频 | 午夜精品一区二区三区在线观看 | 91精品国产91久久久久久吃药 | 亚洲视频一区在线观看 | 亚洲欧美精品在线 | av三级 | 国产玖玖 | 精品久久久久久久 | 国产最新视频在线 | 神马影院一区二区三区 | 国产亚洲网站 | 亚洲欧美中文日韩在线v日本 | 久久久精品视频免费看 | 日本不卡一区二区 | 日韩精品一区二区三区视频播放 | heyzo在线 | 久久久91精品国产一区二区精品 | 国产成人免费视频网站高清观看视频 | 99久久婷婷国产亚洲终合精品 | 91看片网址| 欧美一级黄带 | 久久五月婷| 99精品电影 | 国产欧美一区二区三区久久 | 国产91在线播放 | 欧美看片 | 毛片免费看 | 久久91视频|