大网数据广告活动
服务器运维问答

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

· 52CE 我爱测

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 Di…

问题原文

原帖链接 · Black · CC BY-SA 4.0

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

已采纳解答

原帖链接 · codlord · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-10-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。