0

When I run a mysql query at the command line, the output is encapsulated with hyphens, or bars and plus signs...

mysql -h myhost -u me -pmypw -N thedb -e "select 1 from table1"

I get...

+---+
| 1 |
+---+

How can I get rid of the hyphens, or bars and plus signs ?

Thanks !

Bonus points if you can tell me how to escape backticks in the command as they are needed to specify a column name that someone decided to name with a reserve word...

mysql -h myhost -u me -pmypw -N thedb -e "select `trigger` from table1"

I tried \ and `` and '`' and whatever else I could think of. No luck.

I got around this (sort of) by creating a view of the table that used a non-reserve word in place of 'trigger'

daveg
  • 1,051
  • 11
  • 24
  • 2
    For the first question, will this help? https://stackoverflow.com/questions/15640287/change-output-format-for-mysql-command-line-results-to-csv – Matt Runion Sep 13 '18 at 20:49
  • 1
    For the second, show how you used the backslash to escape the character. But remember that simply putting "\`" inside the string will not work -- you also have to escape the backslash. Try "...\\\`..." inside the string. So: mysql -h myhost ...... "SELECT \\\`trigger\\\` FROM table1" – Matt Runion Sep 13 '18 at 20:52
  • % mysql -h myhost -u me_rw -pmypw -N -B mydb -e "select * from try" abc % mysql -h myhost -u me -pmypw -N -B mydb -e "select `trigger` from try" trigger: Command not found. ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual (blah, blah) % mysql -h myhost -u me -pmypw -N -B mydb -e "select \\`trigger\\` from try" trigger\: Command not found. ERROR at line 1: Unknown command '\\'. – daveg Sep 13 '18 at 21:17
  • 1
    The -B worked great BTW, thanks ! – daveg Sep 13 '18 at 21:18

0 Answers0