如何让MySQL以其他用户身份写出文件? [英] How can I have MySQL write outfiles as a different user?

查看:73
本文介绍了如何让MySQL以其他用户身份写出文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个写入外文件的MySQL查询.我每天或每两天运行一次此查询,因此我希望能够删除输出文件而不必求助于su或sudo.我能想到的唯一方法是将outfile编写为由mysql用户以外的其他人拥有.这可能吗?

I'm working with a MySQL query that writes into an outfile. I run this query once every day or two and so I want to be able to remove the outfile without having to resort to su or sudo. The only way I can think of making that happen is to have the outfile written as owned by someone other than the mysql user. Is this possible?

我没有将输出重定向到文件,而是使用选择查询的INTO OUTFILE部分输出到文件.

I am not redirecting output to a file, I am using the INTO OUTFILE part of a select query to output to a file.

如果有帮助:


mysql --version
mysql  Ver 14.12 Distrib 5.0.32, for pc-linux-gnu (x86_64) using readline 5.2

推荐答案

输出文件是由mysqld进程创建的,而不是由您的客户端进程创建的.因此,输出文件必须归mysqld进程的uid和gid所有.

The output file is created by the mysqld process, not by your client process. Therefore the output file must be owned by the uid and gid of the mysqld process.

如果从可以访问文件的uid或gid下的进程访问文件,则可以避免必须使用sudo来访问文件.换句话说,如果mysqld创建由uid和gid"mysql"/"mysql"拥有的文件,则将您自己的帐户添加到"mysql"组中.然后,只要文件的许可模式包括组访问权限,您就可以访问该文件.

You can avoid having to sudo to access the file if you access it from a process under a uid or gid that can access the file. In other words, if mysqld creates files owned by uid and gid "mysql"/"mysql", then add your own account to group "mysql". Then you should be able to access the file, provided the file's permission mode includes group access.

您正在/tmp中删除目录权限模式为rwxrwxrwt的文件.粘性位('t')表示,仅当您的uid与文件的所有者相同时,才可以删除文件,而不管文件或目录的权限是什么.

You are deleting a file in /tmp, with a directory permission mode of rwxrwxrwt. The sticky bit ('t') means you can remove files only if your uid is the same as the owner of the file, regardless of permissions on the file or the directory.

如果将输出文件保存在未设置粘性位的另一个目录中,则应该可以正常删除该文件.

If you save your output file in another directory that doesn't have the sticky bit set, you should be able to remove the file normally.

从手册页中阅读有关粘性(8)的摘录:

Read this excerpt from the man page for sticky(8):

粘性目录

设置了粘滞位"的目录将成为仅附加目录,或更准确地说,将成为限制删除文件的目录.如果用户具有目录的写许可权,并且该用户是文件的所有者,目录的所有者或超级用户,则粘性目录中的文件只能由用户删除或重命名.此功能非常有用地应用于/tmp之类的目录,该目录必须是可公开写的,但应拒绝用户任意删除或重命名彼此文件的许可.

A directory whose `sticky bit' is set becomes an append-only directory, or, more accurately, a directory in which the deletion of files is restricted. A file in a sticky directory may only be removed or renamed by a user if the user has write permission for the directory and the user is the owner of the file, the owner of the directory, or the super-user. This feature is usefully applied to directories such as /tmp which must be publicly writable but should deny users the license to arbitrarily delete or rename each others' files.

这篇关于如何让MySQL以其他用户身份写出文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆