\sql // to activate sql
\connect root@localhost // to connect to the server with user root and host as localhost
syntax :
select user, host from mysql.user;
syntax:
create user 'username'@'host' identified by 'password';
syntax:
show grants for username@host ;
syntax :
grant privilege_name on dbname.tablename to username@host;
examples :
- Grant select privilege :
grant select on *.* to user@host; // all databases and all tables
grant select on db.tb to user2host; // database db having table tb
- Grant update on single column :
grant update (col) on db.tb to user@host;
syntax :
revoke privilege_name on dbname.tablename from user@host; <br>
privilege must be first granted only then it could be revoked
Only those granted privileges can be revoked.
view currently running users
select id, users from information_schema.processlist;
to disconnect a existing user connection from root account
kill \<id\>; //id given in the previos table i.e processlist
'username'@'localhost'
'pooja'@'localhost' // pooja can only access it through localhost
'username'@'192.25.1.2'
'pooja'@'192.25.1.2' // pooja can only access through server 192.25.1.2
'username'
'pooja' // username without specifying host will enable it to access from anywhere