Page 1 of 1

going crazy with mysql system call

Posted: Mon Feb 15, 2010 1:25 pm
by attrcat
Hi everyone,

I have been trying to figure this one out for days now. What I want to do is execute the following command from a PHP script that doesn't have root-level permissions:

system("mysql DBNAME < FILENAME"); // Load mysql dumpfile into database

Running this from the command line works fine (as I have root permissions) but from the PHP script it does nothing. I tried adding the following line in the sudousers file:

username ALL =NOPASSWD: /usr/bin/mysql

but it seemed to have no effect. I've tried every combination of chmodding and chowning the script to no avail. I've even tried using sudo commands and shell_exec to work around the permissions problem.

Has anyone gotten this to work?

Re: going crazy with mysql system call

Posted: Mon Feb 15, 2010 2:05 pm
by infolock
Does the Database you're trying to dump into exist? If not it won't work.

Also, if root does not have a password try

Code: Select all

 
`mysql -u root DB_NAME < /path/to/dumpfile.sql`;
 

Re: going crazy with mysql system call

Posted: Mon Feb 15, 2010 2:25 pm
by attrcat
No, the database exists. Like I said, this line works perfectly when entered from the command line. It also doesn't prompt me for a password, though root does have one.

Re: going crazy with mysql system call

Posted: Mon Feb 15, 2010 4:16 pm
by infolock
Then it sounds to me like your www user doesn't have a proper mysql username/password.

You should just create a regular mysql user that has select, insert, update, create to the mysql db that you want. then, use the -uUSERNAME_HERE -pPASSWORDHERE approach and you'll be good 2 go. Even though you put the user= all access priv in there, doesn't mean that WWW. WWW does not have access to your shell account mysql login. so, again, just create a user, use the username/password approach, and life will be good again.