久久久久久久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 次之間的微小差異?)
主站蜘蛛池模板: 亚洲成人国产精品 | 在线国产一区 | 婷婷成人在线 | 精品久久久久久久久久久久久久 | 中文字幕99 | 久久精品国产久精国产 | 成人免费视频网站在线看 | 欧美高清视频在线观看 | 一区二区三区视频免费看 | 91久久精品国产91久久性色tv | 久久成人高清视频 | 羞羞视频免费在线观看 | 成人免费观看视频 | 毛片免费看的 | 久草视频网站 | 午夜三级网站 | 福利视频网址 | 久久91 | 免费在线一区二区三区 | 色爽女 | a级片网站 | 欧美视频偷拍 | 91社区在线观看 | 久久99精品久久久久久噜噜 | 91麻豆精品一区二区三区 | 国产高清精品一区 | 范冰冰一级做a爰片久久毛片 | 国产欧美一区二区三区另类精品 | 久久久久久99 | 久草综合在线 | 国产专区视频 | 欧美日韩国产不卡 | 亚洲一级av毛片 | 日日干夜夜操 | 日韩一区av | 久久鲁视频 | 中文字幕一区二区三区四区 | 精品国产精品三级精品av网址 | 伊人色综合久久久天天蜜桃 | 日韩午夜影院 | 狠狠做深爱婷婷综合一区 |