Executing a command file from within a command file?
I have a bunch of things I'd like to execute one after the other. A simple example would be: - drop table x; - drop table y; - create table y by executing create_table_y.sql - create table x by executing create_table_x.sql
With the mysql command line, I can execute "drop table x;", and I can execute a SQL script with -e "source create_table_x.sql".
But what is the good way to bundle all these together into a script which will do all the actions? The only way I can think of is to create a batch file which will call out to mysql for each action. And pass the password as an argument to the batch file. Like this: mysql -u root -p mypassword -e "drop table x;" mysql -u root -p mypassword -e "drop table y;" mysql -u root -p mypassword -e "source create_table_y.sql" mysql -u root -p mypassword -e "source create_table_x.sql"
But this seems fairly clunky. Is there a better, or even best practice?
You can put the source command in a file. Like in
drop table x; drop table y; source create_table_y.sql; source create_table_x.sql;