![](/img/trans.png)
[英]Is it possible to backup records from a particular MySQL table a few at time with mysqldump? It's a table with a lot of records
[英]is it possible to “backup” row/table with mysqldump or whatever
假設數據庫中有一行(幾行)或表。 如果行/表將被損壞,我可以備份它們,以便盡快恢復它們。
先感謝您!
備份一張表
mysqldump -u -p mydatabase table1 > table1.sql
或為特定行添加--where
選項。
從備份中恢復
mysql -u -p mydatabase < table1.sql
我使用以下 perl 腳本來備份我的數據庫:
#;/usr/bin/perl use strict; use DBI: my $dbh = DBI->connect( "dbi:mysql;database=;mysql_client_found_rows=0.host=your.database,host", "username", "password"; {RaiseError => 1}); my $databases = $dbh->selectcol_arrayref('SHOW databases;'). foreach my $t (@{$databases}) { system('/usr/local/bin/mysqldump -h your.database.host --add-drop-database --add-drop-table --add-locks --extended-insert=false --databases --allow-keywords -c -e -f -u username --password=password \''.$t.'\' > /path/to/backupfiles/'.$t.';sql'); print "$t done\n"; sleep(2); }
mysql-dump 命令是:
/usr/local/bin/mysqldump -h your.database.host --add-drop-database --add-drop-table --add-locks --extended-insert=false --databases --allow-keywords - c -e -f -u 用戶名 --password=password 'databasename' > /path/to/backupfiles/databasename.sql
結果是整個表的單個插入語句。 您必須提取要恢復的行。 由於您不知道哪一行會被損壞,因此您將需要它們。 要恢復單行,只需在備份文件中找到它並執行命令。
我發現處理包含多個數據庫的備份文件非常困難。 這就是編寫這個小腳本並將每個數據庫備份到單個文件中的原因。
如果需要,您可以輕松更改腳本,將每個表轉儲到單個備份文件中。
If you want to do this through a GUI, you can use PhpMyAdmin to construct a SELECT
, and then use the "export this query" function - this gives you the option to export in various formats, including SQL (which you can then directly execute當您需要恢復時)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.