开发者

How to dump a single table in MySQL without locking?

开发者 https://www.devze.com 2022-12-21 00:04 出处:网络
When I run the following command, the output only consists of the create syntax for \'mytable\', but none of the data:

When I run the following command, the output only consists of the create syntax for 'mytable', but none of the data:

mysqldump --single-transaction -umylogin -p mydatabase mytable > dump.sql

If I drop --single-transaction, I get an error as I can't lock the tables.

If I drop 'mytable' (and do the DB), it looks like it's creat开发者_开发百科ing the INSERT statements, but the entire DB is huge.

Is there a way I can dump the table -- schema & data -- without having to lock the table?

(I also tried INTO OUTFILE, but lacked access for that as well.)


The answer might depend on the database engine that you are using for your tables. InnoDB has some support for non-locking backups. Given your comments about permissions, you might lack the permissions required for that.

The best option that comes to mind would be to create a duplicate table without the indicies. Copy all of the data from the table you would like to backup over to the new table. If you create your query in a way that can easily page through the data, you can adjust the duration of the locks. I have found that 10,000 rows per iteration is usually pretty darn quick. Once you have this query, you can just keep running it until all rows are copied.

Now that you have a duplicate, you can either drop it, truncate it, or keep it around and try to update it with the latest data and leverage it as a backup source.

Jacob

0

精彩评论

暂无评论...
验证码 换一张
取 消