NeuroLive.NET :: Towards self-reorganizing machine intelligence

13Jan/111

MySQL command via shell script (using variables in SQL)

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"
Print This Post
Comments (1) Trackbacks (0)
  1. 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!


Leave a comment


No trackbacks yet.