MySQL数据库用户创建

创建一个密码为test1234,用户名为yii2db

CREATE USER 'yii2db'@'localhost' IDENTIFIED BY 'test1234';

给创建的用户授权

语法:
GRANT [type of permission] ON [database name].[table name] TO '[username]'@'localhost’;

数据库权限种类
+ ALL PRIVILEGES- as we saw previously, this would allow a MySQL user all access to a designated database (or if no database is selected, across the system)
+ CREATE- allows them to create new tables or databases
+ DROP- allows them to them to delete tables or databases
+ DELETE- allows them to delete rows from tables
+ INSERT- allows them to insert rows into tables
+ SELECT- allows them to use the Select command to read through databases
+ UPDATE- allow them to update table rows
+ GRANT OPTION- allows them to grant or remove other users’ privileges

例子:

GRANT CREATE,DELETE,INSERT,SELECT,UPDATE,DROP ON *.* TO 'yii2db'@'localhost';
GRANT ALL PRIVILEGES ON *.* TO 'yii2db'@'localhost';

刷新权限

FLUSH PRIVILEGES;

实例:删除一个数据库用户,然后创建数据库用户并赋予权限。
DROP USER 'yii2dbuser'@'localhost';
CREATE USER 'yii2dbuser'@'localhost' IDENTIFIED BY 'dbpassword';
GRANT CREATE,DELETE,INSERT,SELECT,UPDATE,DROP ON yii2db.* TO 'yii2dbuser'@'localhost';
FLUSH PRIVILEGES;

参考:https://dev.mysql.com/doc/refman/5.1/en/grant.html

阅读更多
文章标签: MySQL
个人分类: MySQL
想对作者说点什么? 我来说一句

基于jsp开发的简单web相册系统

2013年01月14日 2.47MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭