# Virtualmin create-user with --mysql option granting access to all databases in domain

**URL:** <https://forum.virtualmin.com/t/virtualmin-create-user-with-mysql-option-granting-access-to-all-databases-in-domain/123708>\
**Category:** Help! (Home for newbies)\
**Created:** [November 29, 2023, 11:55am UTC](https://forum.virtualmin.com/t/virtualmin-create-user-with-mysql-option-granting-access-to-all-databases-in-domain/123708 "2023-11-29T11:55:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![prototypefab](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/p/4af34b/32.png) [@prototypefab](https://forum.virtualmin.com/u/prototypefab)\
**Post date:** [November 29, 2023, 11:55am UTC](https://forum.virtualmin.com/t/virtualmin-create-user-with-mysql-option-granting-access-to-all-databases-in-domain/123708/1 "2023-11-29T11:55:34Z")

</div>

| SYSTEM INFORMATION | |
| --- | --- |
| OS type and version | Debian 12 |
| Virtualmin version | 7.8.2 |

Hello, i’m facing a problem with the use of the create-user CLI command, specifically, when using the `--mysql` option, the [documentation](https://www.virtualmin.com/documentation/developer/cli/create_user/) states that `--mysql ` should be followed by the name of the database you want the user to have access to.  
The problem for me is that the command doesn’t seem to assign the permissions correctly. specifically when using the option, regardless of the database name you give it, the user will be granted permissions to all the databases in the domain.

I tried making a test domain and this seems replicable:

 ![image](https://cdn.forum.virtualmin.com/uploads/default/original/2X/7/76f9c662d9e45a282328681c76232dbb37158c59.png)  
i first created a test virtual server, and made 3 databases associated to it

i then tried creating a “control” user without using the `--mysql` option, just to see if the problem was some default template thing

```auto
# virtualmin create-user --domain test.test --user usernodb --pass test
User usernodb@test.test created successfully

```

 ![image](https://cdn.forum.virtualmin.com/uploads/default/original/2X/3/30b523bdaaca02e80f75df6629af88429e3e71c6.png)  
this works as intended, giving the user no access on any of the databases.

i then created a new user trying to give permissions to the `testdb2` database

```auto
# virtualmin create-user --domain test.test --user userdb --pass test --mysql testdb2
User userdb@test.test created successfully

```

 ![image](https://cdn.forum.virtualmin.com/uploads/default/original/2X/4/4423a2ca66349d87a42783eb2cd64102140e8013.png)  
this granted access to all databases in the virtual server, not just the one specified.

i’m positive this could be a bug, but i’m open to solutions if this is an error on my end

I discovered this while trying to automate the migration of a virtual server with a whole bunch of databases and user, trying to give one database per user and discovering the mess that was left afterwards

---

<div class="post-metadata">

**Author:** ![Ilia](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/ilia/32/10185_2.png) [@Ilia](https://forum.virtualmin.com/u/Ilia)\
**Post date:** [November 29, 2023, 12:40pm UTC](https://forum.virtualmin.com/t/virtualmin-create-user-with-mysql-option-granting-access-to-all-databases-in-domain/123708/2 "2023-11-29T12:40:41Z")

</div>

> [@prototypefab](#):
>
> i’m positive this could be a bug, but i’m open to solutions if this is an error on my end

@Jamie, I think it’s the bug. I see it too.

---

<div class="post-metadata">

**Author:** ![prototypefab](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/p/4af34b/32.png) [@prototypefab](https://forum.virtualmin.com/u/prototypefab)\
**Post date:** [November 29, 2023, 3:58pm UTC](https://forum.virtualmin.com/t/virtualmin-create-user-with-mysql-option-granting-access-to-all-databases-in-domain/123708/3 "2023-11-29T15:58:30Z")

</div>

well it’s always a fun day when i find a bug in a big project. i tried looking at the code responsible for this but it’s the very first time i’ve looked at Perl and boy i wish i hadn’t, looks like hieroglyphs to me

~~While we wait for someone with experience with the codebase to help, is there some way i can script something like this at the moment? for example is there a CLI way i can add permissions for a single  
database to an already existing user?~~

Edit: stupid question, modify-user can do this, and does not seem to have the same bug, will use that in the meantime

---

<div class="post-metadata">

**Author:** ![Jamie](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/jamie/32/8589_2.png) [@Jamie](https://forum.virtualmin.com/u/Jamie)\
**Post date:** [November 30, 2023, 3:37am UTC](https://forum.virtualmin.com/t/virtualmin-create-user-with-mysql-option-granting-access-to-all-databases-in-domain/123708/4 "2023-11-30T03:37:41Z")

</div>

This does look like a bug, but I wasn’t able to re-produce it. @Ilia can you repro this on a test system?

---

<div class="post-metadata">

**Author:** ![Ilia](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/ilia/32/10185_2.png) [@Ilia](https://forum.virtualmin.com/u/Ilia)\
**Post date:** [November 30, 2023, 3:52pm UTC](https://forum.virtualmin.com/t/virtualmin-create-user-with-mysql-option-granting-access-to-all-databases-in-domain/123708/5 "2023-11-30T15:52:35Z")

</div>

> [@Jamie](#):
>
> @Ilia can you repro this on a test system?

Yes, and I can see what’s causing this bug. Although, I need to run deeper tests to make sure it will work as expected in all use-cases.

---

<div class="post-metadata">

**Author:** ![Ilia](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/ilia/32/10185_2.png) [@Ilia](https://forum.virtualmin.com/u/Ilia)\
**Post date:** [November 30, 2023, 4:55pm UTC](https://forum.virtualmin.com/t/virtualmin-create-user-with-mysql-option-granting-access-to-all-databases-in-domain/123708/6 "2023-11-30T16:55:23Z")

</div>

Anyway, here is the fix for this issue. Sadly, I don’t understand why I made this change at the first place.

> <https://github.com/virtualmin/virtualmin-gpl/commit/d0afb9f8edeccc43c0c0021cf1cf8bb56d4975dc>
>
> https://github.com/virtualmin/virtualmin-gpl/commit/6cd1509d76e7daeb37d55ec9091c…529527230466#diff-a8b0a88367118c8f13666eed07287b13ecc217c8fdfaf6a34d51b226dc196f92R1419

Perhaps, my idea was to make sure that access to all databases is provided after restore. Although, I can see that access to the associated databases is actually provided after the restore already.

---

<div class="post-metadata">

**Author:** ![Jamie](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/jamie/32/8589_2.png) [@Jamie](https://forum.virtualmin.com/u/Jamie)\
**Post date:** [November 30, 2023, 10:46pm UTC](https://forum.virtualmin.com/t/virtualmin-create-user-with-mysql-option-granting-access-to-all-databases-in-domain/123708/7 "2023-11-30T22:46:59Z")

</div>

Thanks for the fix! Yeah I’m not sure what the reasoning was behind the original code either …

---

<div class="post-metadata">

**Author:** ![system](https://cdn.forum.virtualmin.com/uploads/default/original/2X/c/cd96d761e326db4b2bef94886a639109bd7a8e76.svg) [@system](https://forum.virtualmin.com/u/system)\
**Post date:** [January 29, 2024, 10:47pm UTC](https://forum.virtualmin.com/t/virtualmin-create-user-with-mysql-option-granting-access-to-all-databases-in-domain/123708/8 "2024-01-29T22:47:31Z")

</div>

Closed on January 29, 2024, 10:47pm UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
