在 MySQL 中创建/写入权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2268717/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:17:51  来源:igfitidea点击:

Create/Write Permissions in MySQL

sqlmysqldatabaselinux

提问by mropa

I am experiencing some permission problems with my SELECT ... INTO OUTFILEstatement.

我的SELECT ... INTO OUTFILE声明遇到了一些许可问题。

When I log into my database and do a simple export command, eg:

当我登录到我的数据库并执行一个简单的导出命令时,例如:

mysql> select * from XYZ into outfile '/home/mropa/Photos/Desktop/TEST.txt';

I get the respond:

我得到回应:

ERROR 1 (HY000): 
Can't create/write to file '/home/mropa/Photos/Desktop/TEST.txt' 
(Errcode: 13)

However, when I simply write:

但是,当我简单地写:

mysql> select * from XYZ into outfile 'TEST.txt';
Query OK, 8287 rows affected (0.73 sec)

The file is written into the directory /var/lib/mysql/XYZ. I looked into the file /etc/apparmor.d/usr.sbin.mysqldwhere mysql seems to define the reading and writting permissions but I don't really know how to modify it.

文件被写入目录/var/lib/mysql/XYZ。我查看了/etc/apparmor.d/usr.sbin.mysqldmysql似乎定义读写权限的文件,但我真的不知道如何修改它。

How can I give myself permission to export a mysql table into any directory I like?

我如何授予自己将 mysql 表导出到我喜欢的任何目录的权限?

采纳答案by dnagirl

The issue is directory permissions. mysqld does not run as current_user. Add the mysqld user to the group that has write permissions on your target directories (convenient, but not as secure) or remember to change your target directory permissions before and after you write the outfile.

问题是目录权限。mysqld 不作为 current_user 运行。将 mysqld 用户添加到对您的目标目录具有写入权限的组(方便,但不那么安全)或记住在写入输出文件之前和之后更改您的目标目录权限。

回答by user262976

you can create a directory that is writable by the user that is running mysqld (usually "mysql") and write the file there. For intance:

您可以创建一个可由运行 mysqld 的用户(通常是“mysql”)写入的目录并将文件写入那里。例如:

chmod a+w /home/mropa/mysql

回答by vezult

See https://wiki.ubuntu.com/DebuggingApparmorfor information on debugging/disabling apparmor profiles.

有关调试/禁用 apparmor 配置文件的信息,请参阅https://wiki.ubuntu.com/DebuggingApparmor

It may not be an apparmor issue in particular. The user that mysqld is running as may not have permissions to write to the folder you specified. Check the permission on the destination directory/file.

这可能不是特别的 apparmor 问题。运行 mysqld 的用户可能无权写入您指定的文件夹。检查目标目录/文件的权限。

回答by Layke

This sounds like you don't have access to that particular folder. You should add mysql to the group owner of that particular location.

这听起来像您无权访问该特定文件夹。您应该将 mysql 添加到该特定位置的组所有者。

I don't know under what user you are running mysql under, however,

我不知道你在哪个用户下运行 mysql,但是,

chown mysql:mysql on /home/mropa/Photos/Desktop/logs would mean that mysql user and mysql group is the owner so has permission. You then need to make sure that the permissions include writing but that should be sufficient.

chown mysql:mysql on /home/mropa/Photos/Desktop/logs 意味着 mysql 用户和 mysql 组是所有者,因此具有权限。然后,您需要确保权限包括写入,但这应该足够了。

Chown Command

周命令

回答by tony gil

mysql usually runs under user mysqld. permissions may be solved directly with apparmor. see this answer

mysql 通常在 user 下运行mysqld。权限可以直接用apparmor解决。看到这个答案