Friday, February 01, 2008

MySQL : grant command

The GRANT function is used both to create new users, and to assign privileges to users.
mysql>GRANT SELECT, INSERT, UPDATE, DELETE
->ON widgets.* TO widgetAdmin@localhost
->IDENTIFIED BY 'ilovewidgets';

Assuming that the user widgetAdmin did not yet exist when this query is executed, both the user and db tables will be updated with the necessary rows.

The above is taken from dev.mysql.com.

You can also use assign all privileges to a user on a certain database. Following is the syntax.

mysql> GRANT ALL PRIVILEGES ON
    -> test.* TO 'ketan'@'localhost'
    -> IDENTIFIED BY 'ketans_password';

I find this command exceedingly useful ! A quick way to set up privileges of a user on a db.

5 comments:

Ketan said...

Thanks Christoff !

Keep visiting my blog. I plan to become active now here :-).

Ketan

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...

It is remarkable, it is a valuable piece

Unknown said...

Here in this command we are giving permission to ip address, i have a problem that my ip address is changing when my vplan is restarting. how can i give permission by using system name i.e domain name in alter command

Ketan said...

What is your command Pradeep ?