patternsqlMinor
Import .sql file into multiple databases
Viewed 0 times
filedatabasessqlintomultipleimport
Problem
How to import
I have tried this:
But it asks for database name. Whatever there in
.sql file into multiple databases at one shot.I have tried this:
mysql -uroot -p -all-databases < test.sqlBut it asks for database name. Whatever there in
test.sql file should reflect in all the databases/Schemas.Solution
If you're running on Linux/Unix, you can do it with a bit of shell:
Will obviously be easier if you temporarily set it up to be passwordless.
for DB in `mysql -u root -r --silent -p -e 'show databases;' | egrep -v "_schema$|^mysql$|^sys$"`
do
mysql -uroot -p $DB < test.sql
doneWill obviously be easier if you temporarily set it up to be passwordless.
Code Snippets
for DB in `mysql -u root -r --silent -p -e 'show databases;' | egrep -v "_schema$|^mysql$|^sys$"`
do
mysql -uroot -p $DB < test.sql
doneContext
StackExchange Database Administrators Q#142159, answer score: 2
Revisions (0)
No revisions yet.