MySQL:创建仅对特定数据库具有权限的用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1659848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL: Create user with rights only for specific db
提问by Petr
I would need to create MySQL user programatically with the privileges only for specific db. Say there are databases a,b,c and I would need to create user who has rights only for B. I am sure its possible but my googling was not successful. Thank you!
我需要以编程方式创建 MySQL 用户,并且仅具有特定数据库的权限。假设有数据库 a、b、c,我需要创建仅对 B 拥有权限的用户。我相信这可能,但我的谷歌搜索没有成功。谢谢!
回答by Bj?rn
grant all
on B.*
to
'user'@localhost
identified by
'password'
The user 'user' with password 'password' now have access to all tables in the database 'B'. (Of course you need to run this query with a high priv user)
密码为“password”的用户“user”现在可以访问数据库“B”中的所有表。(当然,您需要以高权限用户运行此查询)
回答by RRUZ
you can try this
你可以试试这个
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'some_pass';
grant all privileges on B.* to 'myuser'@'localhost' identified by 'some_pass';