8

I created a new mysql user with all the same privileges as the current 'root' user. For security reasons I thought why not create another user for this so people at least won't know the username of my super user.

I then dropped the root user.

Immediately my DB started throwing connection refused errors for all of my other users.

I quickly recreated the original 'root' user and everything magically started connecting again.

My question is then, is it possible to delete the root user in a MySQL database? And if so how?

Thanks.

EDIT 1:

All other security options are in place. We are not just securing our system by trying to remove the root user. We have some over zealous security people here and removing the MySQL root user was just an extra step.

I agree with @Pleun for the reasons I tried to remove it.

13
  • 7
    Security through obscurity is not security at all...
    – Platinum Azure
    Jul 23, 2013 at 20:59
  • 1
    Were all your other users connecting as root? Jul 23, 2013 at 21:01
  • 1
    @Pleun: On what grounds?
    – Platinum Azure
    Jul 23, 2013 at 21:02
  • 2
    Just choose a really strong (long) password for your root user. That should be safe enough.
    – mata
    Jul 23, 2013 at 21:18
  • 1
    I'm saying that deleting the MySQL 'root' user does not make other users unable to connect. I just tested this to confirm it. So I conclude that your users were trying to connect as the MySQL 'root' user, but couldn't after you deleted that user. Jul 25, 2013 at 0:19

2 Answers 2

3

You can rename the 'root' user.

To rename the administrator’s username, use the rename command in the MySQL console:

mysql> RENAME USER root TO new_user;

The MySQL “RENAME USER” command first appeared in MySQL version 5.0.2. If you use an older version of MySQL, you can use other commands to rename a user:

mysql> use mysql;

mysql> update user set user=”new_user” where user=”root”;

mysql> flush privileges;

From here.

1
  • @user1819471 , What solution did you implement?
    – Kreya
    Aug 10, 2020 at 13:39
2

From this StackOverflow question I opened (same problem statement), you may be interested in the answer. See here.

Your deleted root account was probably used to create procedures, functions, triggers, events or even views that your other accounts try to interract with. I assume your objects were created with the SQL SECURITY parameter set to DEFINER - this is the default behavior if not specified. In such situation, MySQL want to create root context while working on the objects but cannot as you deleted the root account. This is what generate your error - although MySQL mislead the troubleshoot with this Access Denied for account X message

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.