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

Viewed 26

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.

1 Answers

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