snippetsqlCritical
How do you mysqldump specific table(s)?
Viewed 0 times
howyoumysqldumpspecifictable
Problem
How can I dump a specific table or set of tables without including the rest of the db tables?
Solution
If you are dumping tables
If you have a ton of tables in
UPDATE 2014-03-06 10:15 EST
@RoryDonohue pointed out to me that the GROUP_CONCAT function needs to have its max length extended. I added the session variable group_concat_max_len to my answer with a length max of 10K.
t1, t2, and t3 from mydbmysqldump -u... -p... mydb t1 t2 t3 > mydb_tables.sqlIf you have a ton of tables in
mydb and you want to dump everything except t1, t2, and t3, do this:DBTODUMP=mydb
SQL="SET group_concat_max_len = 10240;"
SQL="${SQL} SELECT GROUP_CONCAT(table_name separator ' ')"
SQL="${SQL} FROM information_schema.tables WHERE table_schema='${DBTODUMP}'"
SQL="${SQL} AND table_name NOT IN ('t1','t2','t3')"
TBLIST=`mysql -u... -p... -AN -e"${SQL}"`
mysqldump -u... -p... ${DBTODUMP} ${TBLIST} > mydb_tables.sqlUPDATE 2014-03-06 10:15 EST
@RoryDonohue pointed out to me that the GROUP_CONCAT function needs to have its max length extended. I added the session variable group_concat_max_len to my answer with a length max of 10K.
Code Snippets
mysqldump -u... -p... mydb t1 t2 t3 > mydb_tables.sqlDBTODUMP=mydb
SQL="SET group_concat_max_len = 10240;"
SQL="${SQL} SELECT GROUP_CONCAT(table_name separator ' ')"
SQL="${SQL} FROM information_schema.tables WHERE table_schema='${DBTODUMP}'"
SQL="${SQL} AND table_name NOT IN ('t1','t2','t3')"
TBLIST=`mysql -u... -p... -AN -e"${SQL}"`
mysqldump -u... -p... ${DBTODUMP} ${TBLIST} > mydb_tables.sqlContext
StackExchange Database Administrators Q#9306, answer score: 735
Revisions (0)
No revisions yet.