テーブルをロックせずにMySQLDumpを実行する 質問する

テーブルをロックせずにMySQLDumpを実行する 質問する

実稼働中の本番データベースをローカルの開発データベースにコピーしたいのですが、本番データベースをロックせずにこれを行う方法はありますか?

現在使用中:

mysqldump -u root --password=xxx -h xxx my_db1 | mysql -u root --password=xxx -h localhost my_db1

しかし、実行時に各テーブルがロックされます。

ベストアンサー1

このオプションは機能しますか--lock-tables=false?

によるマニュアルページInnoDB テーブルをダンプする場合は、以下の--single-transactionオプションを使用できます。

--lock-tables, -l

Lock all tables before dumping them. The tables are locked with READ
LOCAL to allow concurrent inserts in the case of MyISAM tables. For
transactional tables such as InnoDB and BDB, --single-transaction is
a much better option, because it does not need to lock the tables at
all.

innodb DBの場合:

mysqldump --single-transaction=TRUE -u username -p DB

おすすめ記事