bash> mysql -u paul -h myhost -pmypass test_paul <<< "SELECT id from a_table where a_name='boo-yah';"
Which means that you can put this in a shell script (or Perl script, or whatever). For example, to print out the addresses associated with a set of names:
for name in `cat names.list`;
do address=`mysql -u paul -h myhost -pmypass test_paul <<< "SELECT address from a_table where a_name='$name';"`; echo "$name -> $address";
done
right!!! and putting in mysql user/pass in a sheel script is a good idea?
ReplyDeleteC'mon, this is just an example. If you were writing a script that you wanted to save you'd write it to accept command line arguments defining the MySQL username/password.
ReplyDeleteThe for loop example was run on the command line and not saved.
Everybody on a Linux system can see everyone's command lines. So, bad idea from a security perspective.
ReplyDeleteStill, thanks for the post! :)
Thanks! Your posting helped me! I had just to make a small few changes:
ReplyDeletemysql --user=USERNAME --password=PASSWORD MYDATABASE -e 'SELECT name FROM friends;'