0

Ι am trying to import a csv file into an existing mysql 5.7 table.

Here is the command (the db is in docker with bind mount for persistence)

mysql -h 127.0.0.1 -uroot -prootpass --local_infile=1 jira_statistics -e "LOAD DATA LOCAL INFILE '/home/centos/bugs.csv' INTO TABLE bugs FIELDS TERMINATED BY ','"

However:

mysql> select * from bugs;
Empty set (0.05 sec)

No error in the command line nor the docker logs of mysql container.

What is more, the exit code of the mysql command is 0 !

Any ideas?

  • Instead of doing it entirely from the shell, what happens if you first bring up mysql, then enter the LOAD command? – Rick James Feb 14 at 16:44
  • it fails with foreign key constraints (which is true); however I need the exit code because I will be scripting this; – pkaramol Feb 14 at 16:47
0

Encapsulate the LOAD in a Stored Procedure. In there, capture the error and expose it to your script.

However, if LOAD DATA is not allowed in a Stored Proc, then you really need to write application code, not depend on on-line shell scripts.

  • I think LOAD DATA is disallowed in stored procedures; – pkaramol Feb 14 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.