我正在将数据加载到存储过程内的表中,该存储过程的文件名作为参数传递。
select @load_config:= concat('load data local infile ',config_file,' into table config fields terminated by \',\' lines terminated by \n');
prepare stm from @load_config;
为此我收到错误
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '/mnt/appln/mysql/dvdbuser/config.csv into table config fields terminated by ',' ' at line 1 i tried this as well
select @load_config:= concat('load data local infile \'',config_file,'\' into table config fields terminated by \',\' lines terminated by \n');
prepare stm from @load_config;
我收到错误
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
说实话,我迷路了,我不知道我在哪里搞砸了
最佳答案
\
是转义序列的开头。
第一个问题很可能是缺乏转义单引号。因此,当您执行 \'
时,它会转换为单引号,从而终止未关闭的 block 。由于它现在已关闭,因此由于保留了字符串片段,您会收到语法错误。您需要执行 \\'
这会引入斜杠,而不是 foobar 之后的单引号。
有关转义序列表,请参阅 Mysql 手册页 String Literals .
即便如此,这整件事还是行不通。因为存储过程、事件等不支持LOAD DATA INFILE
。这是一件令人悲伤的事情,但据称是出于安全原因。它将生成错误 42000 或类似错误。
Error: This command is not supported in the prepared statement protocol yet
解决方法是使用 UDF,这需要您修改 mysql 环境,或者为这些琐碎的事情创建一个外部进程,这就是我所做的。
关于mysql - 无法使用 load data infile 识别错误原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38241364/