4

How do I skip the version check comments in a MySQL dump.

/*!50003 ... */ ;

I basically want mysqldump to assume the versions are the same, and hence compatible.

The reason I want this is so I can dump the structure of my database, and commit, and compare it to other points in time, and other environments.

Currently it is also wrapping stored procedures, triggers, and functions in a conditional version check comment. I would like it to just output them as normal SQL (no comments). And entirely remove the conditional SET statements.

I have seen a similar question here, however it does not answer my question: How can I get rid of these comments in a MySQL dump?

I am not going to execute the SQL.

And doing a grep/sed on it will also remove triggers etc.

Community
  • 1
  • 1
Petah
  • 45,477
  • 28
  • 157
  • 213

1 Answers1

0

To remove only the SET commands, use:

perl -pi.bak -e 's|^/\*!\d{5} SET .*;\s*$||g;' filename.sql

To remove only the comments, use:

perl -pi.bak -e '
    s|/\*!\d{5} ([^\*]+)\*/|\1|g;
    s|\*/$||g;
    s|\*/\s*(;?;?)$|\1|g;
    s|/\*!\d{5} ||g;' filename.sql

To remove both, use:

perl -pi.bak -e '
    s|^/\*!\d{5} SET .*;\s*$||g;
    s|/\*!\d{5} ([^\*]+)\*/|\1|g;
    s|\*/$||g;
    s|\*/\s*(;?;?)$|\1|g;
    s|/\*!\d{5} ||g;' filename.sql
Ross Smith II
  • 11,799
  • 1
  • 38
  • 43