views:

401

answers:

4

Hi, 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?

+1  A: 

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.

Pekka
Hey Pekka,yes, SELECT, INSERT, UPDATE etc works just fine and, according to phpmyadmin, someUser has "ALL PRIVILEGES"
Peter
@Peter strange. Done a `FLUSH PRIVILEGES` and/or restarted the server?
Pekka
@Peter can you try creating a 2nd user with all privileges and try it with that one, just to rule out duplicate records and such?
Pekka
@Pekka, tried both your suggestions (flush and new users with all privileges), still get the same access denied error
Peter
@Peter strange, then I don't know any further. Do you have the proper write rights in the directory you want to write the outfile to?
Pekka
@Pekka, yup, that seems to be OK. But, I'm wondering now, I'm using PhpMyAdmin to manage my users, but I seem to be missing the FILE privilege in my list of all privileges and I guess that's the one I need for OUTFILE. I tried granting it, trough sql input in phpmyadmin, but I get an error
Peter
@Pekka, almost there! "FILE" is only assigned as a GLOBAL permission, i just discovered, so granting someUser "FILE" right solved that problem, but now he is indeed complaining he can't write the file, so I guess, still some privilege errors to attend too!
Peter
Now I get the following error: Message: Mysqli statement execute error : Can't create/write to file '/var/www/ZendApp/application/backup/1268676308_table.sql' (Errcode: 13), yet that is a 777 chmod'ed directory. I guess I'm to tired to think straight, I'll search on tomorrow.
Peter
@Peter this sounds still strange, but I think you're definitely on the right track. Good luck tomorrow!
Pekka
A: 

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

Peter
A: 

Hello,

I need to do the same thing, and cannot find out how to set the GLOBAL PERMISSION of FILE - for example - it is neither in my /etc/mysql/my.cnf file, nor in either the /home/www/PhpMyAdmin-2.11.5 .../config.inc.php OR the sample config.inc.php file.

Is there a specific line to add to the /config.inc.php file that sets this? If so, what is it please?

Thanks,

Eddie

eddie
Eddie,You have to start up your phpmyadmin and go to the privileges tab. Choose the user you want to give the FILE permission, click the edit icon behind him/her and there you will find a list with the global privileges for that user and amongst them FILE. Just check FILE and confirm.Or, of course, you use your mysql admin or whatever you use to create and manage your mysql users and grand them the correct global permission there. But it's not something you do in a config.
Peter
A: 

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.

Anthony