Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load data Infile @variable into infile error

Tags:

mysql

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.

like image 794
Hawk360 Avatar asked Jan 25 '13 14:01

Hawk360


People also ask

What is load data infile?

The LOAD DATA INFILE statement reads rows from a text file into a table at a very high speed. If the LOCAL keyword is specified, the file is read from the client host. If LOCAL is not specified, the file must be located on the server. ( LOCAL is available in MySQL 3.22.

How do I enable local data Infile in MySQL?

To disable or enable it explicitly, use the --local-infile=0 or --local-infile[=1] option. For the mysqlimport client, local data loading is not used by default. To disable or enable it explicitly, use the --local=0 or --local[=1] option.


1 Answers

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.

like image 123
Binary Alchemist Avatar answered Sep 30 '22 06:09

Binary Alchemist