xelabs / go-mydumper

A multi-threaded MySQL backup and restore tool, faster than mysqldump

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[feature] Stream/Dump without foreign keys

syerad opened this issue · comments

First of all thank you for this amazing tool!

For the future it would be nice to add the possibility
to stream/dump data without the foreign keys.
In the "standard" mysql it looks like this:

/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;

Thank you in Advance :)

commented

Wouldn't it be a nice option to do it just for one dump?

commented

Sure, it's on the plan.
Thanks.

commented

@syerad

Hi, mydumper/mystreamer has add vars flag, we can set as:

./bin/mydumper/mystreamer -h 192.168.0.253 -P 3306 -u test -p test -db mydb  -vars "SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0" -o mydb.sql
commented

Recurrence

image

[root@VM_0_17_centos ~]# ./sync.sh 
 2019/04/03 16:48:48.384138 streamer.go:31:    	 [INFO] 	streaming.database[airbaggy].schema...
panic: Cannot delete or update a parent row: a foreign key constraint fails (errno 1217) (sqlstate 23000)

goroutine 1 [running]:
common.AssertNil(0x5e0100, 0xc420097900)
	/home/ubuntu1804/go-mydumper/src/common/common.go:75 +0x4a
common.streamTableSchema(0xc42007c430, 0x7ffc4c8c57db, 0x8, 0x7ffc4c8c57db, 0x8, 0x0, 0x0, 0x7ffc4c8c57eb, 0xd, 0x1, ...)
	/home/ubuntu1804/go-mydumper/src/common/streamer.go:42 +0x6f6
common.Streamer(0xc42007c430, 0xc4200ee100)
	/home/ubuntu1804/go-mydumper/src/common/streamer.go:168 +0x4cf
main.main()
	/home/ubuntu1804/go-mydumper/src/mystreamer/main.go:79 +0x40a
commented

@xqdd

Hi, what's the code version of mystreamer?

commented

image

image

commented

@xqdd

This is the foreign key constraint issue caused by MySQL, please try:

-vars "SET GLOBAL FOREIGN_KEY_CHECKS=0" 
commented

Not work, I excute this and it work by using set comand directly

image

I think the -var paramatter haven't been excuted

Here is a temporary database, you can use it for debug:

./mystreamer -vars "set FOREIGN_KEY_CHECKS=0"  \
 -h 154.8.160.136 -P 3307 -u root -p secret -o  -db temp1 -table my_wx_mp_user \
 -2h 154.8.160.136 -2P 3307 -2u root -2p secret  -2db temp2
commented

@xqdd

Thanks for your information, fixed: 3d6f763
Please pull the master and build again.