MySQL数据库用户创建

来源:互联网 发布:以父之名 知乎 编辑:程序博客网 时间:2024/05/29 07:14

创建一个密码为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
原创粉丝点击