0
#!bin/bash
Query="update table_name set colume ='i' where column_name is NOT NUll"

mysql -u username -p password mysql  <<EOF
$query;
EOF

The above script is not working

2
  • 1
    What error message do you get when executing the script?
    – Khaled
    May 4, 2015 at 7:47
  • 1
    Query="..." ... $query; Your problem is here... May 4, 2015 at 10:15

2 Answers 2

6

Mysql documentation is pretty clean:

#!bin/bash
query="update table_name set colume ='i' where column_name is NOT NUll"
mysql -u username -p password mysql -e "$query";

-e option allows to send an arbitrary query to the mysql server.

5

The above script is not working because the shell syntax is case-sensitive, and you used Query to define the variable, then query to expand it.

Otherwise, see @Kondybas 's answer for the proper way to do this.

Not the answer you're looking for? Browse other questions tagged or ask your own question.