MySQL: Add User + Privileges

Let's say we want to add a new user "Erick Broski" with SELECT privileges on database "userlistdb".

mysql> grant SELECT on userlistdb.* to 'erick.broski'@'localhost';

Make sure to set his password:

mysql> set password for 'erick.broski'@'localhost'= password('h@ckm3');

Now, lets say we want to give "Erick Broski" all privileges on database "ssnumbersdb".

mysql> grant ALL PRIVILEGES on ssnumbersdb.* to 'erick.broski'@'localhost';

Additionally, we can limit the access to a DB by the user's IP.

 mysql> RENAME USER 'erick.broski'@'localhost' TO 'erick.broski'@'192.168.%';

Show all users.

mysql> SELECT user FROM mysql.user;

 

 


Tagged under: mysql, privileges, grant all