2

I am trying to write a stored procedure to import CSV data from local system to mySQL tables. I do not want to use import wizard as I want SP to create, import and display time taken to import.

However, when I execute this statement:

LOAD DATA INFILE 'path/to/your/file.csv' INTO TABLE your_table_name FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES; -- Use this if your file has a header row

I receive Error Code: 1290. The MySQL server is running with the --secure-file-priv option so it cannot execute this statement.

Things I have tried:

  • Transfer files to path in secure_file_priv C:\ProgramData\MySQL\MySQL Server 8.0\Uploads\
  • Updated 'secure_file_priv'="" and 'local_infile'=1 in my.ini file at various locations, getting default file location from cmd, but the path is not updated when I check their updated values. I restart mySQL server each time after making changes but no luck.
  • Unchecked Safe updates in mySQL preferences

Please let me know any workaround.

4
  • Yep, these are the possible solutions for this behaviour. If neither worked, then you probably made a mistake in implementing those solutions. Please show the exact load data statement with the file path C:\ProgramData\MySQL\MySQL Server 8.0\Uploads\ and what error message you got when you tried it. Commented Sep 14 at 6:38
  • what does SHOW VARIABLES LIKE 'datadir'; produce ? Commented Sep 14 at 7:21
  • This question may have an answer here: stackoverflow.com/questions/1045910/… Commented Sep 28 at 3:52
  • You can try to use the FastTransfer Tool to import your csv data into your table. I don't know the size of your csv file but the tool is very fast to import data into severals RDBMS. Commented Oct 8 at 9:33

1 Answer 1

0

Your question says you have a .csv file on your local machine you want to slurp into a MySql table. I guess that is a remote machine.

Your question didn’t say you tried LOAD DATA LOCAL INFILE with the LOCAL modifier, but that’s what you need. Here’s a write up of the local/nonlocal mischegoss. https://dev.mysql.com/doc/refman/8.4/en/load-data.html#load-data-file-location

I hope this is helpful.

You might try getting this to work outside your stored code first, then put it into that code. Debugging stored code can be a pain in the neck.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.