英文:
Connect to mariaDB with sudo without password
问题
After a fresh installation of MariaDB, the system's user root
is able to connect as root without a password with:
sudo mysql -u root
After reimporting my backup, I can't do this anymore:
user@server:~$ sudo mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Table mysql.user
contains:
MariaDB [mysql]> select host, user, password, plugin from mysql.user;
+-----------+------------+-------------------------------------------+-----------------------+
| host | user | password | plugin |
+-----------+------------+-------------------------------------------+-----------------------+
| localhost | root | | mysql_native_password |
| localhost | phpmyadmin | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | mysql_native_password |
| % | user1 | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | mysql_native_password |
| localhost | seafile | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | mysql_native_password |
| localhost | gogs | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | mysql_native_password |
| localhost | user2 | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | |
| localhost | freshrss | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | |
+-----------+------------+-------------------------------------------+-----------------------+
7 rows in set (0.001 sec)
How can I get back this behavior?
I'm using MariaDB 10.5 and Debian 11.
Thanks.
英文:
After a fresh installation of MariaDB, the system's user root
is able to connect as root without password with :
sudo mysql -u root
After reimporting my backup, I can't do this anymore :
user@server:~$ sudo mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Table mysql.user
contains :
MariaDB [mysql]> select host, user, password, plugin from mysql.user;
+-----------+------------+-------------------------------------------+-----------------------+
| host | user | password | plugin |
+-----------+------------+-------------------------------------------+-----------------------+
| localhost | root | | mysql_native_password |
| localhost | phpmyadmin | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | mysql_native_password |
| % | user1 | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | mysql_native_password |
| localhost | seafile | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | mysql_native_password |
| localhost | gogs | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | mysql_native_password |
| localhost | user2 | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | |
| localhost | freshrss | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | |
+-----------+------------+-------------------------------------------+-----------------------+
7 rows in set (0,001 sec)
How can I get back this behaviour ?
I'm using mariadb 10.5 and Debian 11.
Thanks
答案1
得分: 1
First thing, from MariaDB-10.4 onwards mysql.user
is a view that doesn't completely contain everything related to the user. mysql.global_priv
is the more complete version.
For a complete view of a user, use show create user root@localhost
.
To change use alter user:
Query OK, 0 rows affected (0.000 sec)
MariaDB [mysql]> show create user root@localhost;
+-----------------------------------------------------------+
| CREATE USER for root@localhost |
+-----------------------------------------------------------+
| CREATE USER `root`@`localhost` IDENTIFIED VIA unix_socket |
+-----------------------------------------------------------+
1 row in set (0.000 sec)
英文:
First thing, from MariaDB-10.4 onwards mysql.user
is a view that doesn't completely contain everything related to the user. mysql.global_priv
is the more complete version.
For a complete view of a user, use show create user root@localhost
.
To change use alter user:
MariaDB [mysql]> alter user root@localhost IDENTIFIED VIA unix_socket;
Query OK, 0 rows affected (0.000 sec)
MariaDB [mysql]> show create user root@localhost;
+-----------------------------------------------------------+
| CREATE USER for root@localhost |
+-----------------------------------------------------------+
| CREATE USER `root`@`localhost` IDENTIFIED VIA unix_socket |
+-----------------------------------------------------------+
1 row in set (0.000 sec)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论