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?

John D.


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;


Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.