Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check current FOREIGN_KEY_CHECKS value

Tags:

mysql

How can I check what the current value of FOREIGN_KEY_CHECKS is?

I want to be sure that the value is 1.

like image 548
JGeer Avatar asked Jun 26 '17 15:06

JGeer


People also ask

Why set foreign_ key_ checks 0?

Setting foreign_key_checks to 0It affects data definition statements: DROP SCHEMA drops a schema even if it contains tables that have foreign keys that are referred to by tables outside the schema, and DROP TABLE drops tables that have foreign keys that are referred to by other tables.


1 Answers

Check 5.1.5 Server System Variables::foreign_key_checks:

mysql> SELECT @@GLOBAL.foreign_key_checks, @@SESSION.foreign_key_checks;
+-----------------------------+------------------------------+
| @@GLOBAL.foreign_key_checks | @@SESSION.foreign_key_checks |
+-----------------------------+------------------------------+
|                           1 |                            1 |
+-----------------------------+------------------------------+
1 row in set (0.01 sec)

UPDATE

mysql> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 5.7.18    |
+-----------+
1 row in set (0.00 sec)

mysql> SELECT IF((SELECT `VARIABLE_VALUE`
    -> FROM `performance_schema`.`global_variables`
    -> WHERE `VARIABLE_NAME` = 'foreign_key_checks') = 'ON', 1, 0) `global.foreign_key_checks`,
    -> IF((SELECT `VARIABLE_VALUE`
    -> FROM `performance_schema`.`session_variables`
    -> WHERE `VARIABLE_NAME` = 'foreign_key_checks') = 'ON', 1, 0) `session.foreign_key_checks`;
+---------------------------+----------------------------+
| global.foreign_key_checks | session.foreign_key_checks |
+---------------------------+----------------------------+
|                         1 |                          1 |
+---------------------------+----------------------------+
1 row in set (0.00 sec)
like image 92
wchiquito Avatar answered Sep 28 '22 11:09

wchiquito