授予数据库用户文件夹访问权限

发布于 2024-09-13 07:27:13 字数 446 浏览 6 评论 0原文

我正在尝试使用以下查询从 mysql 创建数据的 csv 导出:

SELECT * INTO OUTFILE '/tmp/result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM getfreepellets WHERE 1

并且出现以下错误:(

#1045 - Access denied for user '[username]'@'localhost' (using password: YES)

删除了用户名,但它是正确的)

我将如何授予该用户访问权限以在服务器?

编辑:

我将第一行更改为我的确切主路径,并收到相同的错误。

I'm trying to create a csv export of data from mysql using the following query:

SELECT * INTO OUTFILE '/tmp/result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM getfreepellets WHERE 1

And I get the following error:

#1045 - Access denied for user '[username]'@'localhost' (using password: YES)

(removed username but it's the right one)

How would I go about granting access to this user to create a file on the server?

Edit:

I changed the first line to be my exact home path, and received the same error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若能看破又如何 2024-09-20 07:27:13

您可能想要 GRANT 您的用户FILE 特权:

FILE 权限允许您使用 LOAD DATA INFILESELECT ... INTO OUTFILE 在服务器主机上读取和写入文件> 语句和 LOAD_FILE() 函数。

拥有FILE权限的用户可以读取服务器主机上任何世界可读或MySQL服务器可读的文件。 (这意味着用户可以读取任何数据库目录中的任何文件,因为服务器可以访问这些文件中的任何一个。)FILE 权限还允许用户在 MySQL 服务器所在的任何目录中创建新文件具有写权限。作为一项安全措施,服务器不会覆盖现有文件。

要授予 FILE 权限,请以 root 身份登录并执行:

GRANT FILE ON *.* TO 'your_user'@'localhost';

You may want to GRANT your user the FILE privilege:

The FILE privilege gives you permission to read and write files on the server host using the LOAD DATA INFILE and SELECT ... INTO OUTFILE statements and the LOAD_FILE() function.

A user who has the FILE privilege can read any file on the server host that is either world-readable or readable by the MySQL server. (This implies the user can read any file in any database directory, because the server can access any of those files.) The FILE privilege also enables the user to create new files in any directory where the MySQL server has write access. As a security measure, the server will not overwrite existing files.

To grant the FILE privilege, log-in as root and execute:

GRANT FILE ON *.* TO 'your_user'@'localhost';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文