I need a variable to hold results retrieved from the database. So far this is basically what I'm trying with no success.
myvariable=$(mysql database -u $user -p $password | SELECT A, B, C FROM table_a)
My understanding of bash commands is not very good as you can see.
Running select queries After you have logged into a database with the MySQL command line tool (covered in my using the MySQL command line tool post), you can run queries by simply typing them in at the command prompt. The query will not be executed until you either enter ; g or G and then press the <enter> key.
A more direct way would be:
myvar=$(mysql mydatabase -u $user -p$password -se "SELECT a, b, c FROM table_a")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With