Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql dump tables only

Tags:

mysql

export

In my database I have some tables and views. How can I export all the tables (and not the views) from my database from command line?

like image 221
dole doug Avatar asked Apr 02 '09 09:04

dole doug


People also ask

How do I dump multiple tables in MySQL?

To dump multiple tables with multiple where conditions. Then, for second table, use ">>". It will append the previous dump file.

How do I dump a specific table?

In order to dump only a specific set of tables using mysqldump , you need to specify the database name followed by the name of the tables you want to include in the dump. After running the command from the example above, the output file my_backup.


3 Answers

To ignore a single view from your DB for Dump:

mysqldump -uusrname -ppwd -h hostname --ignore-table=db.view_name db > db.sql

To ignore multiple view from your Db for Dump:

mysqldump -uusrname -ppwd -h hostname --ignore-table=db.view1 --ignore-table=db.view2 db > db.sql

NOTE: to ignore multiple views for dump use --ignore-table option multiple times.

like image 116
naveen_sfx Avatar answered Nov 02 '22 23:11

naveen_sfx


The current implementation mysqldump won't create dumps without views -- and furthermore, (last time I checked) views are actually created twice -- once as a table, then the table is dropped and replaced with a view. So you can't just filter out the "CREATE VIEW" command, unless that behavior has been modified.

However, mysqldump will take a list of tables as parameters following the database name. Something like this:

mysqldump -ujoe -pmysecret joesdb posts tags comments users 
like image 37
tylerl Avatar answered Nov 02 '22 22:11

tylerl


Backuping a single table from a database

mysqldump -uUSERNAME -pPASWORD DATABASE TABLE_NAME --host=HOST_NAME > c:\TABLE_NAME.sql

Restoring a single table from a database dump

mysql -uUSERNAME -pPASSWORD DATABASE --host=HOST_NAME < c:\TABLE_NAME.sql
like image 29
Green Card Avatar answered Nov 02 '22 23:11

Green Card