What file and directory permissions are required for MySQL LOAD DATA INFILE?

前端 未结 4 1356
清歌不尽
清歌不尽 2020-12-17 00:26

I have a script that is trying to load some data into MySQL with LOAD DATA INFILE. For some reason, it works if the file is in the /tmp directory,

相关标签:
4条回答
  • 2020-12-17 01:01

    I've encountered a similar problem (unable to read a file in /tmp) and adding LOCAL after LOAD DATA INFILE fixed the problem.

    This Launchpad bug report might have some explanations as to why this is happening.

    0 讨论(0)
  • 2020-12-17 01:16

    Errcode 13 means missing permissions (in contrast to Errcode 2, which means the file does not exist). MySQL needs the file to be readable by anyone. THe permissions of your files are fine.

    We once had the same issue on a CentOS server and it was caused by AppArmor which forbid the MySQL application to access files not being listed in a whitelist in /etc/ap­par­mor.d/usr.​sbin.​mysqld. Maybe you have some kind of security suit which causes a similar behavior?

    As mentioned by others, using LOAD DATA INFILE LOCAL can be a workaround.

    0 讨论(0)
  • 2020-12-17 01:17
    mysqlimport --local <database> <infile>
    

    OR

    LOAD DATA LOCAL INFILE... should fix the issue.
    
    0 讨论(0)
  • 2020-12-17 01:22

    Errno 13 might be due to SELinux in case you are using a Linux server distro (for example, RedHat Enterprise Linux or CentOS). Check 'audit.log' to see if SELinux is complaining about your /tmp2 path. You can then add your path via semanage fcontext -a -t mysqld_db_t "/tmp2(/.*)?" and run restorecon -R /tmp2.

    However, the solution might be much simpler and I would have replied directly under your question (instead of providing an answer), if I only knew how..

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