percona MYSQL 5.7.13 5.7.14 MYSQLDUMP 導入報錯delimiter (修改MYSQLDUMP代碼)
percona 5.7.13 5.7.14
MYSQLDUMP備份完成后不能呢導回去,
文件一大了非常麻煩,最近遇到這樣的問題。
[root@testmy client]# /mysqldata/mysql3308/bin/mysql -uroot -p<log.sql
Enter password:
ERROR at line 63: DELIMITER must be followed by a 'delimiter' character or string
ERROR 1064 (42000) at line 64: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4
其實這里就是DELIMITER 后面的;;解析了,只要把;;轉變為$$ 就好了.
[root@testmy client]# sed -i "s/;;/$$/g" log.sql
[root@testmy client]# /mysqldata/mysql3308/bin/mysql -uroot -p<log.log
Enter password:
[root@testmy client]#
當然我這里是測試庫,如果真的是線上庫量非常大作sed談何容易。所以決定從mysqldump下手改一下標識即可。
下面是修改部分,因為MYSQLDUMP是獨立的工具,這些函數全是static函數,可以放心修改,如果是外部函數真
還不敢改,修改源碼的client/mysqldump.c 如下部分修改了:
static uint dump_events_for_db(char *db)
2547 fprintf(sql_file,
2548 "DELIMITER ;;\n"
2549 "%s ;;\n"
2550 "DELIMITER ;\n",
修改為
static uint dump_events_for_db(char *db)
2547 fprintf(sql_file,
2548 "DELIMITER $$\n"
2549 "%s $$\n"
2550 "DELIMITER ;\n",
static void dump_trigger_old(FILE *sql_file, MYSQL_RES *show_triggers_rs,
MYSQL_ROW *show_trigger_row,
const char *table_name)
3247 fprintf(sql_file,
3248 "DELIMITER ;;\n"
3249 "/*!50003 SET SESSION SQL_MODE=\"%s\" */;;\n"
3250 "/*!50003 CREATE */ ",
3251 (*show_trigger_row)[6]);
修改為:
3247 fprintf(sql_file,
3248 "DELIMITER $$\n"
3249 "/*!50003 SET SESSION SQL_MODE=\"%s\" */$\n"
3250 "/*!50003 CREATE */ ",
3251 (*show_trigger_row)[6]);
static int dump_trigger(FILE *sql_file, MYSQL_RES *show_create_trigger_rs,
const char *db_name,
const char *db_cl_name)
3334 fprintf(sql_file,
3335 "DELIMITER ;;\n"
3336 "/*!50003 %s */;;\n"
3337 "DELIMITER ;\n",
3338 (const char *) (query_str != NULL ? query_str : row[2]));
修改為:
3334 fprintf(sql_file,
3335 "DELIMITER $$\n"
3336 "/*!50003 %s */$$\n"
3337 "DELIMITER ;\n",
3338 (const char *) (query_str != NULL ? query_str : row[2]));
最后需要重新cmake一下make編譯一下不需要make install 把mysqldump 拷貝到相應的目錄即可
修改后
[root@testmy client]# more log.log |grep '$$'
DELIMITER $$
end */$$
DELIMITER $$
end $$
[root@testmy client]# /mysqldata/mysql3308/bin/mysql -uroot -p<log.log
Enter password:
[root@testmy client]#
不會報錯了。
</log.log
</log.log
</log.sql