/*创建用户*/
GRANT ALL PRIVILEGES ON *.* TO 'zhihua'@'%' IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
/*OR*/
CREATE USER zhihua IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'zhihua'@'%' WITH GRANT OPTION;
除了GRANT,还可以直接用INSERT语句创建相同的账户,然后使用FLUSH PRIVILEGES告诉服务器重载授权表。
INSERT INTO user VALUES('localhost','monty',PASSWORD('some_pass'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
INSERT INTO user VALUES('%','monty',PASSWORD('some_pass'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
INSERT INTO user SET Host='localhost',User='admin',Reload_priv='Y', Process_priv='Y';
INSERT INTO user (Host,User,Password) VALUES('localhost','dummy','');
FLUSH PRIVILEGES;
当你用INSERT创建账户时使用FLUSH PRIVILEGES的原因是告诉服务器重读授权表。否则,只有重启服务器后更改方会被注意到。使用 GRANT,则不需要使用FLUSH PRIVILEGES。
/*可以访问bankaccount数据库,但只能从本机访问*/
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON bankaccount.* TO 'custom'@'localhost' IDENTIFIED BY 'obscure';
/*可以访问expenses数据库,但只能从主机whitehouse.gov访问*/
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON expenses.* TO 'custom'@'whitehouse.gov' IDENTIFIED BY 'obscure';
/*可以访问customer数据库,但只能从主机server.domain访问*/
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON customer.* TO 'custom'@'server.domain' IDENTIFIED BY 'obscure';
具体还有两种方式,请看
LINK。