- NeuroLive.NET - http://blog.neurolive.net -
MySQL command via shell script (using variables in SQL)
Posted By bigmoshi On January 13, 2011 @ 9:33 am In ยป Machine Intelligence | 1 Comment
Running mysql commands on the shell is pretty simple. However, things can get tricky if you need to enclose variables within those aprostophes in your script. Spend some time trying to figure this out.
The short sample code below shows how it can be done. Note the cats on "`echo $1`". Hope this helps you as well.
1 2 3 4 5 6 7 8 9 10 11 | #!/bin/bash mysql_user="root" mysql_pass="root" do_mysql() { mysql -u $mysql_user -p$mysql_pass -e "`echo $1`" } dbname="neurodb" do_mysql "drop database $dbname; \g" |
Article printed from NeuroLive.NET: http://blog.neurolive.net
URL to article: http://blog.neurolive.net/2011/01/mysql-command-via-shell-script-using-variables-in-sql/
Click here to print.
Copyright © 2009 Neuro Live. All rights reserved.
1 Comment To "MySQL command via shell script (using variables in SQL)"
#1 Comment By Aba On January 25, 2011 @ 11:23 am
Beneficial info and excellent design you got here! I want to thank you for sharing your ideas and putting the time into the stuff you publish! Great work!