Is there any way to disable foreign key verification using the mysqlimport bookmark option?

I asked this question and I am just returning to the problem.

I have a backup script for my MySQL database using mysqldump with the --tab option, so it creates a .sql file for the structure and a .txt file (pipe split) for the content.

The answer to a related question works when importing SQL files (table structure), but I also get a foreign key constraint error when importing some tables (since the table has a foreign key for itself). These two teams:

 cat <(echo "SET FOREIGN_KEY_CHECKS=0;") "table.sql" | mysql [user/pass] database mysqlimport [user/pass] --local --fields-terminated-by="|" database "table.txt" 

It seems that this was requested a few years ago on its bug tracker , but was never implemented. Is there any way around this?

Please note that I want to continue using the tab option for various reasons (it is faster and works better with git, since each line is on a separate line).

+6
source share
1 answer

You can always temporarily set the mysql global system variable 'foreign_key_checks' to off / zero by following the command line before starting the script database creation.

 mysql --host=localhost --user=USER --password -e "SET GLOBAL foreign_key_checks=0" 

You cannot enter a password on the command line. Omitting it, and only specifying --password , and not --password=MYPATH will force the system to ask the user for it before continuing.

+10
source

Source: https://habr.com/ru/post/946911/


All Articles