patternsqlModerate
mysqldump not escaping single quotes properly
Viewed 0 times
escapingproperlymysqldumpquotessinglenot
Problem
I use mysqldump to backup my mysql database.
The problem is that the sql file generated by mysqldump doesn't escapes single quotes properly.
Here is an example of the mysqldump generated sql script :
That single quote escaping in "ain't" doesn't work and it makes the rest of the script being inside that string.
Is there a way around this?
The problem is that the sql file generated by mysqldump doesn't escapes single quotes properly.
Here is an example of the mysqldump generated sql script :
INSERT INTO `someTable` VALUES (1,'This ain\'t escaped correctly');That single quote escaping in "ain't" doesn't work and it makes the rest of the script being inside that string.
Is there a way around this?
Solution
That output of mysqldump is working as designed, and it is properly escaped, unless you try to restore the dump on a MySQL instance with
There's an outstanding feature request to make mysqldump use a pair of single-quotes to escape literal single-quotes, as per ANSI SQL. See http://bugs.mysql.com/bug.php?id=65941
In the meantime you might be able to convert from backslash-singlequote to pair-of-singlequotes with a command line this:
I tried that out briefly by creating a dummy table in my
SQL_MODE=NO_BACKSLASH_ESCAPES set.There's an outstanding feature request to make mysqldump use a pair of single-quotes to escape literal single-quotes, as per ANSI SQL. See http://bugs.mysql.com/bug.php?id=65941
In the meantime you might be able to convert from backslash-singlequote to pair-of-singlequotes with a command line this:
mysqldump test | sed -e "s/\\\'/''/g" > test-dump.sqlI tried that out briefly by creating a dummy table in my
test database and inserting the string "O'Hare" into the table. But that's hardly a comprehensive test -- I take no responsibility for this suggestion working in all cases.Code Snippets
mysqldump test | sed -e "s/\\\'/''/g" > test-dump.sqlContext
StackExchange Database Administrators Q#29575, answer score: 12
Revisions (0)
No revisions yet.