going crazy with mysql system call

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
attrcat
Forum Newbie
Posts: 2
Joined: Mon Feb 15, 2010 1:22 pm

going crazy with mysql system call

Post 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?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: going crazy with mysql system call

Post 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`;
 
attrcat
Forum Newbie
Posts: 2
Joined: Mon Feb 15, 2010 1:22 pm

Re: going crazy with mysql system call

Post 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.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: going crazy with mysql system call

Post 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.
Post Reply