# MySQL User Privileges

**URL:** <https://forums.percona.com/t/mysql-user-privileges/25850>\
**Category:** MySQL & MariaDB\
**Created:** [October 11, 2023, 7:08pm UTC](https://forums.percona.com/t/mysql-user-privileges/25850 "2023-10-11T19:08:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![parttime](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@parttime](https://forums.percona.com/u/parttime)\
**Post date:** [October 11, 2023, 7:08pm UTC](https://forums.percona.com/t/mysql-user-privileges/25850/1 "2023-10-11T19:08:45Z")

</div>

Hi,  
I did drop root user. After new create root user, but the user not yet privileges.  
Example it isn’t not create new user. How can ı this error?

```auto
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
ERROR 1045 (28000): Access denied for user 'root'@'%' (using password: YES)
mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'passwpord';
ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
mysql> GRANT GRANT OPTION ON *.* TO 'root'@'%';
ERROR 1045 (28000): Access denied for user 'root'@'%' (using password: YES)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
ERROR 1045 (28000): Access denied for user 'root'@'%' (using password: YES)
mysql> FLUSH PRIVILEGES;
ERROR 1227 (42000): Access denied; you need (at least one of) the RELOAD privilege(s) for this operation
mysql>

```

---

<div class="post-metadata">

**Author:** ![Mauricio\_Cacho](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/mauricio_cacho/32/5859_2.png) [@Mauricio\_Cacho](https://forums.percona.com/u/Mauricio_Cacho)\
**Post date:** [October 12, 2023, 1:23am UTC](https://forums.percona.com/t/mysql-user-privileges/25850/2 "2023-10-12T01:23:20Z")

</div>

Hi @parttime .

Could you share the MySQL version, and how the user was dropped?

Also, is this a new MySQL installation, do you have other users created in there?

Finally, using this guide might help you (It’s for resetting a root password, which is not directly your case, but due to the errors it might help: [https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html](https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html)).

Please try it, should it not work, share more details about the current situation.

Best,  
Mauricio.

---

<div class="post-metadata">

**Author:** ![parttime](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@parttime](https://forums.percona.com/u/parttime)\
**Post date:** [October 13, 2023, 2:11pm UTC](https://forums.percona.com/t/mysql-user-privileges/25850/3 "2023-10-13T14:11:15Z")

</div>

This error. How we can resolve the stitation?

mysql\> GRANT ALL PRIVILEGES ON _._ TO ‘user’@‘%’ WITH GRANT OPTION;  
ERROR 1045 (28000): Access denied for user ‘root’@‘%’ (using password: YES)

---

<div class="post-metadata">

**Author:** ![lalit.choudhary](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/lalit.choudhary/32/51_2.png) [@lalit.choudhary](https://forums.percona.com/u/lalit.choudhary)\
**Post date:** [December 28, 2023, 5:46am UTC](https://forums.percona.com/t/mysql-user-privileges/25850/5 "2023-12-28T05:46:20Z")

</div>

Hello @parttime

Ref: [https://dev.mysql.com/doc/refman/8.0/en/grant.html](https://dev.mysql.com/doc/refman/8.0/en/grant.html)  
To grant a privilege with [`GRANT`](https://dev.mysql.com/doc/refman/8.0/en/grant.html), you must have the [`GRANT OPTION`](https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_grant-option) privilege, and you must have the privileges that you are granting. (Alternatively, if you have the [`UPDATE`](https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_update) privilege for the grant tables in the `mysql` system schema, you can grant any account any privilege.) When the [`read_only`](https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_read_only) system variable is enabled, [`GRANT`](https://dev.mysql.com/doc/refman/8.0/en/grant.html) additionally requires the [`CONNECTION_ADMIN`](https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_connection-admin) privilege (or the deprecated [`SUPER`](https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_super) privilege).

Example:

```auto
master [localhost] {msandbox} ((none)) > select user, host,Grant_priv, Super_priv from mysql.user;
+------------------+-----------+------------+------------+
| user | host | Grant_priv | Super_priv |
+------------------+-----------+------------+------------+
| msandbox | 127.% | N | Y |
| msandbox_ro | 127.% | N | N |
| msandbox_rw | 127.% | N | N |
| rsandbox | 127.% | N | N |
| msandbox | localhost | N | Y |
| msandbox_ro | localhost | N | N |
| msandbox_rw | localhost | N | N |
| mysql.infoschema | localhost | N | N |
| mysql.session | localhost | N | Y |
| mysql.sys | localhost | N | N |
| root | localhost | Y | Y |
+------------------+-----------+------------+------------+
11 rows in set (0.00 sec)

master [localhost] {msandbox} ((none)) > select user();
+--------------------+
| user() |
+--------------------+
| msandbox@localhost |
+--------------------+
1 row in set (0.00 sec)

master [localhost] {msandbox} ((none)) > show Grants\G
***************************1. row***************************
Grants for msandbox@localhost: GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `msandbox`@`localhost`
***************************2. row***************************
Grants for msandbox@localhost: GRANT APPLICATION_PASSWORD_ADMIN,AUDIT_ADMIN,BACKUP_ADMIN,BINLOG_ADMIN,BINLOG_ENCRYPTION_ADMIN,CLONE_ADMIN,CONNECTION_ADMIN,ENCRYPTION_KEY_ADMIN,FLUSH_OPTIMIZER_COSTS,FLUSH_STATUS,FLUSH_TABLES,FLUSH_USER_RESOURCES,GROUP_REPLICATION_ADMIN,INNODB_REDO_LOG_ARCHIVE,INNODB_REDO_LOG_ENABLE,PERSIST_RO_VARIABLES_ADMIN,REPLICATION_APPLIER,REPLICATION_SLAVE_ADMIN,RESOURCE_GROUP_ADMIN,RESOURCE_GROUP_USER,ROLE_ADMIN,SERVICE_CONNECTION_ADMIN,SESSION_VARIABLES_ADMIN,SET_USER_ID,SHOW_ROUTINE,SYSTEM_USER,SYSTEM_VARIABLES_ADMIN,TABLE_ENCRYPTION_ADMIN,XA_RECOVER_ADMIN ON *.* TO `msandbox`@`localhost`
2 rows in set (0.00 sec)

master [localhost] {msandbox} ((none)) > create user u1@'%' identified by 'Hello@123';
Query OK, 0 rows affected (0.03 sec)

master [localhost] {msandbox} ((none)) > grant ALL on *.* to u1@'%';
ERROR 1045 (28000): Access denied for user 'msandbox'@'localhost' (using password: YES)
master [localhost] {msandbox} ((none)) > grant ALL on *.* to u1@'%' with grant option;
ERROR 1045 (28000): Access denied for user 'msandbox'@'localhost' (using password: YES)
master [localhost] {msandbox} ((none)) >

```

**Check if you have any user with `Grant_priv`, `Super_priv`**

`select user, Grant_priv, Super_priv from mysql.user;`

If it’s a new setup **without any data,** I would suggest Re-Initializing MySQL and creating a required user with ALL, SUPER, WITH GRANT Option privileges before deleting the root user.
