久久久久久久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 次之間的微小差異?)
主站蜘蛛池模板: 国产亚洲一区二区三区在线观看 | 国产一区二区影院 | 性国产丰满麻豆videosex | 欧美久久久久久 | 中文字幕 欧美 日韩 | 免费在线观看黄网站 | 国产亚洲精品a | 国产精品视频久久久 | 国产精品视频在线播放 | 国产精品明星裸体写真集 | 一区二区三区 在线 | 老司机午夜性大片 | 日日做夜夜爽毛片麻豆 | 日韩欧美在线一区 | 在线日韩| 女同av亚洲女人天堂 | 国产一区免费视频 | 欧美二区在线 | 国产在线精品一区二区 | 一级aaaaaa毛片免费同男同女 | 国产视频三级 | 欧美福利三区 | 欧美激情在线精品一区二区三区 | 高清国产一区二区 | 99色综合 | 99免费看 | 日韩精品久久久 | 中文av在线播放 | 国产精品久久亚洲 | 在线观看免费av网站 | 一区二区三区av | 久久一区二区av | 日本在线一二 | 欧美国产精品一区二区三区 | 久久99精品国产麻豆婷婷 | 久久久精品久久 | 欧美一级全黄 | 日本xx视频免费观看 | 国产精品一区二区三区四区五区 | 亚洲视频中文字幕 | 韩日视频在线观看 |