#1  
Old 22nd May 2005, 13:43
mcfly mcfly is offline
Junior Member
 
Join Date: May 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default MySQL Privileges

I've a little problem: I have a script that writes the privileges of new MySQL users into the mysql.db table. Now it seems as if this table has changed from MySQL 3.23 to MySQL 4.0, i.e., there are now more privileges columns than before.

Now for MySQL 3.23 I'm running this command:

Code:
INSERT INTO `db` (`Host`, `Db`, `User`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`) VALUES ('localhost', 'database_name', 'database_user', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y');
but for MySQL 4.0 I'd have to change it. But it's bothersome to program a routine that finds out which MySQL version is used or which privileges columns are available for the database in question in order to form the right SQL INSERT statement.
So my question is: is there an easier way to do this?
Reply With Quote
Sponsored Links
  #2  
Old 22nd May 2005, 19:44
peter peter is offline
Junior Member
 
Join Date: May 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can use MySQL's GRANT command:

Code:
GRANT ALL PRIVILEGES ON test_db.* TO 'test_db_user'@'localhost';
GRANT ALL PRIVILEGES ON test_db.* TO 'test_db_user'@'%';
GRANT ALL PRIVILEGES ON test_db.* TO 'test_db_user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON test_db.* TO 'test_db_user'@'%' IDENTIFIED BY 'password';
You can find details about it here: http://dev.mysql.com/doc/mysql/en/grant.html

Peter
Reply With Quote
  #3  
Old 23rd May 2005, 09:13
mcfly mcfly is offline
Junior Member
 
Join Date: May 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What's the
Code:
IDENTIFIED BY 'password'
for?
Reply With Quote
  #4  
Old 24th May 2005, 02:34
joe joe is offline
Junior Member
 
Join Date: Apr 2005
Posts: 23
Thanks: 0
Thanked 1 Time in 1 Post
Default

It creates a password for the user you are granting privileges to. Just like normal shell accounts use passwords to protect privileges, the same goes for database users.
__________________
Joe Topjian
email: joe@adminspotting.net
web: http://adminspotting.net
Reply With Quote
  #5  
Old 26th May 2005, 19:00
peter peter is offline
Junior Member
 
Join Date: May 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

if you use the
Code:
IDENTIFIED BY 'password'
clause, and the user doesn't exist in the user table, it will be created with the specified password. If the user is already existing, its password will be changed.

Peter
Reply With Quote
Reply

Bookmarks

Thread Tools
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 On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:19.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.