Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

mysql - Load data Infile @variable into infile error

I want to use a variable as the file name in Load data Infile. I run a below code:

Set @d1 = 'C:/Users/name/Desktop/MySQL/1/';
Set @d2 = concat( @d1, '20130114.txt');
load data local infile  @d2  into table Avaya_test (Agent_Name, Login_ID,ACD_Time);

Unfortunately after running, there is a error with the commment like below: "Error Code: 1064. You have an error in your SQL syntax ......"

Variable "@D2" is underlined in this code so it means that this error is caused by this variable.

Can you help me how to define correctly a variable of file name in LOAD DATA @variable infile ?

Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

A citation from MySQL documentation:

The file name must be given as a literal string. On Windows, specify backslashes in path names as forward slashes or doubled backslashes. The character_set_filesystem system variable controls the interpretation of the file name.

That means that it can not be a parameter of a prepared statement, stored procedure, or anything "server-side". The string/path evaluation must be done client side.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...