Adding user to role in mysql using SQL statement
I need to know if it is possible to add USER to ROLE in MYSQL using some SQL statement开发者_开发问答?
Thanks.
MySQL doesn't have roles per se. You can create a new user with basic SELECT permissions like this:
CREATE USER 'user'@'host' IDENTIFIED BY 'password';
GRANT SELECT ON database.* TO 'user'@'host';
FLUSH PRIVILEGES;
MySQL GRANT docs: http://dev.mysql.com/doc/refman/5.1/en/grant.html
YES ,
As an alternative to GRANT, you can create the same accounts directly by issuing INSERT statements and then telling the server to reload the grant tables:
shell> mysql --user=root mysql
mysql> INSERT INTO user
-> VALUES('localhost','monty',PASSWORD('some_pass'),
-> 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
mysql> INSERT INTO user
-> VALUES('%','monty',PASSWORD('some_pass'),
-> 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
mysql> INSERT INTO user SET Host='localhost',User='admin',
-> Reload_priv='Y', Process_priv='Y';
mysql> INSERT INTO user (Host,User,Password)
-> VALUES('localhost','dummy','');
mysql> FLUSH PRIVILEGES;
精彩评论