This tutorial is about SQL privileges also known as Account Management. I used mysql database engine in our examples.
To manage your account there are 6 commands you should be familiar with: CREATE USER, DROP USER, GRANT, RENAME USER, REVOKE, SET PASSWORD
Let’s start from the syntax for CREATE USER action.
CREATE USER user_name [IDENTIFIED BY password];
The sample user creation looks like:
CREATE USER 'manager'@'localhost' IDENTIFIED BY 'mypass';
In MySQL, if you don’t specify the “@’localhost’” parameter, it’s “%” by default. This parameter value points the location from with You can connect to the database. You can provide IP address here. “%” means that user can connect from any host.
If you do not include IDENTIFIED BY clause, user would be able to connect without password. It’s insecure solution. try to avoid such situation.
To delete user simply write:
DROP USER 'manager'@'localhost';
or
DROP USER 'manager';
The Syntax for the GRANT command is:
GRANT privilege_name ON object_name TO {user_name |PUBLIC |role_name} [WITH GRANT OPTION];
Let me write just some examples of GRANT command:
GRANT ALL ON db1.* TO 'manager'@'localhost'; GRANT SELECT ON db2.invoice TO 'manager'@'localhost'; GRANT USAGE ON *.* TO 'manager'@'localhost' WITH MAX_QUERIES_PER_HOUR 90; GRANT UPDATE ON *.* TO 'manager'@'localhost' WITH MAX_QUERIES_PER_HOUR 90;
The post How to use SQL Privileges appeared first on Programmer's lounge.