让MySQL用户创建数据库,但只允许访问他们自己的数据库 [英] Let MySQL users create databases, but allow access to only their own databases

查看:221
本文介绍了让MySQL用户创建数据库,但只允许访问他们自己的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望拥有多个 MySQL用户,以便能够发出

I want to have multiple a MySQL users to be able to issue commands like

CREATE DATABASE dbTest;

但是我也希望这些用户中的每一个都只能看到和访问他们的自己的数据库.

But I also want each of these users to be able to see and access only their own databases.

我所能找到的就是如何由DBA创建数据库并将该数据库的特权授予特定用户:

All I could find was how to either create the databases by a DBA and grant the privileges on this database to the specific user:

GRANT ALL PRIVILEGES ON dbTest.* TO 'user';

或在所有数据库上授予用户特权:

or grant privileges on all databases to a user:

GRANT ALL PRIVILEGES ON *.* TO 'user';

但是我也不想要什么,因为它需要扩展并保持安全.

But neither is what I want, because it needs to scale and be secure.

推荐答案

您可以使用

GRANT ALL PRIVILEGES ON `testuser\_%` .  * TO 'testuser'@'%';

授予用户名称以testuser_开头的所有数据库的用户testuser特权.

to grant the user testuser privileges on all databases with names beginning with testuser_.

这允许测试用户创建限于名称以testuser_开头的数据库

This allows the testuser to create databases limited to names starting with testuser_

这篇关于让MySQL用户创建数据库,但只允许访问他们自己的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆