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

标签 mysql privileges mysql-error-1045

我正在尝试使用以下查询从 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)

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

我将如何授予此用户访问权限以在服务器上创建文件?

编辑:

我将第一行更改为我的确切主页路径,但收到了同样的错误。

最佳答案

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

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.

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

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

关于mysql - 授予数据库用户文件夹访问权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3431500/

相关文章:

postgresql - Postgres : how to grant an user to add more users to a group

php - MediaWiki/Apache/PHP/MySQL 与 OpenSSL 的数据库连接需要 SSL

Java MySQL 查询问题

javascript - mysql Node js的问题

javascript - PHP/MySQL : Register isn't creating new users in database

python - Pandas 将表写入 MySQL : "unable to rollback"

mysql - GROUP BY 和 ORDER BY <- ORDER BY TIMESTAMP 被忽略

oracle - 同义词和基础表的访问权限

mysql - Win7 上全新完整安装 MySQL。没有提示输入用户名?

windows - 如果 ImpersonateSelf() 失败后的 RevertToSelf() 会致命吗?