April 23, 2012 · Don't Forget mysql
mysqldump with wildcard
Today I had to dump an existing database, but only wanted a subset of tables. Currently, mysql does not have a built-in option to do this, but with awk I got this to work:
- filter out the table you are looking for. connect to you mysql server and test you wildcard combination
> mysql -u user -p test_db
> password: **********
> show tables like 'iesna%'
- now combine that with awk and mysqldump command
> mysqldump -u user -p test_db 'mysql -DN test_db -e "show tables like 'iesna%'" | awk '{printf $1" "}''