0

I have started a humongous (~800GB sql dump) import to a mysql 5.5.

At some point I realized that while the db was being imported, the progress was starting slowing down as the db size increased;

That was a clear hint that the increasing size of foreign key checks was probably slowing the process;

I realized I had forgotten to disable them, which I just did (in the middle of the import);

So my question is if whether the specific import will benefit from this or it will keep performing FK checks (which were on in the import initialization)

mysql> show variables like 'fo%';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| foreign_key_checks | ON    |
+--------------------+-------+
1 row in set (0.00 sec)

mysql> SET FOREIGN_KEY_CHECKS=0;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like 'fo%';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| foreign_key_checks | OFF   |
+--------------------+-------+
1 row in set (0.00 sec)
  • You also need to be sure that innodb_buffer_pool_size is set to about 70% of RAM. – Rick James Oct 19 '18 at 4:05
1

The command

SET FOREIGN_KEY_CHECKS=0;

sets the value of a variable in a session scope. So it affects on the current session only, and do not affect on another sessions, both already running and those that will be launched later.

If you specify new value as a global-scope one using the command

SET GLOBAL FOREIGN_KEY_CHECKS=0;

then the global setting will be set. It affects on the current session and sessions that will be launched later, and do not affects on another sessions, which are already running.

You can see it in practice.

  • Start 2 CLI (mysql.exe) sessions.
  • Check the variable value in all windows.
  • Alter it in the 1st window.
  • Start 3rd window.
  • Check the variable value in all windows.
  • Alter it globally in the 1st window.
  • Start 4th window.
  • Check the variable value in all windows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.