最近在做一个日志统计项目,有一个辅助表是在MySQL数据库的,现在要将其迁移到Postgresql,自然是先用mysqldump将MySQL里面的数据导出,然后再导入到Postgresql即可。但在实际操作过程中,发现一些字段中本身就含有单引号,在导出的sql语句中,对这样的单引号使用’\’做了转义处理,比如原来的某个字段的值为:It’s very popular,导出的sql中大概是这样的格式:’It\’s very popular’,可以看到,字段中的单引号被转义。但使用导出的sql往Postgresql中插入数据时,却报告错误,因为Postgresql对’\’作为转义字符并不识别。
Question:
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 :
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?
Answer:
That output of mysqldump is working