Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display query results without table line within mysql shell ( nontabular output )

Tags:

Is it possible to display query results like below within 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.

like image 863
Chawarong Songserm PMP Avatar asked Sep 05 '13 07:09

Chawarong Songserm PMP


People also ask

How do I get output in MySQL?

The Output is located at the bottom of MySQL Workbench. Its select box includes the Action Output , History Output , and Text Output options.

What is %s in MySQL query?

%s can subsitute strings, %d decimals etc.

How check table is empty or not in MySQL?

SELECT * FROM yourTableName WHERE yourSpecificColumnName IS NULL OR yourSpecificColumnName = ' '; The IS NULL constraint can be used whenever the column is empty and the symbol ( ' ') is used when there is empty value.


2 Answers

--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.

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 --silent mysql> SELECT CHAR(92); CHAR(92) \\  % mysql --silent --raw mysql> SELECT CHAR(92); CHAR(92) \ 

From MySQL Docs

like image 196
Vahid Hallaji Avatar answered Oct 07 '22 16:10

Vahid Hallaji


Not exactly what you need, but it might be useful. Add \G at the end of the query

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 
like image 32
edtech Avatar answered Oct 07 '22 14:10

edtech