sourcecode

비밀번호 없이 sudo를 사용하여 mariaDB에 연결

codebag 2023. 6. 17. 09:05
반응형

비밀번호 없이 sudo를 사용하여 mariaDB에 연결

시스템 사용자인 MariaDB를 새로 설치한 후root암호 없이 루트로 연결할 수 있습니다.sudo mysql -u root

백업을 다시 가져온 후에는 더 이상 이 작업을 수행할 수 없습니다.

user@server:~$ sudo mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

테이블mysql.user포함:

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)

어떻게 하면 이 행동을 되돌릴 수 있을까요?

mariadb 10.5와 debian 11을 사용하고 있습니다.

감사해요.

첫 번째, MariaDB-10.4 이후 버전mysql.user사용자와 관련된 모든 내용을 포함하지 않는 보기입니다. mysql.global_priv더 완전한 버전입니다.

사용자의 전체 보기를 보려면 다음을 사용합니다.show create user root@localhost.

다른 사용자 사용을 변경하려면 다음을 수행합니다.

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)

언급URL : https://stackoverflow.com/questions/75978151/connect-to-mariadb-with-sudo-without-password

반응형