# mariadb에서 패스워드 없이 로그인할때

### 시작하는 말

안녕하세요, 고니입니다.  
기존에 작성했던 컨텐츠들 업데이트를 하면서 문서의 리팩토링(Refactoring)을 진행해보려고 합니다.  
이번엔 MariaDB 소켓인증 기술편입니다.  
MariaDB 버전 업그레이드 후 localhost에서 접속시 패스워드 없이 로그인이 가능했는데 왜 그런지 확인해보려고 합니다.

<table border="1" id="bkmrk-perplexity%EC%97%90%EC%84%9C-%EC%83%9D%EC%84%B1%ED%95%9C-ai%EC%9D%B4" style="border-collapse: collapse; width: 100%; border-width: 1px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>[![854e1d8b-3195-435a-879b-b7992083c5f7.png](http://wiki.igoni.kr/uploads/images/gallery/2026-03/scaled-1680-/854e1d8b-3195-435a-879b-b7992083c5f7.png)](http://wiki.igoni.kr/uploads/images/gallery/2026-03/854e1d8b-3195-435a-879b-b7992083c5f7.png)

</td></tr><tr><td class="align-right">perplexity에서 생성한 AI이미지</td></tr></tbody></table>

### 발생현상

1. #### 패스워드없이 root 로그인
    
    ```Python
    # mysql -u root
    Welcome to the MariaDB monitor. Commands end with ; or \g.
    Your MariaDB connection id is 15
    Server version: 10.4.7-MariaDB MariaDB Server
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    ```
2. #### DML / DDL 테스트 
    
    ```SQL
    MariaDB [(none)]> create database test123;
    Query OK, 1 row affected (0.003 sec)
    
    MariaDB [test123]> create table wow( name int);
    Query OK, 0 rows affected (0.008 sec)
    MariaDB [test123]> insert into wow values(123);
    Query OK, 1 row affected (0.003 sec)
    MariaDB [test123]> select * from wow;
    +------+
    | name |
    +------+
    | 123 |
    +------+
    1 row in set (0.001 sec)
    
    --
    MariaDB [(none)]> show databases;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mysql |
    | performance_schema |
    +--------------------+
    3 rows in set (0.001 sec)
    ```

### 왜?

1. unux\_socket 기능 활성화로 자동인증된 상태여서 그렇다고 하네요.

#### Unix\_Socket을 사용하는 이유는

1. unix\_socket을 사용하는 이유 
    - 보안성 강화 : OS계정을 기준으로 사용하기 때문에 별도의 계정으로 mysql root로그인은 할 수 없다고 합니다,
    - login 패스워드가 없기 때문에 무차별 대입(brute force) 공격에 유용합니다. 부수적으로 mysql root패스워드가 노출될수가 없다고 합니다. (패스워드 값이 없으니....)
2. 단점 
    - MariaDB에서도 기술한대로 여러사용자가 접속하는 경우에는 적합하진 않습니다.  
        "The unix\_socket authentication plugin is not suited to multiple Unix users accessing a single MariaDB user account."
    - 패스워드가 노출된 사용자가 sudo 명령어를 이용해 root 권한이 획득된 경우 DB접근도 자동으로 허용할 수 있습니다.

### unix\_socket 비활성화 방법

1. #### local socket 차단설정
    
    ```Python
    $> vi /etc/my.cnf
    
    [mariadb]
    ...
    unix_socket=OFF
    
    ```
2. #### root로 localhost 접근을 위한 DCL 적용
    
    ```sql
    MYSQL> grants for *.* to root@localhost identified by '{{ root 패스워드 }}';
    Query OK, 0 rows affected (0.011 sec)
    MYSQL> flush privileges;
    Query OK, 0 rows affected (0.001 sec)
    ```
3. #### Mariadb 서비스 재시작

### *reference*

- *<span class="wikiexternallink">[https://mariadb.com/kb/en/library/authentication-plugin-unix-socket/](https://mariadb.com/kb/en/library/authentication-plugin-unix-socket/)</span>*