Hebben we net als de optie --disable-column-names
een optie om de SQL-query op te halen zonder het tabelformaat? Bijvoorbeeld:
mysql -u username -p password --disable-column-names --execute "select name from test"
resultaten hieronder:
-----
| A |
| B |
| C |
| D |
-----
Is het mogelijk om het zoekresultaat te krijgen met behulp van sommige sql-programmaoptie-modifiers zoals hieronder, zonder het tabelformaat?
Ik wil dit:
A
B
C
D
Antwoord 1, autoriteit 100%
Voeg de vlag -B
toe aan mysql
.
mysql -B -u username -ppassword \
--disable-column-names \
--execute "select name from mydb.test"
-B, --batch: Print results in nontabular output format.
--execute: Execute the statement and quit.
Merk op dat -B
/--batch
ook de schakelaar --silent
inschakelt.
Antwoord 2, autoriteit 29%
Hoewel de andere antwoorden incidenteel werken, is de juiste schakelaar eigenlijk -s
wat een afkorting is voor --silent
.
Misschien wilt u aanvullend -r
specificeren voor --raw
-uitvoer, waardoor ook het ontsnappen van tekens wordt uitgeschakeld, anders worden nieuwe regel, tab, null-teken en backslash weergegeven als \n, \t, \0 en \ respectievelijk.
· --silent, -s Silent mode. Produce less output. This option can be given multiple times to produce less and less output. This option results in nontabular output format and escaping of special characters. Escaping may be disabled by using raw mode; see the description for the --raw option. · --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 -s mysql> SELECT CHAR(92); CHAR(92) \\ % mysql -s -r mysql> SELECT CHAR(92); CHAR(92) \
– Oracle Corporation
MySQL 5.7 06/07/2018