MariaDB - 无法以 root 身份登录

2022-01-15 00:00:00 mariadb mysql

我正在尝试在 Ubuntu (16.04.02) 上设置 MariaDB (10.0.29).在我安装它并启动进程(sudo service mysql start)后,即使我最初将密码设置为空白,我也无法以 root 身份登录.

I am trying to setup MariaDB (10.0.29) on Ubuntu (16.04.02). After I installed it and started the process (sudo service mysql start), I cannot login as root even though I originally set the password to blank.

mysql -u root 将拒绝我访问.我通过 sudo mysql 登录并检查了用户表,即.select user, password, authentication_string from mysql.user 和预期的一样:

Ie mysql -u root will deny me access. I logged in through sudo mysql and checked the user table, ie. select user, password, authentication_string from mysql.user and as expected:

+---------+----------+-----------------------+ 
| User    | password | authentication_string |
+---------+----------+-----------------------+
| root    |          |                       |
+---------+----------+-----------------------+

我还创建了一个新用户,即.create user 'test'@'localhost' identify by ''; 当我尝试执行 mysql -u test (空密码)时,它按预期工作并记录我在.

I also created a new user, ie. create user 'test'@'localhost' identified by ''; and when I try to do mysql -u test (empty password), it works as expected and logs me in.

用户表如下所示:

+---------+----------+-----------------------+
| User    | password | authentication_string |
+---------+----------+-----------------------+
| root    |          |                       |
| test    |          |                       |
+---------+----------+-----------------------+

那么,谁能告诉我为什么我不能以 root 的身份使用空密码登录,但我可以以 test 的身份登录?

So, can anyone tell me why I cannot login as root with empty password but I can login as test?

推荐答案

与原生 MariaDB 包(MariaDB 自身提供的包)不同,Ubuntu 生成的包默认具有 unix_socket 本地根身份验证.要检查,请运行

Unlike native MariaDB packages (those provided by MariaDB itself), packages generated by Ubuntu by default have unix_socket authentication for the local root. To check, run

SELECT user, host, plugin FROM mysql.user;

如果您在 plugin 列中看到 unix_socket,这就是原因.

If you see unix_socket in the plugin column, that's the reason.

要返回通常的密码验证,请运行

To return to the usual password authentication, run

UPDATE mysql.user SET plugin = '' WHERE plugin = 'unix_socket';
FLUSH PRIVILEGES;

(选择适合您目的的 WHERE 子句,以上只是示例)

(choose the WHERE clause which fits your purposes, the one above is just an example)

相关文章