Monday, May 23, 2016

Mysql Administration




Create new users using CREATE USER statement
create a new user that connects from local host  with the password.
CREATE USER admin@localhost IDENTIFIED BY 'admin';

create a new user that connects from any host with the password.

CREATE USER admin@'%'IDENTIFIED BY 'admin';

create a new user by insert statement
INSERT INTO user (host,user,password) VALUES('localhost','admin',PASSWORD('admin'));


MySQL changing password using UPDATE statement
USE mysql;
UPDATE user
SET password = PASSWORD('admin')
WHERE user = 'amin' AND host = 'localhost';

Granting Permissions in Mysql
If you want to create a super account that can do anything including being able to grant 
privileges to other users, you can use the following statements:
CREATE USER 'admin'@'localhost' IDENTIFIED BY 'admin';
GRANT ALL ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;

We can grant multiple privileges using a single grant statement. 
For example, we can create a user that can execute the SELECTINSERT and UPDATE 
statements using the following statements

CREATE USER 'admin'@'localhost' IDENTIFIED BY 'localhost';
GRANT SELECT,UPDATE,DELETE ON db_name.tbl_name TO 'admin'@'localhost';


Revoking or Terminating user permissions

REVOKE UPDATE, DELETE ON *.*  FROM 'admin'@'localhost';

REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'admin'@'localhost';

*.* resembles -> dbname.tblname here

Droping a user in Mysql

drop user username;
drop user username@'hostname';

0 comments:

Post a Comment