mysql创建只读账号及授权语句

1.查询所有账号信息

SELECT DISTINCT a.`User`,a.`Host`,a.password_expired,a.password_last_changed,a.password_lifetime,a.* FROM mysql.user a;

2.创建账号

CREATE USER '账号名称'@'host地址' IDENTIFIED BY '密码';

示例:CREATE USER 'asdfghname'@'192.168.0.111' IDENTIFIED BY '123456';

即:在192.168.0.111上创建账号是asdfghname,密码是123456

3.授权

GRANT SELECT ON databasename.* TO '账号名称'@'host地址';

示例:GRANT SELECT ON mytestdb.* TO 'asdfghname'@'192.168.0.111';

即:只有查询权限

4.添加视图的权限

UPDATE mysql.`user` a SET a.Show_view_priv='Y' WHERE a.`User`='账号名称' and a.`Host`='192.168.0.111';
FLUSH PRIVILEGES;

你可能感兴趣的:(mysql)