Score:2

Why can I use mysql even when entering a wrong password when using sudo?

id flag

If I try to login to mysql with mysql -u root -p and enter the wrong password, then I get "access denied".

However, if I use sudo mysql -u root -p and enter the wrong mysql password, then I get access.

Version: mysql Ver 15.1 Distrib 10.3.25-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Score:3
mp flag

It's likely due to the the root user using the unix_socket method of authentication. With this method a password it not used, only the operating system user matching the database user can login. So only the root OS user can login as the root database user. And although it's accepting a password on the command line it's being ignored.

See the MariaDB knowledgebase for more detailed info including (if you really want/need) how to change to password authentication.

If you do use mysql; followed by select user, plugin from user; you can see which authentication plugins are configured for which users.

vn flag
pgr
Thanks. This was useful. I got the same behavior but when listing plugins it says `auth_socket` instead of `unix_socket` - I suppose they are the same thing.
codlord avatar
mp flag
@pgr yes, I think it's `auth_socket` in MySQL but `unix_socket` in MariaDB (a fork of MySQL).
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.