加载数据文件错误代码:13

2021-11-20 00:00:00 file-io mysql

在我的远程 MySQL 中,当我尝试执行此查询时,我收到 MySQL 错误代码:13.

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

查询 -

LOAD DATA INFILE 
'/httpdocs/.../.../testFile.csv'
INTO TABLE table_temp
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\\r \\n'
(sku, qty);

错误代码:13 Can't get stat of '/httpdocs/.../.../testFile.csv' (Errcode: 2)

一个.数据库用户登录具有所有授予权限.

a. The database userlogin has all the grant priviliges.

CREATE USER 'userName'@'%' IDENTIFIED BY '************';

GRANT ALL PRIVILEGES ON * . * TO 'userName'@'%' IDENTIFIED BY '************' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

GRANT ALL PRIVILEGES ON `userName\_%` . * TO 'userName'@'%';

B.我还将文件和文件夹权限设置为 chmod 777 (rwxrwxrwx)使用FTP工具

b. I have also set the file and folder permission to chmod 777 (rwxrwxrwx) using FTP Tool

推荐答案

我知道这个帖子很旧,但是搜索结果中仍然出现这个.我在网上找不到这个问题的解决方案,所以我最终自己解决了这个问题.如果您使用的是 Ubuntu,那么有一个名为Apparmor"的程序会阻止 MySQL 看到该文件.如果您希望 MySQL 能够从tmp"目录读取文件,您需要执行以下操作:

I know that this post is old, but this still comes up in search results. I couldn't find the solution to this problem online, so I ended up figuring it out myself. If you're using Ubuntu, then there is a program called "Apparmor" that is preventing MySQL from seeing the file. Here's what you need to do if you want MySQL to be able to read files from the "tmp" directory:

sudo vim /etc/apparmor.d/usr.sbin.mysqld

进入文件后,您将看到一堆 MySQL 可以使用的目录.将行 /tmp/** rwk 添加到文件中(我不确定它放在哪里很重要,但这里是我放置它的位置的示例):

Once you are in the file, you're going to see a bunch of directories that MySQL can use. Add the line /tmp/** rwk to the file (I am not sure that it matters where, but here is a sample of where I put it):

  /etc/mysql/*.pem r,

  /etc/mysql/conf.d/ r,

  /etc/mysql/conf.d/* r,

  /etc/mysql/*.cnf r,

  /usr/lib/mysql/plugin/ r,

  /usr/lib/mysql/plugin/*.so* mr,

  /usr/sbin/mysqld mr,

  /usr/share/mysql/** r,

  /var/log/mysql.log rw,

  /var/log/mysql.err rw,

  /var/lib/mysql/ r,

  /var/lib/mysql/** rwk,


  /tmp/** rwk,


  /var/log/mysql/ r,

  /var/log/mysql/* rw,

  /var/run/mysqld/mysqld.pid w,

  /var/run/mysqld/mysqld.sock w,

  /run/mysqld/mysqld.pid w,

  /run/mysqld/mysqld.sock w,

现在您需要做的就是重新加载 Apparmor:

Now all you need to do is reload Apparmor:

sudo /etc/init.d/apparmor reload

请注意,我使用了vim",但可以将其替换为您最喜欢的、您知道如何使用的文本编辑器.

Note I used "vim", but substitute that with whatever your favorite text editor is that you know how to use.

相关文章