gpt4 book ai didi

mysql - 授予对选定表的权限

转载 作者:行者123 更新时间:2023-11-29 12:00:28 24 4
gpt4 key购买 nike

我有一个 MySQL 5.x 数据库,包含大约 100 个表。我想授予某些表的 SELECT 权限:

show tables from my_db like '%some_pattern%'; # select only tables

...以及其余表上的 SELECTINSERTUPDATEDELETE

我该怎么做?

最佳答案

尝试

SELECT CONCAT('GRANT SELECT ON schemaName.', TABLE_NAME, ' to ''username'';')
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'schemaName'
AND TABLE_NAME LIKE '%some_pattern%'

SELECT CONCAT('GRANT SELECT, INSERT, UPDATE, DELETE ON schemaName.', TABLE_NAME, ' to ''username'';')
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'schemaName'
AND TABLE_NAME NOT LIKE '%some_pattern%'

然后运行上面的语句,复制生成的sql并运行结果授予权限

关于mysql - 授予对选定表的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32458143/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com