0

mysql 5.7.22 on centos 7

To be clear I have a root password set up. Usually I log in using

mysql -u root -p

Today I accidentally hit Enter after I only typed

mysql

And I was shocked to find out I had logged in as root user. show grants displays

mysql> show grants;
+---------------------------------------------------------------------+
| Grants for root@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION        |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)

Then I tried

mysql -u root

It still didn't ask for a password for logging in.

Firstly I thought it was some wired setup issue because I was logging in from localhost. However when I tried to login from web browser using serverIP/phpmyadmin and it does ask for root password.

Does anyone know what was going on? Thanks

1 Answer 1

1

I assume you are already ssh'd in as root? If you are, then this would be correct as far as I understand from my experience. As you are logged in as the Root user on the server itself, you have complete control over the entire OS and all its applications. There is no 'privilege escalation', as, being the root server user, you can easily change the root password for MySQL (or indeed any aspect of the MySql installation).

Try logging in to the server as a standard user, and try the same, it should not work unless you have an anonymous user set up.

You can view all the users and their hosts with:

SELECT host, user, authentication_string, plugin FROM mysql.user;

This will show you whether there is a password set (there will be an entry in authentication_string) and also the 'plugin' for the db user (re backward compatibility for earlier versions of MySQL)

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.