在 mysql shell 中显示没有表行的查询结果(非表格输出)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18630499/
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
Display query results without table line within mysql shell ( nontabular output )
提问by Chawarong Songserm PMP
Is it possible to display query results like below within mysql shell?
是否可以在 mysql shell 中显示如下查询结果?
mysql> select code, created_at from my_records;
code created_at
1213307927 2013-04-26 09:52:10
8400000000 2013-04-29 23:38:48
8311000001 2013-04-29 23:38:48
3 rows in set (0.00 sec)
instead of
代替
mysql> select code, created_at from my_records;
+------------+---------------------+
| code | created_at |
+------------+---------------------+
| 1213307927 | 2013-04-26 09:52:10 |
| 8400000000 | 2013-04-29 23:38:48 |
| 8311000001 | 2013-04-29 23:38:48 |
+------------+---------------------+
3 rows in set (0.00 sec)
The reason I'm asking because I have some tedious task that I need to copy the output and paste it on other tool.
我问的原因是因为我有一些繁琐的任务,我需要复制输出并将其粘贴到其他工具上。
回答by Vahid Hallaji
--raw, -r
--raw, -r
For tabular output, the “boxing” around columns enables one column value to be distinguished from another. For nontabular output (such as is produced in batch mode or when the --batch or --silent option is given), special characters are escaped in the output so they can be identified easily. Newline, tab, NUL, and backslash are written as \n, \t, \0, and \\. The --raw option disables this character escaping.
对于表格输出,列周围的“装箱”可以将一个列值与另一列值区分开来。对于非表格输出(例如以批处理模式生成或在提供 --batch 或 --silent 选项时),特殊字符会在输出中转义,以便轻松识别。换行符、制表符、NUL 和反斜杠写为 \n、\t、\0 和 \\。--raw 选项禁用此字符转义。
The following example demonstrates tabular versus nontabular output and the use of raw mode to disable escaping:
以下示例演示表格输出与非表格输出以及使用原始模式禁用转义:
% mysql
mysql> SELECT CHAR(92);
+----------+
| CHAR(92) |
+----------+
| \ |
+----------+
% mysql -s
mysql> SELECT CHAR(92);
CHAR(92)
\
% mysql -s -r
mysql> SELECT CHAR(92);
CHAR(92)
\
From MySQL Docs
来自MySQL 文档
回答by edtech
Not exactly what you need, but it might be useful. Add \G at the end of the query
不完全是您需要的,但它可能有用。在查询末尾添加 \G
select code, created_at from my_records\G;
Query result will look like this:
查询结果将如下所示:
*************************** 1. row ***************************
code: 1213307927
created_at: 2013-04-26 09:52:10
*************************** 2. row ***************************
code: 8400000000
created_at: 2013-04-29 23:38:48
回答by kujiy
One-liner
单线
mysql -u YOURUSER -p --password=YOURPASSWORD -s -r -e "show databases;"
mysql -u root -p --password=abc12345 -s -r -e "show databases;"
回答by Chris Stryczynski
You need to pass the -s
parameter mysql -s
.
您需要传递-s
参数mysql -s
。
回答by Andy Fenney
I solved this but using concat_ws to join the results together and then add a space (first argument)
我解决了这个问题,但使用 concat_ws 将结果连接在一起,然后添加一个空格(第一个参数)
select concat_ws (' ',ipNetFull,ipUsage,broadcast,gateway) from ipNets;
回答by JTW
If you want to get MySQL client output without the surrounding table, you can run your query from the linux command line instead of through the mysql client:
如果你想在没有周围表的情况下获得 MySQL 客户端输出,你可以从 linux 命令行而不是通过 mysql 客户端运行你的查询:
$ echo "SELECT CONCAT_WS(' ','DROP TABLE',TABLE_NAME,';') FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '%';" | mysql dbname
bonus: you can pipe the output through sort and stuff, or even back into mysql:
奖励:您可以通过 sort 和内容管道输出,甚至可以返回到 mysql:
$ echo "SELECT CONCAT_WS(' ','DROP TABLE',CONCAT_WS('.',TABLE_SCHEMA,TABLE_NAME),';') FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'i\'m\_not\_that\_mean';" | mysql | mysql;
回答by Dennis Akwensioge
So confused by the question and answers. ran sql and result kept displaying without lines or non tabular format. Later realized there is an option when you right click on the query space, navigate to "results to" > "results to grid". This Should set it back to tabular format.
被问题和答案弄糊涂了。运行 sql 并且结果保持显示,没有行或非表格格式。后来意识到当您右键单击查询空间时有一个选项,导航到“结果到”>“结果到网格”。这应该将其设置回表格格式。
There is also an option for "results to text" which was the format I was experiencing.
还有一个“结果到文本”的选项,这是我遇到的格式。
:)!
:)!