ERROR 1148: The used command is not allowed with this MySQL version

后端 未结 12 1157
感动是毒
感动是毒 2020-11-27 03:46

I am trying to load data into mysql database using

LOAD DATA LOCAL
INFILE A.txt
INTO DB
LINES TERMINATED BY \'|\';

the topic of this questi

相关标签:
12条回答
  • 2020-11-27 04:25

    SpringBoot 2.1 with Default MySQL connector

    To Solve this please follow the instructions

    1. SET GLOBAL local_infile = 1;

    to set this global variable please follow the instruction provided in MySQL documentation https://dev.mysql.com/doc/refman/8.0/en/load-data-local.html

    2. Change the MySQL Connector String

    allowLoadLocalInfile=true Example : jdbc:mysql://localhost:3306/xxxx?useSSL=false&useUnicode=yes&characterEncoding=UTF-8&allowLoadLocalInfile=true

    0 讨论(0)
  • 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;.
    0 讨论(0)
  • 2020-11-27 04:28

    All of this didn't solve it for me on my brand new Ubuntu 15.04.

    I removed the LOCAL and got this command:

    LOAD DATA
    INFILE A.txt
    INTO DB
    LINES TERMINATED BY '|';
    

    but then I got:

    MySQL said: File 'A.txt' not found (Errcode: 13 - Permission denied)
    

    That led me to this answer from Nelson to another question on stackoverflow which solved the issue for me!

    0 讨论(0)
  • 2020-11-27 04:29

    Also struggled with this issue, trying to upload .csv data into AWS RDS instance from my local machine using MySQL Workbench on Windows.

    The addition I needed was adding OPT_LOCAL_INFILE=1 in: Connection > Advanced > Others. Note CAPS was required.

    I found this answer by PeterMag in AWS Developer Forums.


    For further info:

    SHOW VARIABLES LIKE 'local_infile'; already returned ON and the query was:

    LOAD DATA LOCAL INFILE 'filepath/file.csv' 
        INTO TABLE `table_name`
        FIELDS TERMINATED BY ',' 
        ENCLOSED BY '"'
        LINES TERMINATED BY '\n'
        IGNORE 1 ROWS;
    

    Copying from the answer source referenced above:

    Apparently this is a bug in MYSQL Workbench V8.X. In addition to the configurations shown earlier in this thread, you also need to change the MYSQL Connection in Workbench as follows:

    1. Go to the Welcome page of MYSQL which displays all your connections
    2. Select Manage Server Connections (the little spanner icon)
    3. Select your connection
    4. Select Advanced tab
    5. In the Others box, add OPT_LOCAL_INFILE=1

    Now I can use the LOAD DATA LOCAL INFILE query on MYSQL RDS. It seems that the File_priv permission is not required.*

    0 讨论(0)
  • 2020-11-27 04:31

    I find the answer here.

    It's because the server variable local_infile is set to FALSE|0. Refer from the document.

    You can verify by executing:

    SHOW VARIABLES LIKE 'local_infile';
    

    If you have SUPER privilege you can enable it (without restarting server with a new configuration) by executing:

    SET GLOBAL local_infile = 1;
    
    0 讨论(0)
  • 2020-11-27 04:36

    I had the same issue while importing the CSV file in AWS MySQL 8.0 RDS.

    mysql> LOAD DATA LOCAL INFILE '/tmp/your.csv' INTO TABLE test.demo2 FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES;

    ERROR 1148 (42000): The used command is not allowed with this MySQL version

    1) Check for local_infile parameter

    mysql> SHOW VARIABLES LIKE 'local_infile';
    

    2) Log out from client and re-login using below parameter.

    mysql -u root -p -h rdsendpoint --local-infile=1
    

    3) Run the same command

    mysql> LOAD DATA LOCAL INFILE '/tmp/your.csv' INTO TABLE test.demo2 FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES;
    
    
    Query OK, 300 rows affected (0.01 sec)
    
    Records: 300  Deleted: 0  Skipped: 0  Warnings: 0
    
    0 讨论(0)
提交回复
热议问题