jen_jen_jen
asked on
How to write a shell script for mysql?
I want to write a shell script for a unix-based system that will run a number of mysql commands:
mysql table < a.sql -u admin ...
mysql table < b.sql -u admin ...
mysql table < c.sql -u admin ...
mysql table < d.sql -u admin ...
mysql table < e.sql -u admin ...
I've really never done shell scripting before... How would I go about doing this?
mysql table < a.sql -u admin ...
mysql table < b.sql -u admin ...
mysql table < c.sql -u admin ...
mysql table < d.sql -u admin ...
mysql table < e.sql -u admin ...
I've really never done shell scripting before... How would I go about doing this?
ASKER
I tried that, but I get a bunch of ??? in the files and it says it can't read them?
ASKER
I changed it to this:
#!/bin/sh
CURDIR="/tmp/"
for file in $CURDIR;
do
mysql database < ${file} -u admin ...
done
But, now I'm getting a sql error on a valid sql file:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??' at line 1
Do I need to remove the commented lines in the sql files or something?
#!/bin/sh
CURDIR="/tmp/"
for file in $CURDIR;
do
mysql database < ${file} -u admin ...
done
But, now I'm getting a sql error on a valid sql file:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??' at line 1
Do I need to remove the commented lines in the sql files or something?
>>Do I need to remove the commented lines in the sql files or something?
Normally not, can you post the the SQL with the problematic lines
Normally not, can you post the the SQL with the problematic lines
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Assuming you have your sql files listed in let's say sql.files.txt:
Open in new window