LOAD DATA INFILE Error Code : 13

后端 未结 19 2358
有刺的猬
有刺的猬 2020-11-28 02:37

In my remote MySQL, when I try to execute this query, I am getting the MySQL Error Code : 13.

Query -

LOAD DATA INFILE 
\'/httpdocs/.../.../testFile.         


        
相关标签:
19条回答
  • 2020-11-28 03:15

    If you're using cPanel or phpmyadmin to import the CSV using LOAD DATA then be sure to Enable Use LOCAL keyword. This worked for me in a shared server environment.

    0 讨论(0)
  • 2020-11-28 03:16

    This is normally a file access permissions issue but I see your already addressing that in point b, but it's worth going over just in case. Another option is to use LOAD DATA LOCAL INFILE which gets past a lot of these issues of file access permissions. To use this method though you need to copy the file locally (in the mysql folder is best) first. •If LOCAL is specified, the file is read by the client program on the client host and sent to the server.

    Insufficient Directory Permissions

    The error in this example has resulted because the file you are trying to import is not in a directory which is readable by the user the MySql server is running as. Note that all the parent directories of the directory the is in need to be readable by the MySql user for this to work. Saving the file to /tmp will usually work as this is usually readable (and writable) by all users. The error code number is 13. Source

    EDIT:

    Remember you will need permissions on not just the folder the holds the file but also the upper directories.

    Example from this post on the MySql Forums.

    If your file was contained within the following strucutre: /tmp/imports/site1/data.file

    you would need (I think, 755 worked) r+x for 'other' on these directories:

    /tmp

    /tmp/imports

    As well as the main two:

    /tmp/imports/site1

    /tmp/imports/site1/data.file

    You need the file and directory to be world-readable. Apologies if you've already tried this method but it may be worth retracing your steps, never hurts to double check.

    0 讨论(0)
  • 2020-11-28 03:18

    Adding the keyword 'LOCAL' to my query worked for me:

    LOAD DATA LOCAL INFILE 'file_name' INTO TABLE table_name
    

    A detailed description of the keyword can be found here.

    0 讨论(0)
  • 2020-11-28 03:20

    Error 13 is nothing but the permission issues. Even i had the same issue and was unable to load data to mysql table and then resolved the issue myself.

    Here's the solution:

    Bydefault the

    --local-infile is set to value 0

    , inorder to use LOAD DATA LOCAL INFILE it must be enabled.

    So Start mySQL like this :

    mysql -u username -p --local-infile

    This will make LOCAL INFILE enabled during startup and thus there wont be any issues using it !

    0 讨论(0)
  • 2020-11-28 03:22

    I use Ubuntu 12.04, I had to create the table, then do one of these:

    Using local gives an error (mysql 5.5):

    > LOAD DATA LOCAL INFILE "file.csv" INTO table inverter FIELDS TERMINATED BY ',';
    ERROR 1148 (42000): The used command is not allowed with this MySQL version
    

    LOAD DATA INFILE command is disabled by default for security reasons, re-enable it here and it should work: https://stackoverflow.com/a/16286112/445131

    You can import the csv-file using mysqlimport:

    mysqlimport -u root -p --fields-terminated-by=',' --local dbname tablename.csv
    

    Note the csv-file must have same name before the extension as the table.

    0 讨论(0)
  • 2020-11-28 03:22

    If you are using XAMPP on Mac, this worked for me:

    Moving the CSV/TXT file to /Applications/XAMPP/xamppfiles/htdocs/ as following

    LOAD DATA LOCAL INFILE '/Applications/XAMPP/xamppfiles/htdocs/file.csv' INTO TABLE `tablename` FIELDS TERMINATED BY ',' LINES TERMINATED BY ';'
    
    0 讨论(0)
提交回复
热议问题