I want to execute a .sql file in a bash file but I need to pass parameters to the .sql from the bash file. I think it's a simple solution but I can't figure it out.
This is what I have so far:
.SQL File
SET @columnValue = &1;
UPDATE tblTest SET Description = @columnValue;
Bash File
#!/bin/bash
columnValue=$1
mysql -uroot -ppassword testDB < SQLscript.sql $columnValue
Shell
sh myBashFile.sh "testColumnValue"
Can anyone tell me what i am doing wrong?
You need a combination of setting SQL parameters first and then loading your .sql file.
In your bash script you can use mysql
with the -e
option to execute an SQL statement. The same method must then be used to tell mysql to load the file instead of reading it using bash.
See this example script.
If you only want to execute a single statement, see this question.
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