If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > creating/granting privs on table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-18-07, 14:10
ScottAN ScottAN is offline
Registered User
 
Join Date: Aug 2007
Posts: 1
creating/granting privs on table

I am trying to create an auto install script for a popular PHP web application. I am trying to create a database, create a user and grant privileges to the user all in PHP. I use the following code to try and do this...

PHP Code:
mysql_query("create database ".$db);
// make and grant privs for db user
mysql_query("GRANT ALL PRIVILEGES ON ".$db.".* TO '".$db_user."' IDENTIFIED BY '".$db_user_pass."'"); 
My problem is all of the DBs that are created are listed as having the host as % in the 'mysql' database on the server. When I look at the privileges tab when viewing the database in phpMyAdmin I see this:

username_database % wildcard: username_dbusername

Instead of % it should be localhost and instead of wildcard: username_dbusername it should say database-specific. When viewing databases in CPanel it lists the database and the user but it does not show that the user was added to the database.

Can anyone help?!
Reply With Quote
  #2 (permalink)  
Old 08-18-07, 15:47
shadowdancer shadowdancer is offline
Registered User
 
Join Date: Jul 2007
Posts: 4
Probably you have to change the syntax to become like this:

Code:
mysql_query("GRANT ALL PRIVILEGES ON ".$db.".* TO '".$db_user."@"localhost"' IDENTIFIED BY '".$db_user_pass."'");
Reply With Quote
  #3 (permalink)  
Old 08-20-07, 07:57
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
Bear in mind that in order for this to function you need to run the GRANT syntax as the root user. I'm sure you're aware of this and are probably connecting as root to your database, but I would urge you to be VERY careful about how you go about this. Especially if you allow someone to input information directly from a web browser to set this up. Escape your input and sanatize it, the last thing you want is someone with root mysql privileges adding their own users and messing up databases/tables.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On