Wednesday, May 11, 2011

MySql - Manage users and user roles

I cam across to create a new user with restricted access for the database. Just to allow user to view, update and delete.
The below is just a brief step to do the task. To learn and understand , it would be better to look at mysql online manual


Step 1: Go to command propmt, and login to mysql

[root@sun ~]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3384
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
* make sure username has the rights to create and grant access to new users :)

mysql> GRANT SELECT,INSERT,UPDATE,DELETE on {TABLENAME}.* to '{USERNAME}'@'{DOMAINNAME}';
Query OK, 0 rows affected (0.04 sec)


The above user is created with password as null.

the other alternative is to create a user first,

CREATE USER '{USERNAME}'@'{DOMAINNAME}' IDENTIFIED BY 
'{PASSWORD}';
and than
GRANT SELECT,INSERT,UPDATE,DELETE on {TABLENAME}.* to 
'{USERNAME}'@'{DOMAINNAME}'; 
 
Hope it helps someone.
Feel free to provide your suggestion.

No comments:

Post a Comment