I got this error while loading data when using docker[1]. The solution worked after I followed these next steps. Initially, I created the database and table datavault
and fdata
. When I tried to import the data[2], I got the error[3]. Then I did:
SET GLOBAL local_infile = 1;
- Confirm using
SHOW VARIABLES LIKE 'local_infile';
- Then I restarted my mysql session:
mysql -P 3306 -u required --local-infile=1 -p
, see [4] for user creation.
- I recreated my table as this solved my problem:
use datavault;
drop table fdata;
CREATE TABLE fdata (fID INT, NAME VARCHAR(64), LASTNAME VARCHAR(64), EMAIL VARCHAR(128), GENDER VARCHAR(12), IPADDRESS VARCHAR(40));
- Finally I imported the data using [2].
For completeness, I would add I was running the mysql version inside the container via docker exec -it testdb sh
. The mysql version was mysql Ver 8.0.17 for Linux on x86_64 (MySQL Community Server - GPL). This was also tested with mysql.exe Ver 14.14 Distrib 5.7.14, for Win64 (x86_64) which was another version of mysql from WAMP64. The associated commands used are listed in [5].
[1] docker run --name testdb -v //c/Users/C/Downloads/data/csv-data/:/var/data -p 3306 -e MYSQL_ROOT_PASSWORD=password -d mysql:latest
[2] load data local infile '/var/data/mockdata.csv' into table fdata fields terminated by ',' enclosed by '' lines terminated by '\n' IGNORE 1 ROWS;
[3] ERROR 1148 (42000): The used command is not allowed with this MySQL version
[4] The required client was created using:
CREATE USER 'required'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'required'@'%';
FLUSH PRIVILEGES;
- You might need this line
ALTER USER 'required'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
if you run into this error: Authentication plugin ‘caching_sha2_password’ cannot be loaded
[5] Commands using mysql from WAMP64:
mysql -urequired -ppassword -P 32775 -h 192.168.99.100 --local-infile=1
where the port is thee mapped port into the host as described by docker ps -a
and the host ip was optained using docker-machine ip
(This depends on OS and possibly Docker version).
- Create database datavault2 and table fdata as described above
load data local infile 'c:/Users/C/Downloads/data/csv-data/mockdata.csv' into table fdata fields terminated by ',' enclosed by '' lines terminated by '\n';
- For my record, this other alternative to load the file worked after I have previously created datavault3 and fdata:
mysql -urequired -ppassword -P 32775 -h 192.168.99.100 --local-infile datavault3 -e "LOAD DATA LOCAL INFILE 'c:/Users/C/Downloads/data/csv-data/mockdata.csv' REPLACE INTO TABLE fdata FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 ROWS"
and it successfully loaded the data easily checked after running select * from fdata limit 10;
.