Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LOAD DATA is not allowed in stored procedures

I have a case to import data into mysql automatically every 6pm. data to be imported is "data.txt".

I created in mysql like this:

CREATE EVENT EVENT_NAME
ON SCHEDULE EVERY '18: 00:00 'DAY
DO
LOAD DATA LOCAL INFILE 'd :/ data.txt'
INTO TABLE table_name
FIELDS terminated BY ','
LINES terminated BY '\ n'
(atribut1, atribut2, atribut3);

if i just write like this

LOAD DATA LOCAL INFILE 'd :/ data.txt'
INTO TABLE table_name
FIELDS terminated BY ','
LINES terminated BY '\ n'
(atribut1, atribut2, atribut3);

the query was successfully executed

but if i write the code like a fist code instead there is an error "LOAD DATA is not allowed in stored procedures". is it really like that? if it's like that how do i to handle such cases? thanks in advance sorry for my bad english

like image 448
Dhoni Eko Wahyu Nugroho Avatar asked Nov 13 '22 02:11

Dhoni Eko Wahyu Nugroho


1 Answers

Indeed, you are out of luck.

You will need to resort to an external mechanism in order to automate this import (such as a cron job).

You can submit arbitrary statements from outside MySQL by calling the mysql command-line client like this:

    shell > mysql [options] -D [database] -e "LOAD DATA INFILE..."
like image 199
RandomSeed Avatar answered Nov 15 '22 06:11

RandomSeed