LOAD DATA INFILE Error Code : 13

后端 未结 19 2527
有刺的猬
有刺的猬 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:41

    CentOS 7+ Minimal Secure Solution: (should work with RedHat too)

    chcon -Rv --type=mysqld_db_t /YOUR/PATH/
    

    Explanation:

    Knowing that you applied the good practice of using secure-file-priv=/YOUR/PATH/ in my.cnf in order to use load data infile sql statement, you still see the following:

    ERROR 13 (HY000): Can't get stat of '/YOUR/PATH/FILE.EXT' (Errcode: 13 "Permission denied")

    That's caused by SELinux Enforcing mode, it's not secure to change the mode to Permissive or disable SELinux.
    In short,

    chcon change SELinux security context of a file or files/directories in a similar way to how 'chown' or 'chmod' may be used to change the ownership or standard file permissions of a file.

    SELinux Enforcing mode prevents mysqld from accessing directories with secure-context-type default_t, hence we need to change the secure-context-type of our path to mysqld_db_t. To see the current secure-context-type use the command:

    ls --directory --scontext /YOUR/PATH/
    

    In case you want to reset/undo the solution, then apply below command:

    restorecon -Rv /YOUR/PATH/
    

    The solution I shared is referenced in below links:

    https://wiki.centos.org/HowTos/SELinux
    https://mariadb.com/kb/en/selinux/
    https://linux.die.net/man/8/mysqld_selinux

提交回复
热议问题