User Account Management
User Privileges
Administrative Privileges
Database Access Privileges
Creating and Rename User Account
Drop User Account
Grant Privileges
Revoke Privileges
Routines and Triggers
2. AJENDA
User Account Management
User Privileges
Administrative Privileges
Database Access Privileges
Creating and Rename User Account
Drop User Account
Grant Privileges
Revoke Privileges
Routines and Triggers
2 out of 22
3. USER MANAGEMENT
To manage MySQL account for clients that connect to MySQL server
to access databases.
* The grant tables used to store account information.
* The SQL statements used for account management.
3 out of 22
4. USER ACCOUNT MANAGEMENT
In mysql the concept of account is combined with two things: a
user name and a host name.
When you connect to the server, it checks only the user name that
you specify, but also from what host you are connecting.
Format: ‘user_name’@ ‘host_name’
Ex: ‘rose’@‘localhost’
Account management statements such as CREATE
USER,GRANT,REVOKE OR SET PASSWORD.
4 out of 22
5. USER PRIVILEGES
It mean a special advantages is given to an user account like
select,insert,update,delete etc at different levels.
Two types of privileges, one is administrative privileges and
other is database privileges.
Administrative privileges access the account in mysql.
Database privilege control to access the data stored in
databases.
5 out of 22
8. CREATING & RENAME USER ACCOUNT
CREATE USER creates a new account and optionally assign it a
password.
It does not grant any privileges.
Syntax:
CREATE USER ‘USER_NAME’ @ ‘HOST_NAME’ IDENTIFIED BY
‘PASSWORD’;
-Ex: create user ‘rose’@ ‘localhost’ identified by ‘stem123’;
8 out of 22
9. CREATING & RENAME USER ACCOUNT
The above statement creates an account for rose@localhost and
assign the account a password of “stem123”.
Alternatively we can give GRANT to create the account and grant it
privileges at the same time.
-Ex: Grant all on *.* to ‘rose’@ ‘localhost’ identified by ‘stem123’;
To rename the user account use this statement as RENAME USER.
9 out of 22
10. CREATING & RENAME USER ACCOUNT
Syntax:
RENAME USER ‘old_user_name’@ ‘old_host_name’ To
‘new_user_name’@ ‘old_host_name’;
Ex: Rename user ‘rose’@ ‘localhost’ to ‘flower’@ ‘localhost’;
To check the created user in MySQL by using Select command.
Syntax:
SELECT USER,HOST FROM MYSQL.USER;
It will show the list of user with hostname in the user account.
10 out of 22
11. CREATING & RENAME USER ACCOUNT
How to set password for a user and change the password for a user.
Syntax:
SET PASSWORD for [‘USER_NAME’@ ‘HOST_NAME’]=PASSWORD(‘12345’);
After change the password to get update in that user account we
need to do flush privileges to get update.
Syntax:
FLUSH PRIVILEGES;
11 out of 22
12. DROP USER ACCOUNT
It deletes all records for the account from any grant table in which
they exist.
It revokes all privileges for an existing account and then removes
the account.
To revoke the privileges without removing the account itself, use
the revoke statement.
Syntax:
DROP USER ‘user_name’@ ‘host_name’;
Ex: drop user ‘flower’@ ‘localhost’;
12 out of 22
13. GRANT PRIVILEGES
It is use to give the authority for the mysql user accounts
databases.
To see grant privileges in an account.
Syntax: SHOW GRANTS;
Grant privileges can exists in different levels.
13 out of 22
14. GRANT PRIVILEGES
1)Global levels:
Any privileges can be granted globally. Global privileges are
quite powerful and are normally granted only administrative
accounts. Applied to all databases on a given server.
Syntax: GRANT ALL ON *.* to ‘user’@‘host_name’
Ex: grant all on *.* to ‘rose’@‘localhost’;
In this we can do insert, delete,update,etc in global level
statement.
14 out of 22
15. GRANT PRIVILEGES
2)Database level:
Some privileges are granted for specific databases:
ALTER,CREATE,CREATE TEMPORARY TABLES,CREATE VIEW,
DELETE, DROP, GRANT, OPTION,INDEX,INSERT,LOCK TABLES,
SELECT,SHOW VIEW AND UPDATE. A database level privileges
applies for all tables and stores routines in the databases.
Syntax: GRANT ALL ON DATABASE_NAME .* to ‘USER’@
‘HOST_NAME’;
Ex: grant all on redrose.* to ‘rose’@‘localhost’;
15 out of 22
16. GRANT PRIVILEGES
3)Table level:
Some privileges granted for specific tables:
ALTER,CREATE,DELETE,DROP,GRANT,OPTION,INDEX,INSERT,SELEC
T AND UPDATE. A table-level privilege applies to specific table in a
database.
Syntax: GRANT ALL ON DB_NAME.TABLE_NAME to ‘USER’@‘HOST_NAME’;
Ex: grant all on redrose.price to ‘rose’@‘localhost’;
16 out of 22
17. GRANT PRIVILEGES
4)Column level:
Some privileges granted for specific table columns:
INSERT,SELECT AND UPDATE.
Syntax: GRANT ALL ON DB_NAME.TBLE_NAME.COLUMN_NAME TO
‘USER’@‘HOST_NAME’;
Ex: grant all on redrose.price.low to ‘rose’@ ‘localhost’;
5)Routine level:
Some privileges can be granted for specific stored routines:
EXECUTE,ALTER,ROUTINE AND GRANT OPTION.
17 out of 22
18. REVOKE PRIVILEGES
It enables system administrators to revoke privileges from MySQL
accounts(Break the rules and regulations that given by GRANT to the
user account).
Syntax: REVOKE privilege_type [(column_list)] ,[priv_type
[(column_list)]]...ON [object_type] privilege_level FROM user [‘user’]
Ex: revoke all privileges, grant option from‘rose’@‘localhost’;
18 out of 22
19. ROUTINES AND TRIGGERS
Routines (otherwise known as stored procedures and stored
functions).
When used in conjunction with each other MySQL stored procedures
and triggers will provide a database that all but runs itself.
A MySQL stored procedure is a block of code stored on the server
will normally carry out a series of SQL statements.
19 out of 22
20. ROUTINES AND TRIGGERS
This is particularly useful because:
client applications need to know nothing about the structure or the
content of a database - they just need to know how to run any
MySQL stored procedures
any changes in procedures can be made via the stored procedures -
those changes will automatically be used by client applications
without the need to modify the applications
A stored procedure can only be run by some one or something and
that's where the MySQL trigger is used.
20 out of 22
21. ROUTINES AND TRIGGERS
A MySQL trigger is a piece of code that fires whenever something
happens to a table, and that something can be one of three table
events.
Delete - the trigger fires if something is deleted from table.
Insert - the trigger fires if something is inserted into the table.
Update - the trigger fires if the table is updated.
There is a further refinement as well - the trigger may be fired:
Before the event occurs.
After the event occurs.
21 out of 22