Home > Software engineering >  how to run an sql file, that incorporates multiple databases(schemas), from Mysql shell?
how to run an sql file, that incorporates multiple databases(schemas), from Mysql shell?

Time:07-10

Ive exported multiple schemas using Mysql Workbench, into a single 2gb sql file. Now, I want to import it.

Problem is, that in the examples i saw so far, the command is per schema:

mysql -h hostname -u user database < path/to/test.sql

My file contains many tables from multiple schemas.

How can this be run? It's too large to paste into Mysql Workbench, or run it from the program.

CodePudding user response:

Three choices:

  • Include the USE <schema> statement in the SQL input file, preceding other statements that reference tables in that schema.

  • Use qualified table names. Then you can reference tables in any schema, regardless of which schema is the default schema.

  • Split the input file into multiple files, one per schema. Run each of these multiple files with a different invocation of the mysql command line tool, passing the respective schema name as the argument.

  • Related