使用 Zend 选择到输出文件时出现访问被拒绝错误
我正在尝试在服务器上转储 MySQL 表,并且我正在尝试在 Zend 中执行此操作。我有一个 model/mapper/dbtable 结构用于与表的所有连接,并且我将以下代码添加到映射器中:
public function dumpTable()
{
$db = $this->getDbTable()->getAdapter();
$name = $this->getDbTable()->info('name');
$backupFile = APPLICATION_PATH .
'/backup/' . date('U') .
'_' . $name . '.sql';
$query = "SELECT * INTO OUTFILE '$backupFile' FROM $name";
$db->query( $query );
}
我想这应该可以正常工作,但这
Message: Mysqli prepare error: Access denied for user 'someUser'@'localhost' (using password: YES)
就是结果。
我检查了 someUser 的用户权限他拥有相关数据库和表的所有权利。我一直在这里和网上四处寻找,通常打开用户的“所有”权限似乎是解决方案,但在我的情况下不是(除非我现在用疲惫的眼睛忽略了一些东西+我不想在我的生产服务器上打开“全部”)。
我在这里做错了什么?或者,有人知道在 Zend 中完成此操作的更优雅的方法吗?
I'm trying to make a dump of a MySQL table on the server and I'm trying to do this in Zend. I have a model/mapper/dbtable structure for all my connections to my tables and I'm adding the following code to the mappers:
public function dumpTable()
{
$db = $this->getDbTable()->getAdapter();
$name = $this->getDbTable()->info('name');
$backupFile = APPLICATION_PATH .
'/backup/' . date('U') .
'_' . $name . '.sql';
$query = "SELECT * INTO OUTFILE '$backupFile' FROM $name";
$db->query( $query );
}
This should work peachy, I thought, but
Message: Mysqli prepare error: Access denied for user 'someUser'@'localhost' (using password: YES)
is what this results in.
I checked the user rights for someUser and he has all the rights to the database and table in question. I've been looking around here and on the net in general and usually turning on "all" the rights for the user seems to be the solution, but not in my case (unless I'm overlooking something right now with my tired eyes + I don't want to turn on "all" on my production server).
What am I doing wrong here? Or, does anybody know a more elegant way to get this done in Zend?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尽管我向相关用户授予了“所有权限”,但我是在每个数据库的基础上而不是在全局上执行此操作。然而使用 outfile 所需的权限是 FILE,只能设置为 GLOBAL 权限
Although I gave "all privileges" to the user in question, I did this on a per database basis instead of globaly. The privilige needed to use outfile however is FILE, an can only be set as a GLOBAL permission
如果您遇到权限问题,您需要设置 mysql 运行所在的用户,以获得访问该文件夹所需的必要权限。例如,您有
/tmp/filedumps
,所有者为www-data
且组为www-data
,您需要添加 mysql将用户帐户添加到 debian/ubuntu 上的组中,您可以执行usermod -a -G www-data mysql
。这就是我解决 *nix 盒子问题的方法。
If you have an issue with permissions you need to set the user mysql runs under to have the necessary permissions needed to access that folder. For example you have
/tmp/filedumps
, with a owner ofwww-data
and group ofwww-data
, you need to add the mysql user account to the group on debian/ubuntu you can dousermod -a -G www-data mysql
.This is how I solved my issues on *nix boxes.
正常的 SELECT 可以工作吗?如果也没有,我会说这是密码错误的简单情况。如果正常的 SELECT 有效,请确保您将 OUTFILE 权限授予了确切的用户
,而不是例如
,如果我没记错的话,这两个帐户将被区别对待并具有单独的权限设置。
Does a normal SELECT work? If it doesn't either, I would say this is a simple case of a wrong password. If a normal SELECT works, make sure you granted the OUTFILE right to the exact user
and not for example
if I remember correctly, those two accounts would be treated differently and have separate rights settings.
从这篇文章中获取的信息,该文章提供了未授予 FILE 权限的解决方法:
文件的查询输出出现访问被拒绝错误
Snarfed from this post that has a workaround to the FILE permissions not being granted:
Query output to a file gives access denied error