Backup all tables except one

Asked

Viewed 2,867 times

7

In Mysql we can perform backups via terminal as follows:

Database

mysqldump nomeBaseDados > meuFicheiroBackup.sql

Table

mysqldump nomeBaseDados nomeTabela > meuFicheiroBackupDaTabelaX.sql

How can I backup all tables in my database nomeBaseDados with the exception of a call tabelaCorrupta ?

1 answer

7


The mysqldumphas a flag exactly for this:

--ignore-table 


Example of use:

mysqldump -u username -p database --ignore-table=meubanco.tabelaCorrupta > database.sql


Remembering that, if necessary, you can use the --ignore-table more than once:

mysqldump -u username -p database --ignore-table=db.tab1 --ignore-table=db.tab2 ...


See more details on manual.

  • 1

    In Mariadb I did as follows: mysqldump -u root -p <dbname> -ignore-table=<dbname>. {Tabela1,table2,Tabela3} > backup.sql

  • 1

    @dark777 this is a feature of the shell used (parameter expansion), not a Mariadb feature. If you give a echo a.{1,2,3} in the same shell the result will also be a.1 a.2 a.3, because the expansion occurs before the execution. In practice you generated a line with --ignore-table= several times, as mentioned in the answer.

  • yes I did it so I wouldn’t have to write --ignore-table several times.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.