授予多个数据库。 MySQL

发布于 2024-09-09 07:11:44 字数 184 浏览 1 评论 0原文

如何在多个数据库上授予权限? MySQL。

像这样的东西

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE
ON 'databasesprefix%'.*
TO testuser@localhost IDENTIFIED BY 'testpasswd';

How to grant on multiple databases? MySQL.

Something like

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE
ON 'databasesprefix%'.*
TO testuser@localhost IDENTIFIED BY 'testpasswd';

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一袭水袖舞倾城 2024-09-16 07:11:44

您只需要在 db_name 前缀周围使用反引号而不是引号。

我认为这会起作用:

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE
ON `databasesprefix%`.*
TO testuser@localhost IDENTIFIED BY 'testpasswd';

You just need to use backticks instead of quotes around the db_name prefix.

I think this will work:

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE
ON `databasesprefix%`.*
TO testuser@localhost IDENTIFIED BY 'testpasswd';
北渚 2024-09-16 07:11:44

你的例子应该有效。来自(5.5)手册

在授予全局或数据库级别权限的 GRANT 语句中指定数据库名称时,允许使用“_”和“%”通配符。

其中 % 匹配任意数量(甚至零)的字符,而 _ 恰好匹配一个字符。如果您希望数据库名称中包含 _,则必须将其转义为 \_。另请注意手册中的其他注意事项。

<更新>正如另一个答案指出的那样:如果数据库名称包含通配符,则必须用 标识符引号字符,反引号(“`”)更新>

your example should work. from the (5.5) manual:

The “_” and “%” wildcards are allowed when specifying database names in GRANT statements that grant privileges at the global or database levels.

with % matching any number (even zero) of characters, and _ matching exactly one character. if you want a _ in your database name, you have to escape it as \_. also watch the other caveats from the manual.

<UPDATE>as the other answer points out: if the database name contains wildcards, it has to be quoted with the identifier quote character, the backtick (“`”)</UPDATE>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文