MySQL 创建用户并只赋予某个数据库的权限

MySQL luoluolzb 浏览1168次

使用 root 或者其他有权限的账号登录mysql。

如果没有创建,先创建要使用的数据库:

create database `test`;

创建一个新用户并设置密码:

create user 'test'@'localhost' identified by '123456';

赋予用户权限:

grant all on test.* to 'test'@'localhost';

其中all表示所有权限,test.*表示test数据库的所有表。

grant命令在用户不存在的时候回自动创建,所以可以直接使用grant创建账号并指定权限:

grant all on test.* to 'test'@'localhost' identified by '123456';

撤销用户权限:

revoke all on test.* from 'test'@'localhost';

本文标签: MySQL

版权声明:本文为作者原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://luoluolzb.cn/articles/97/mysql-creates-users-and-only-gives-permissions-to-a-database
您需要登录后才发布评论。 点此登录
用户评论 (0条)

暂无评论,赶紧发表一下你的看法吧。