Showing posts with label switches. Show all posts
Showing posts with label switches. Show all posts

Friday, February 14, 2014

How to format the output of mysql in command line

Use of switches in command line

Here are some interesting switches that can be helpful..

-N removes header
-s removes separator chars
-r raw output

exemple

if you need to get the result of a count(*)

mysql -uusername -ppassword -N -s -r -e 'select count(*) from user'  

if you get the ERROR : 2003 you may need to add more options like the port number and the socket

mysql --port=$MYSQL_PORT --socket=$MYSQL_SOCKET -uroot -p -Dmysql -h localhost -N -s -r -e 'select count(*) from user'