使用 Zend 选择到输出文件时出现访问被拒绝错误

发布于 2024-08-25 09:13:56 字数 833 浏览 10 评论 0原文

我正在尝试在服务器上转储 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 技术交流群。

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

发布评论

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

评论(4

空城缀染半城烟沙 2024-09-01 09:13:56

尽管我向相关用户授予了“所有权限”,但我是在每个数据库的基础上而不是在全局上执行此操作。然而使用 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

您的好友蓝忘机已上羡 2024-09-01 09:13:56

如果您遇到权限问题,您需要设置 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 of www-data and group of www-data, you need to add the mysql user account to the group on debian/ubuntu you can do usermod -a -G www-data mysql.

This is how I solved my issues on *nix boxes.

一身骄傲 2024-09-01 09:13:56

正常的 SELECT 可以工作吗?如果也没有,我会说这是密码错误的简单情况。如果正常的 SELECT 有效,请确保您将 OUTFILE 权限授予了确切的用户

 'someUser'@'localhost'

,而不是例如

  'someUser'@'%'

,如果我没记错的话,这两个帐户将被区别对待并具有单独的权限设置。

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

 'someUser'@'localhost'

and not for example

  'someUser'@'%'

if I remember correctly, those two accounts would be treated differently and have separate rights settings.

暗地喜欢 2024-09-01 09:13:56
>$ echo "select count(predicate),subject from TableA group by subject"  | mysql -u yourusername -p yourdatabasename > ~/XYZ/outputfile.txt

从这篇文章中获取的信息,该文章提供了未授予 FILE 权限的解决方法:
文件的查询输出出现访问被拒绝错误

>$ echo "select count(predicate),subject from TableA group by subject"  | mysql -u yourusername -p yourdatabasename > ~/XYZ/outputfile.txt

Snarfed from this post that has a workaround to the FILE permissions not being granted:
Query output to a file gives access denied error

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