Tuesday, September 13, 2011

How to run mysql from Linux command line

Following code connects to MySql server and show all databases in mysql with column delimited by tab
mysql -hHOST -uUSER -pPASSWORD -e "show databases" -N -s
-N means do *not* display the column names
-s option means display raw data with no formatting
To run multiple commands, delimit them by semicolon.
To read command from a file run
mysql -hHOST -uUSER -pPASSWORD < batch-fileor
mysql -hHOST -uUSER -pPASSWORD-e "source batch-file"

No comments:

Post a Comment