MySQL export tables with prefix from Unix command line

6,311

You have to generate the list of tables you want to dump then act upon it.

mysql -u USER -p -D test -Bse "show tables like 'wiki_%'" >tables.out
mysqldump -u USER -p test <tables.out >wiki_tables.dump

or as a one liner

mysqldump -u USER -p test $(mysql -u USER -p -D test -Bse "show tables like 'wiki_%'")

but you still get to enter the password twice.

Share:
6,311
o01
Author by

o01

Updated on September 18, 2022

Comments

  • o01
    o01 over 1 year

    I want to export certain tables from one database and import them to another. The tables in question are used for my MediaWiki installation and are prefixed with "wiki_".

    I do not have access to phpMyAdmin, but I am able to connect to the server via SSH. I'm guessing I need to use the mysqldump command, but how do I specify that I only want to dump tables prefixed with "wiki_"?