skip to Main Content

I have a Digital Ocean-managed MySQL database. In order to prevent data replication issues across nodes, DO automatically sets your instance with sql_require_primary_key. This is fine in theory except that there are various WordPress plugins, including notably WP Cerber, which do not support that setting.

I can ask Digital Ocean to disable the setting for me, but I run the risk of my data not replicating properly. So what I’m wondering is, is there a way to disable that setting for specific databases and even tables, or is that setting restricted to the connection settings and the server-wide settings?

2

Answers


  1. The first table on the page you referred is created like this:

    CREATE TABLE IF NOT EXISTS cerber_log ( 
        ip varchar(39) CHARACTER SET ascii NOT NULL, 
        user_login varchar(60) NOT NULL, 
        user_id bigint(20) unsigned NOT NULL DEFAULT '0', 
        stamp bigint(20) unsigned NOT NULL, 
        activity int(10) unsigned NOT NULL DEFAULT '0', 
        KEY ip (ip) 
        ) DEFAULT CHARSET=utf8;
    

    Adding a primary key:

    ALTER TABLE cerber_log ADD COLUMN primaryKey int primary key auto_increment;
    

    You can use any name for the field primaryKey, as long as it is not an existing field.

    This should not interfere with the plugin. And if it does than you should probably not (want) to use that plugin at all.

    Login or Signup to reply.
  2. You can temporarily disable it at the session level.

    SET SESSION sql_require_primary_key = 0;
    

    I have some migration code that makes primary keys after it makes the table. I added the above snippet to the migration before the table is created. In the end it does make a primary key so all is well.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search