MySQL复制用户

发布于 2024-11-18 21:12:29 字数 312 浏览 9 评论 0原文

我想在我的 MySQL 测试数据库上创建两个用户,一个对与生成报告等相关的表具有只读访问权限,另一个对相同的表具有读写访问权限。这是为了测试通常与只读用户连接但切换到读写用户以执行某些任务的子系统。我已经创建了具有正确权限的读写用户,现在我需要同一用户的只读版本。

我不想从头开始创建只读版本,因为我必须设置很多权限,这相当费力。有没有办法可以基于现有用户创建新用户,然后从新用户中删除 INSERT/UPDATE/DELETE 权限?类似 CREATE USER 'user2' LIKE 'user1' 或类似内容?如果可以的话,我在 MySQL 文档中找不到它。

I want to create two users on my MySQL test database, One with read-only access to tables relevant to generating reports, etc, the other with read-write access to the same tables. This is for testing a subsystem that normally connects with a read-only user but switches to a read-write user for certain tasks. I've created the read-write user with the correct privileges, and now I need a read-only version of the same user.

I'd rather not create the read-only version from scratch as I had to set a lot of privileges, which was rather laborious. Is there a way I can create a new user based on an existing user and then remove the INSERT/UPDATE/DELETE privilages from the new user? Something like CREATE USER 'user2' LIKE 'user1' or similar? I couldn't find it in the MySQL docs if it is possible to do this.

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

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

发布评论

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

评论(2

流绪微梦 2024-11-25 21:12:29

插入另一个表并更新列怎么样?像这样的东西:

CREATE TABLE user_tmp LIKE user;
INSERT INTO user_tmp SELECT * FROM user WHERE host ='localhost' AND USER ='root';
UPDATE user_tmp SET user = 'readonlyuser', Insert_priv = 'N', Update_priv = 'N',
    Delete_priv = 'N', /* TODO: ADAPT TO YOUR SUITS */ LIMIT 1;
INSERT INTO user select * FROM user_tmp;
DROP TABLE user_tmp;

How about inserting into another table, update columns? Something like:

CREATE TABLE user_tmp LIKE user;
INSERT INTO user_tmp SELECT * FROM user WHERE host ='localhost' AND USER ='root';
UPDATE user_tmp SET user = 'readonlyuser', Insert_priv = 'N', Update_priv = 'N',
    Delete_priv = 'N', /* TODO: ADAPT TO YOUR SUITS */ LIMIT 1;
INSERT INTO user select * FROM user_tmp;
DROP TABLE user_tmp;
双手揣兜 2024-11-25 21:12:29

我找到了两个选择。

第一,如果您是Windows用户,您可以使用MySql管理员。 http://dev.mysql.com /doc/administrator/en/mysql-administrator-user-administration-user-accounts.html

第二个你可以使用 Mysql 实用程序中的 mysquserclone 命令:http://wb.mysql.com/utilities/man/mysqluserclone.html

祝你好运。

I found two options.

1st if you are Windows User, you can use MySql Administrator. http://dev.mysql.com/doc/administrator/en/mysql-administrator-user-administration-user-accounts.html

2nd you can use mysquserclone command from Mysql Utilities: http://wb.mysql.com/utilities/man/mysqluserclone.html

Good luck.

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