MySQL 会话/用户的文件权限
当有人在我的 MySQL 数据库中注册时,此功能必须起作用:
mysql_query("SELECT mail
FROM users
INTO OUTFILE 'test.txt'");
但我收到错误
用户“registerdb”@“%”的访问被拒绝(使用密码:YES)
那么我如何向会话/用户授予文件写入权限?
When someone is registerd in my MySQL database, this function must work:
mysql_query("SELECT mail
FROM users
INTO OUTFILE 'test.txt'");
But I get the error
Access denied for user 'registerdb'@'%' (using password: YES)
So how I give the FILE writing permission to the session/user?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查该用户的权限:
如果没有列出 FILE 权限,只需添加它:
,然后:
但请注意,通过授予
*.*
上的 FILE 权限,您实际上是 授予该用户对服务器上任何文件的完全访问权限。限制 限制可以读取文件的位置写入后,将 secure_file_priv 系统设置为特定目录。
Chek for permissions of that user:
If there no listed FILE permission, just add it:
and then:
But beware for by doing granting the FILE permission on
*.*
you are essentially giving that user full access to any file the server.To limit limit the location in which files can be read and written, set the secure_file_priv system to a specific directory.
您需要先删除 MySQL 之外的文件,MySQL 中没有函数可以删除或覆盖文件。
这是一项安全措施,您应该对此表示感谢。
请注意,弄清楚 MySQL 存储其文件的确切位置可能很棘手。
我通常使用
生成的错误,为您提供
SELECT ... INTO OUTFILE
将写入的当前数据库的完整路径。您可以使用多种方法来删除(或更好地移动)文件,例如
cron-job
。您甚至可以编写一个自定义 UDF 来为您执行删除操作,尽管这是一个巨大的安全风险,而这样做的程序员应该遭受比可怕的事情更糟糕的命运。
另一种选择是
我不 100% 确定您可以使用函数来创建 OUTFILE 参数,如果不是,您将必须选择该值并使用动态 SQL 将其注入到查询中。
您可以使用以下方式获取最新文件:
You need to delete the file outside of MySQL first, there is no function in MySQL that can delete or overwrite a file.
This is a security measure and you should be thankful for that fact.
Note that it can be tricky to figure out where exactly MySQL stores its files.
I usually use
The error that generates, gives you the full path for the current database that
SELECT ... INTO OUTFILE
will write to.You can use a variety of ways to delete (or better move) the file, a
cron-job
comes to mind.You could even write a custom UDF that will do the deleting for you although that is a mayor security risk and programmers who do this deserve a fate worse than something horrid.
Another option is to do
I'm not 100% sure you can use a function to create the
OUTFILE
parameter, if not you will have to select that value and inject it into the query using dynamic SQL.You can get the latest file using: