如果在init.sql 中包含存储过程并且存储过程包含查询语句,如下:
[pre]
drop procedure if exists proc_s_test;
create procedure proc_s_test(in aid INT)
BEGIN
select 1 from dual;
END;
[/pre]
直接通过 mysql 导入
[pre]
mysql> source init.sql;
[/pre]
会提示异常信息:
[pre]
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 'END WHILE'
[/pre]
原因是: mysql命令行 默认按照 【;】符号为提交,故执行到第4行 进行提交操作时认为sql有误,导致执行失败!
修改后的脚本为:
[pre]
-- 设置提交换行符为 ;
delimiter ;
drop procedure if exists proc_s_test;
-- 设置提交换行符为 //
delimiter //
create procedure proc_s_test(in aid INT)
BEGIN
select 1 from dual;
END//
-- 设置提交换行符为 ;
delimiter ;
[/pre]
这样就不会报错啦!face[微笑]