Mysql Client Fun!

email-addthis printer-addthis favorites-addthis facebook-addthis digg-addthis | Share

06 Nov 2008 12:46:57
Category: Bash Programming

Here's some tips on running queries from commandline with the mysql client with out a prompt. FYI, All this assumes you are running Linux

Method number one. Run a query that is sitting in a file.

mysql -u[username] -p['password'] -h[your-database-host] < THE_FILE_WITH_SQL_IN_IT

Method number two: Run a query at the commandline.

mysql -u[username] -p[password] -e"SELECT NOW()"

Method number three: Run a query at the commandline in a more different way.

cat<<<"SELECT NOW()" | mysql -u[username] -p[password]