Uploaded image for project: 'Confluence Data Center'
  1. Confluence Data Center
  2. CONFSERVER-30380

Upgrade to 5.2.x fails due to MySQL collation mismatch on columns 'FOLLOW_CONNECTIONS.FOLLOWER' and 'user_mapping.user_key'

    XMLWordPrintable

Details

    Description

      The problem

      Confluence 5.2.x introduces a new table 'user_mappings' as well as a new foreign key:

      alter table FOLLOW_CONNECTIONS add constraint FK_FOLLOW_CONNECTIONS_FOLLOWER foreign key (FOLLOWER) references user_mapping (user_key)
      

      When using MySQL, the upgrade can fail at the stage where this foreign key is being added if the storage engine is incorrect, or the column definitions between the following do not match:

      • FOLLOW_CONNECTIONS.FOLLOWER
      • user_mapping.user_key

      The logs will show:

      2013-08-13 22:50:16,459 ERROR [main] [hibernate.tool.hbm2ddl.SchemaUpdate] execute Unsuccessful: alter table FOLLOW_CONNECTIONS add constraint FK_FOLLOW_CONNECTIONS_FOLLOWER foreign key (FOLLOWER) references user_mapping (user_key)
      

      Diagnosis

      There are two issues that can cause this problem - either having the wrong collation, or using the wrong storage engine (MyISAM as opposed to InnoDB). To determine which you are experiencing, follow these steps. Be aware that your database may have both problems, and ensure you run through all steps in the diagnosis section.

      1. Run the following against the Confluence database in MySQL:
        show table status;
        
        1. If the storage engine for any table is not InnoDB, follow the instructions in Workaround 1.
        2. See whether collations for FOLLOW_CONNECTIONS and user_mapping tables are different (and check other tables while you are there).
        3. If they are different, run a show variables like '%collation%'; and see what your DB collation is set to.
        4. If the collation is not set to utf8_bin, follow the steps in Workaround 2.
      2. Otherwise if the collations are the same, examine the two tables explicitly:
        show create table FOLLOW_CONNECTIONS;
        show create table user_mapping;
        
        1. Look at the column definitions for FOLLOWER and user_key for differences.
        2. If the collation for these tables is not both set to utf8_bin, follow the steps in Workaround 2.
      3. Check the default engine by running this command:
        show engines;
        
        • If InnoDB is not the default engine, follow the steps in this document to set the default engine.

      Workaround

      Workaround 1 - Storage Engine

      NB: the database should be backed up before making any changes.

      1. Follow the instructions in this document. This is necessary to create all the foreign keys that you should have in your database, to ensure referential integrity.
      2. Then attempt the upgrade to 5.2 again. NB: Do not attempt to perform the upgrade at the same time. Follow the instructions above to fix the storage engine, and then upgrade as normal once that is complete.

      You may also want to check the Known Issues for MySQL to see if there are any other settings you may be missing that could prevent issues like this in future.

      Workaround 2 - Collation

      NB: the database should be backed up before making any changes.

      1. Shut down Confluence
      2. If any of the following SQL statements returns any rows, migration to utf8 should be performed before proceeding:
        use confluence;
        SHOW variables WHERE Variable_name = "character_set_database" AND Value != "utf8";
        
        SELECT table_name, column_name, character_set_name FROM information_schema.`COLUMNS` C
        WHERE table_schema = "confluence"
          AND character_set_name != "utf8";
        
        SELECT T.table_name, CCSA.character_set_name FROM information_schema.`TABLES` T,
               information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
        WHERE CCSA.collation_name = T.table_collation
          AND T.table_schema = "confluence"
          AND CCSA.character_set_name != "utf8";
        
      3. Check database collation:
        use confluence;
        show variables like "collation_database";
        
      4. If database collation is not "utf8_bin", fix it with:
        alter database confluence character set utf8 collate utf8_bin;
        
      5. Find tables using non utf8_bin collation:
        SELECT DISTINCT T.table_name FROM information_schema.`TABLES` T, information_schema.`COLUMNS` C 
        WHERE T.table_schema = "confluence"
          AND T.table_name = C.table_name
          AND (T.table_collation != "utf8_bin" OR C.collation_name != "utf8_bin");
        
      6. Fix each table with a command like the following:
        ALTER TABLE FOLLOW_CONNECTIONS CONVERT TO CHARACTER SET DEFAULT; 
        

        OR

        SELECT CONCAT('ALTER TABLE `', t.`TABLE_SCHEMA`, '`.`', t.`TABLE_NAME`, '` CONVERT TO CHARACTER SET DEFAULT') as stmt 
        FROM `information_schema`.`TABLES` t
        WHERE 1
        AND t.`TABLE_SCHEMA` = 'confluence'
        ORDER BY 1;
        

        Ensure to change the t.table_schema to reflect your Confluence database name.

      1. Restart Confluence. The remaining upgrade tasks should run at this point.

      You may also want to check the Known Issues for MySQL to see if there are any other settings you may be missing that could prevent issues like this in future.

      Attachments

        Issue Links

          Activity

            People

              onevalainen Olli Nevalainen
              rchang Robert Chang
              Votes:
              11 Vote for this issue
              Watchers:
              24 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: