Check Whether GIPKs are Enabled in MySQL

In MySQL, GIPK stands for generated invisible primary key. These are created whenever we create an InnoDB table without explicitly defining primary key.

However, MySQL will only create a GIPK if we have enabled GIPKs. More specifically, a GIPK will only be created when our sql_generate_invisible_primary_key server system variable is set to ON. By default this is set to OFF.

Example

We can run the following code to check whether GIPKs are enabled on our system:

SELECT @@sql_generate_invisible_primary_key;

Result:

+--------------------------------------+
| @@sql_generate_invisible_primary_key |
+--------------------------------------+
|                                    0 |
+--------------------------------------+

In this case my sql_generate_invisible_primary_key variable is set to 0, which means OFF. In other words, GIPKs are disabled.

Enable GIPKs

We can enable GIPKs by setting our sql_generate_invisible_primary_key variable is set to 1, which means ON:

SET sql_generate_invisible_primary_key = ON;

GIPKs are now enabled.

We can verify this by selecting the sql_generate_invisible_primary_key again:

SELECT @@sql_generate_invisible_primary_key;

Result:

+--------------------------------------+
| @@sql_generate_invisible_primary_key |
+--------------------------------------+
|                                    1 |
+--------------------------------------+

This time it returns a value of 1, which means ON.