Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-6899

Database Dump has Syntax Error When Importing

    Details

    • Type: Bug
    • Status: Stalled
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 5.5.40
    • Fix Version/s: 10.0
    • Component/s: Events, OTHER
    • Labels:
    • Environment:
      Scientific Linux release 6.5

      Description

      Dear MariaDB developers,

      I encountered a problem when importing from a database dump of itself.

      I used this command for the dump:
      mysqldump --routines --triggers --events --single-transaction -u root -p --databases my_db > ./my_db_dump.sql

      After I got the dump file, and was trying to import the database dump, the MariaDB complains about syntax error on a single line. This line is about the EVENT from the dump.

      The offending line looks like this:

      /*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `expireToken` ON SCHEDULE EVERY 1 DAY STARTS '2014-08-08 14:47:34' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM Token WHERE DATE(time_end) < CURRENT_DATE; */ ;;
      

      Notice, there are a lot of "/* */" in this line. If I remove them as the following, the import can finish without any issue, and the database seems to be set up properly after importing:

      CREATE DEFINER=`root`@`localhost` EVENT `expireToken` ON SCHEDULE EVERY 1 DAY STARTS '2014-08-08 14:47:34' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM Token WHERE DATE(time_end) < CURRENT_DATE;
      

      Do you know what could be the issues here? Is this a bug in MariahDB "mysqldump" command?

      Thanks,

      Kai

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            ksong Kai Song added a comment -

            Hi Elena,

            I found the problem while trying to prepare the sql script for you!

            The DELIMITER is set to be "//", but I didn't use it for the EVENT.

            Thanks so much for your help, and please feel free to remove this bug report!

            Kai

            Show
            ksong Kai Song added a comment - Hi Elena, I found the problem while trying to prepare the sql script for you! The DELIMITER is set to be "//", but I didn't use it for the EVENT. Thanks so much for your help, and please feel free to remove this bug report! Kai
            Hide
            elenst Elena Stepanova added a comment -

            Okay, as long as the fix made the problem go away.

            I'm still mildly curious about how exactly it looked at the file, because even with the missing delimiter it's not so easy to achieve. But I suppose it's possible.

            Show
            elenst Elena Stepanova added a comment - Okay, as long as the fix made the problem go away. I'm still mildly curious about how exactly it looked at the file, because even with the missing delimiter it's not so easy to achieve. But I suppose it's possible.
            Hide
            ksong Kai Song added a comment -

            Hi Elena,

            I managed to extract the problematic code in a schema.sql file and attached it to this issue.

            Take any database server without a database name "test_db", you can import the schema.sql file and generate a dump file, db_dump.sql:

            [kaisong ~]$ mysql -u root -p test_db < schema.sql 
            Enter password: 
            [kaisong ~]$ mysqldump --routines --triggers --events --single-transaction -u root -p --databases test_db > ./db_dump.sql
            Enter password: 
            

            Then, we can see the extra semicolon in the dump file:

            [kaisong ~]$ grep EVENT db_dump.sql 
            /*!50106 DROP EVENT IF EXISTS `fooEvent` */;
            /*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `fooEvent` ON SCHEDULE EVERY 1 DAY STARTS '2014-10-21 08:28:26' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM Token WHERE DATE(time_end) < CURRENT_DATE; */ ;;
            

            Notice, in the schema.sql file line 22, if I replace the semicolon with "//" delimiter, the problem should be fixed.

            Hope this helps with debugging the issue.

            Thanks,

            Kai

            Show
            ksong Kai Song added a comment - Hi Elena, I managed to extract the problematic code in a schema.sql file and attached it to this issue. Take any database server without a database name "test_db", you can import the schema.sql file and generate a dump file, db_dump.sql: [kaisong ~]$ mysql -u root -p test_db < schema.sql Enter password: [kaisong ~]$ mysqldump --routines --triggers --events --single-transaction -u root -p --databases test_db > ./db_dump.sql Enter password: Then, we can see the extra semicolon in the dump file: [kaisong ~]$ grep EVENT db_dump.sql /*!50106 DROP EVENT IF EXISTS `fooEvent` */; /*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `fooEvent` ON SCHEDULE EVERY 1 DAY STARTS '2014-10-21 08:28:26' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM Token WHERE DATE(time_end) < CURRENT_DATE; */ ;; Notice, in the schema.sql file line 22, if I replace the semicolon with "//" delimiter, the problem should be fixed. Hope this helps with debugging the issue. Thanks, Kai
            Hide
            elenst Elena Stepanova added a comment - - edited

            Thanks, it's interesting.
            So here is how one can actually do it:

            DROP EVENT IF EXISTS fooEvent;
            DELIMITER //
            CREATE EVENT fooEvent
            ON SCHEDULE EVERY 1 DAY
            DO
                DELETE FROM Token WHERE DATE(time_end) < CURRENT_DATE;
            SELECT 1 //
            DELIMITER ;
            

            It's the same in MySQL, too, probably has always been. Not sure that upstream will want to fix it, but at least next time we'll know.

            Still, if you want, you can try to file a bug at bugs.mysql.com and see what they say.

            Show
            elenst Elena Stepanova added a comment - - edited Thanks, it's interesting. So here is how one can actually do it: DROP EVENT IF EXISTS fooEvent; DELIMITER // CREATE EVENT fooEvent ON SCHEDULE EVERY 1 DAY DO DELETE FROM Token WHERE DATE(time_end) < CURRENT_DATE; SELECT 1 // DELIMITER ; It's the same in MySQL, too, probably has always been. Not sure that upstream will want to fix it, but at least next time we'll know. Still, if you want, you can try to file a bug at bugs.mysql.com and see what they say.
            Hide
            elenst Elena Stepanova added a comment -

            After some contemplation, re-opening because it still feels like a bug, albeit minor – a problem with parsing multi-statement queries?
            In the example above, if the server considers SELECT being a part of the event body, there should probably be a syntax error; or, if there is no syntax error, SELECT should become a part of the event definition which it's not – when the query is issued, the event is created, while the SELECT gets executed, no errors. So, the server is able to split them properly; but then, it shouldn't put the semicolon in the event body.

            Show
            elenst Elena Stepanova added a comment - After some contemplation, re-opening because it still feels like a bug, albeit minor – a problem with parsing multi-statement queries? In the example above, if the server considers SELECT being a part of the event body, there should probably be a syntax error; or, if there is no syntax error, SELECT should become a part of the event definition which it's not – when the query is issued, the event is created, while the SELECT gets executed, no errors. So, the server is able to split them properly; but then, it shouldn't put the semicolon in the event body.

              People

              • Assignee:
                Unassigned
                Reporter:
                ksong Kai Song
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: