关闭

MySQL数据库用户创建

标签: MySQL
295人阅读 评论(0) 收藏 举报
分类:

创建一个密码为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

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:175259次
    • 积分:2902
    • 等级:
    • 排名:第13231名
    • 原创:101篇
    • 转载:53篇
    • 译文:1篇
    • 评论:12条
    文章分类
    最新评论