How do I upload a CSV file into Mysql on MacOS?

Viewed 855

I am using the following lines of code:

LOAD DATA LOCAL INFILE 'CA_DRU_proj_2010-2060.csv'
INTO TABLE pop_proj
FIELDS TERMINATED BY ' , '
ENCLOSED BY ' " '
LINES TERMINATED BY ' \n '
IGNORE 1 LINES;

The error I am receiving is:

Error Code: 1148. The used command is not allowed with this MySQL version

My version of mysql is version 8.0.16

1 Answers

You need both the server and the client to enable local-infile import.

The server needs to enable local_infile=1. You can put this in your my.cnf options file, or you can enable it dynamically on a running server with SET GLOBAL local_infile=1;

You also need to tell the client to allow it. Do this by starting the client:

mysql --local-infile=1 ...

Since MySQL 8.0.19, the error message is more clear:

ERROR 3950 (42000): Loading local data is disabled; this must be enabled on both the client and server side

See also:


Update: If you use MySQL Workbench instead of the mysql command line client, you can enable local-infile in the options on the Advanced tab of your connection profile. See highlighted line below:

enter image description here

Related