MySQL 如何调整mysql命令行的显示设置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4285664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to adjust display settings of mysql command line?
提问by XCeptable
Command Line of mysql is not displaying results properly. I mean some columns of table are in 1st line some in 2nd line. Output is also broken into two rows. How do I adjust these settings so that it properly display results.
mysql 的命令行未正确显示结果。我的意思是表格的某些列在第一行,有些在第二行。输出也分为两行。如何调整这些设置以使其正确显示结果。
回答by Buhake Sindi
You can use the \G
command (instead of the ;
) at the end of your SQL queries...
您可以在 SQL 查询的末尾使用\G
命令(而不是;
)...
Example:
例子:
SELECT * FROM USER \G
It will display your table in row form instead of column form.
它将以行形式而不是列形式显示您的表格。
回答by Jinesh Parekh
mostly this happens when the row it fetches is too long. try playing with your terminal to have scroll bar and you could even reduce fonts.
大多数情况下,当它获取的行太长时会发生这种情况。尝试使用您的终端播放滚动条,您甚至可以减少字体。
The mysql option is
mysql 选项是
mysql> pager less -n -i -S
回答by SilverSurfer972
To set the scrolling automatically add this to your my.cnf file in the [client] section like this:
要自动设置滚动,请将其添加到 [client] 部分中的 my.cnf 文件中,如下所示:
[client]
pager = less -n -i -S
回答by cam clarke
In Microsoft Windows mysql Command Prompt, Right-click on the prompt boarder and select Properties, now select the Layout tab and change the Window Size width or screen buffer width to a more suitable view. That should fix the problem.
在 Microsoft Windows mysql 命令提示符中,右键单击提示边框并选择属性,现在选择布局选项卡并将窗口大小宽度或屏幕缓冲区宽度更改为更合适的视图。那应该可以解决问题。
回答by user7412956
Another option, which I was looking for and finally found, is the MySQL string function LEFT()
.
我一直在寻找并最终找到的另一个选项是 MySQL 字符串函数LEFT()
。
LEFT(
str
,
len
)
Returns the leftmost lencharacters from the string str, or NULLif any argument is NULL.
LEFT(
str
,
len
)
返回最左边的len个从字符串中的字符STR,或NULL如果任何参数是NULL。
For example ...
例如 ...
mysql> SELECT
-> `bib`,
-> `name_id` AS `Print`,
-> `code`,
-> `name_en` AS `EN`,
-> `name_fr` AS `FR`,
-> `name_de` AS `DE`,
-> `Id`
-> FROM `iso639_Language`
-> WHERE `Id` LIKE 'in%'
-> ORDER BY `bib`;
+-----+------------------------------------------------------------+------+------------------------------------------------------------+------------------------------------------------+------------------+-----+
| bib | Print | code | EN | FR | DE | Id |
+-----+------------------------------------------------------------+------+------------------------------------------------------------+------------------------------------------------+------------------+-----+
| ina | Interlingua (International Auxiliary Language Association) | ia | Interlingua (International Auxiliary Language Association) | interlingua (langue auxiliaire internationale) | Interlingua | ina |
| ind | Indonesian | id | Indonesian | indonésien | Bahasa Indonesia | ind |
| inh | Ingush | NULL | Ingush | ingouche | Inguschisch | inh |
+-----+------------------------------------------------------------+------+------------------------------------------------------------+------------------------------------------------+------------------+-----+
3 rows in set (0.01 sec)
... becomes ...
……变成……
mysql> SELECT
-> `bib`,
-> LEFT(`name_id`,15) AS `Print`,
-> `code`,
-> LEFT(`name_en`,10) AS `EN`,
-> LEFT(`name_fr`,10) AS `FR`,
-> LEFT(`name_de`,10) AS `DE`,
-> `Id`
-> FROM `iso639_Language`
-> WHERE `Id` LIKE 'in%'
-> ORDER BY `bib`;
+-----+-----------------+------+------------+-------------+------------+-----+
| bib | Print | code | EN | FR | DE | Id |
+-----+-----------------+------+------------+-------------+------------+-----+
| ina | Interlingua (In | ia | Interlingu | interlingu | Interlingu | ina |
| ind | Indonesian | id | Indonesian | indonésien | Bahasa Ind | ind |
| inh | Ingush | NULL | Ingush | ingouche | Inguschisc | inh |
+-----+-----------------+------+------------+-------------+------------+-----+
3 rows in set (0.00 sec)
I do like the \G
and pager less -Sin
options, and use them. Often, however, I need the results in a normal fashion. With the pager option I loose the ability to reference, visually, the previous results, as the output is displayed by the selected program, externally to MySQL, and is no longer displayed when that program is closed. With the \G
option I can easily compare the data of each record as a whole, but comparing records, such as viewing the column looking for patterns, or discrepancies, is not so easy.
我喜欢\G
和pager less -Sin
选项,并使用它们。然而,我经常需要以正常方式获得结果。使用 pager 选项,我失去了在视觉上引用先前结果的能力,因为输出由选定的程序显示,在 MySQL 外部,并且在该程序关闭时不再显示。使用该\G
选项,我可以轻松地将每条记录的数据作为一个整体进行比较,但是比较记录(例如查看列以查找模式或差异)并不是那么容易。
What I used to do was remove some of the columns until the results fit in the window, and rerun the queries with other columns removed, and developed a "view" of the table in my mind. (Not a good place to keep tables.) I seldom need to view the entire column, however, when using MySQL in the terminal, and selectively reducing an excessively long column from a query can be done by editing the last command to insert LEFT()
around the offending column, and I'm back to doing what I needed to do, with little distraction or lost time.
我以前做的是删除一些列,直到结果适合窗口,然后在删除其他列的情况下重新运行查询,并在我的脑海中形成一个表的“视图”。(不是保存表格的好地方。)我很少需要查看整个列,但是,在终端中使用 MySQL 时,可以通过编辑最后一个命令插入LEFT()
到冒犯性的专栏,我又回到了做我需要做的事情上,几乎没有分心或浪费时间。