LOAD DATA INFILE Error Code : 13

后端 未结 19 2361
有刺的猬
有刺的猬 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:22
    1. checkout this system variable local_infile is on
     SHOW VARIABLES LIKE 'local_infile';
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | local_infile  | ON    |
    +---------------+-------+
    

    If not, restart mysqld with:

    sudo ./mysqld_safe --local-infile
    
    1. change you csv file to /tmp folder so that it mysqls can read it.

    2. import to db

    mysql> LOAD DATA INFILE '/tmp/a.csv'  INTO TABLE table_a  FIELDS TERMINATED BY ','  ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 ROWS;
    Query OK, 18 rows affected (0.17 sec)
    Records: 18  Deleted: 0  Skipped: 0  Warnings: 0
    
    0 讨论(0)
  • 2020-11-28 03:22
    1. GRANT ALL PRIVILEGES ON db_name.* TO 'db_user'@'localhost';
    2. GRANT FILE on .* to 'db_user'@'localhost' IDENTIFIED BY 'password';
    3. FLUSH PRIVILEGES;
    4. SET GLOBAL local_infile = 1;
    5. Variable in the config of the MYSQL "secure-file-priv" must be empty line!!!
    0 讨论(0)
  • 2020-11-28 03:26

    OLD:

    LOAD DATA INFILE '/home/root12/Downloads/task1.csv' INTO TABLE test.task FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 ROWS;
    
    File '/home/root12/Downloads/task1.csv' not found (Errcode: 13 - Permission denied)
    

    NEW WORKING FOR ME:

    LOAD DATA LOCAL INFILE '/home/root12/Downloads/task1.csv' INTO TABLE test.task FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 ROWS;
    
    Query OK, 500 rows affected, 284 warnings (1.24 sec)
    Query OK, 5000 rows affected, 2846 warnings (1.24 sec)
    
    0 讨论(0)
  • 2020-11-28 03:28

    If you are using Fedora/RHEL/CentOO you can disable temporarily SELinux:

    setenforce 0
    

    Load your data and then enable it back:

    setenforce 1
    
    0 讨论(0)
  • 2020-11-28 03:29

    I had a lot of trouble to fix this, there are two things to do :

    • update file /etc/mysql/my.cnf with local-infile =1 at two locations after [mysql] paragraphs (this allows to use LOCAL INFILE sql command).

    • update via sudo gedit /etc/apparmor.d/usr.sbin.mysqld so apparmor will allow you to write into the special files of /var/www/ by adding the lines:

    /name of your directory/ r,

    /name of your directory/* rw,

    The name of your directory can be as /var/www/toto/ (this allows to use the directory where your files are located).

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

    There is one property in mysql configuration file under section [mysqld] with name - tmpdir

    for example:

    tmpdir = c:/temp (Windows) or tmpdir = /tmp (Linux)
    

    and LOAD DATA INFILE command can perform read and write on this location only.

    so if you put your file at that specified location then LOAD DATA INFILE can read/write any file easily.

    One more solution

    we can import data by following command too

    load data local infile
    

    In this case there is no need to move file to tmpdir, you can give the absolute path of file, but to execute this command, you need to change one flag value. The flag is

    --local-infile
    

    you can change its value by command prompt while getting access of mysql

    mysql -u username -p --local-infile=1
    

    Cheers

    0 讨论(0)
提交回复
热议问题