Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagebash
mysqldump  --single-transaction --databases db1 --ignore-table=db1.table1  --ignore-table=db1.table2 -h localhost \
-u root -pmypwd \
--where='created_at > subdate(current_date, 1)'
> mydump.sql

실전 예

mydb의 table1, table2 의 id 가 2,000 이상만 덤프후 primary key(id)  제거

  1. 덤프

    Code Block
    mysqldump --complete-insert --no-create-db  --no-create-info --single-transaction -u root -pmypwd mydb table1 table2 --where='id > 2000' > mydump.sql
  2. id 값 제거

    Code Block
    sed -e "s/([0-9]*,/(/gi" mydump.sql > mydump2.sql
  3. editor 로 mydump2.sql 열어서 insert 구문에서 `id` 삭제

dump 파일 복구

db2 에 복구

Code Block
mysql -h dbhost2 -u root -pmypwd db2 <  mydump.sql

...