I'm running Ubuntu with MySQL version 5.5.44
mysqld Ver 5.5.44-0ubuntu0.14.10.1 for debian-linux-gnu on x86_64 ((Ubuntu))
I have a DB with foreign keys. I would like to have the foreign key check disabled at the system level (not at the session).
I saw the system var foreign_key_checks that seems to control this behavior but when I set it in /etc/mysql/my.cnf
(by adding foreign_key_checks = 0
) the server won't start. The error log looks like:
150729 15:38:18 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
150729 15:38:18 [Note] Plugin 'FEDERATED' is disabled.
150729 15:38:18 InnoDB: The InnoDB memory heap is disabled
150729 15:38:18 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150729 15:38:18 InnoDB: Compressed tables use zlib 1.2.8
150729 15:38:18 InnoDB: Using Linux native AIO
150729 15:38:18 InnoDB: Initializing buffer pool, size = 128.0M
150729 15:38:18 InnoDB: Completed initialization of buffer pool
150729 15:38:18 InnoDB: highest supported file format is Barracuda.
150729 15:38:18 InnoDB: Waiting for the background threads to start
150729 15:38:19 InnoDB: 5.5.44 started; log sequence number 56348937
150729 15:38:19 [ERROR] /usr/sbin/mysqld: unknown variable 'foreign_key_checks=0'
150729 15:38:19 [ERROR] Aborting
How can I configure my MySQL server to start with foreign key checks off at the system level?
Edit: behavior is the same with MySQL 5.6.25:
mysqld Ver 5.6.25-0ubuntu0.15.04.1 for debian-linux-gnu on x86_64 ((Ubuntu))
Best Answer
Root Cause
foreign_key_checks is not a global option you can preset at startup. Why ?
When you click on that link to the Documentation on foreign_key_checks, there is no chart that says it is global or session scope. Other options will specify the scope in a chart
With foreign_key_checks, it is session scope only.
Further proof of this is when you go to the command line and run this
When you look inside the text file, you do not see
--foreign-key-checks
as a command line startup option. The other four variables I showed you can be used on the command line and inmy.cnf
.If you have data to load, you can set that before loading:
Proof of this is a standard mysqldump header ( first 10 lines )
Please note line 8
What does the bottom of a mysqldump look like ? Like this:
Please note the line
Epilogue
Bottom Line: foreign_key_checks is not meant of use in
my.cnf
. That make the most sense because (if allowed) starting mysqld with that would be damaging to referential integrity from startup.