Iterate multiple MySQL tables, export 1 table from each

I have about 150 MySQL databases, I need to export 1 table from each database.

Is it possible, the username and password are identical for every DB.

+2


source to share


4 answers


I'm sure there is a more compact way to do this, but it should work.

#!/bin/bash

mysql -B -e "show databases" | egrep -v "Database|information_schema" | while read db; 
do 
  echo "$db"; 
  mysqldump $db TableName > $db.sql
done

      



You may need to customize your calls mysql

and mysqldump

depending on your connection information.

+4


source


I think that in this case, iteration would be more appropriate (rather than recursion).



+2


source


If you are on Linux, I would suggest writing a simple bash script that will quote 150 DB URLs and call mysqldump on each one.

+1


source


See link text , it generates metadata for all databases and all tables, you can adapt it to export data for you, However, this is in PHP and I'm not sure which language you want to use.

0


source







All Articles