서버 운영/APM 서버 구축

MariaDB 10.4 이후의 계정 인증 관련 변화(unix_socket, mysql_native_password 인증 / 계정, 암호 및 전역 권한 정보 저장 테이블 변경 등)

씨실과 날실 2020. 9. 24. 09:00

[관련 게시물]

Ubuntu 20.04 LTS에서 APM 설치

2020/09/14 - [서버 운영/APM 서버 구축] - 우분투(Ubuntu) 20.04에서 APM 설치 - 아파치(Apache2 설치

2020/09/16 - [서버 운영/APM 서버 구축] - 우분투(Ubuntu) 20.04에서 APM 설치 - 마리아DB(MariaDB) 10.3 설치

2020/09/18 - [서버 운영/APM 서버 구축] - 우분투(Ubuntu) 20.04에서 APM 설치 - 마리아DB(MariaDB) 10.5 설치

2020/09/20 - [서버 운영/APM 서버 구축] - 우분투(Ubuntu) 20.04에서 APM 설치 - PHP 7.4 설치

2020/09/22 - [서버 운영/APM 서버 구축] - 우분투(Ubuntu) 20.04에서 APM 설치 - APM 설치 후 방화벽 설정

2020/09/24 - [서버 운영/APM 서버 구축] - MariaDB 10.4 이후의 계정 인증 관련 변화(unix_socket, mysql_native_password 인증 / 계정, 암호 및 전역 권한 정보 저장 테이블 변경 등)

2020/09/26 - [서버 운영/APM 서버 구축] - 우분투 20.04 APM 서버 기본 환경 파일 설정 - apache2.conf 기본 설정

2020/09/28 - [서버 운영/APM 서버 구축] - 우분투 20.04 APM 서버 기본 환경 파일 설정 - php.ini 기본 설정

 

Ubuntu 20.04에서 설치한 Apache2 서버 주요 설정 파일 원문

2020/09/30 - [서버 운영/APM 서버 구축] - 우분투 20.04 APM 서버 주요 환경 파일 목록

2020/10/05 - [서버 운영/APM 서버 구축] - 우분투 20.04 APM 서버 주요 환경 파일 원문 - Apache2

2020/10/07 - [서버 운영/APM 서버 구축] - 우분투 20.04 APM 서버 주요 환경 파일 원문 - PHP 7.4 - php.ini

 

Ubuntu 20.04에서 설치한 Apache2 서버 주요 설정 파일 내 지시어 설명

2020/10/09 - [서버 운영/APM 서버 구축] - [Ubuntu 20.04 - Apache2 서버] apache2.conf의 기본값에 사용된 지시어 설명

2020/10/11 - [서버 운영/APM 서버 구축] - [Ubuntu 20.04 - Apache2 서버] ports.conf 의 기본값에 사용된 지시어 설명

2020/10/13 - [서버 운영/APM 서버 구축] - [Ubuntu 20.04 - Apache2 서버] envvars의 기본값에 사용된 지시어 설명

2020/10/15 - [서버 운영/APM 서버 구축] - [Ubuntu 20.04 - Apache2 서버] security.conf의 기본값에 사용된 지시어 설명

2020/10/17 - [서버 운영/APM 서버 구축] - [Ubuntu 20.04 - Apache2 서버] 000-default.conf의 기본값에 사용된 지시어 설명

2020/10/19 - [서버 운영/APM 서버 구축] - [Ubuntu 20.04 - Apache2 서버] default-ssl.conf의 기본값에 사용된 지시어 설명

 

Ubuntu 20.04에서 phpMyAdmin 설치 및 설정

2021.02.20 - [서버 운영/APM 서버 구축] - 우분투 20.04에서 phpMyAdmin 설치 01 - 저장소 설치

2021.03.15 - [서버 운영/APM 서버 구축] - 우분투 20.04에서 phpMyAdmin 설치 02 - Apache 서버 관리자를 위한수동 설치(버전 5.1.0 기준)

2021.03.17 - [서버 운영/APM 서버 구축] - 우분투 20.04에서 phpMyAdmin 설치 03 - 보안강화 작업

2021.03.19 - [서버 운영/APM 서버 구축] - phpMyAdmin 설치 04 - 웹호스팅 사용자를 위한 수동 설치(버전 5.1.0 기준)

2021.03.21 - [서버 운영/APM 서버 구축] - phpMyAdmin 설치 05 - setup 페이지를 통한 구성 파일 생성

Ubuntu 18.04 LTS에서 APM 설치

2018/11/09 - [서버 운영/APM 서버 구축] - Apache 서버 설치

2018/11/14 - [서버 운영/APM 서버 구축] - MariaDB 설치

2018/11/16 - [서버 운영/APM 서버 구축] - MariaDB 업그레이드 1

2018/11/16 - [서버 운영/APM 서버 구축] - MariaDB 업그레이드 2 - ERROR 1524 (HY000): Plugin 'unix_socket' is not loaded

2018/11/16 - [서버 운영/APM 서버 구축] - MariaDB 업그레이드 3

2018/11/19 - [서버 운영/APM 서버 구축] - PHP7 설치

2018/11/21 - [서버 운영/APM 서버 구축] - 서버 환경 파일 수정 - php.ini, apache2.conf

 

Ubuntu 18.04 LTS에서 MariaDB 백업 및 업그레이드

2019/01/15 - [서버 운영/APM 서버 구축] - MariaDB & MySQL 백업과 복원 - Nextcloud 14

2019/06/27 - [서버 운영/APM 서버 구축] - MariaDB 업그레이드 (Upgrading from MariaDB 10.3 to MariaDB 10.4)

 

Ubuntu 18.04 LTS에서 PHP 버전 전환

2019/07/05 - [서버 운영/APM 서버 구축] - Apache와 Shell에서 PHP 버전 전환하기(How to Switch between Multiple PHP Version)

 

Ubuntu 18.04 LTS에서 phpmyadmin 설치 및 운용

2018/11/23 - [서버 운영/APM 서버 구축] - phpmyadmin 설치 - APT 패키지 관리자를 통한 설치

2019/06/18 - [서버 운영/APM 서버 구축] - APT 패키지 관리자를 통해 설치한 phpMyAdmin 업그레이드 방법(업그레이드 버전 4.9.0.1)

2019/07/01 - [서버 운영/APM 서버 구축] - phpMyAdmin 수동 설치 01 - 일반 설치

2019/07/03 - [서버 운영/APM 서버 구축] - phpMyAdmin 수동 설치 02 - 심볼릭 링크를 이용한 보안 접속

2019/06/16 - [서버 운영/APM 서버 구축] - phpMyAdmin 4.6.6deb5와 PHP 7.2 간 호환성 문제 해결 - Warning in ./libraries/sql.lib.php#613

 

XAMPP 설치 및 운용

2019/04/20 - [서버 운영/서버 구축 꾸러미] - XAMPP에 대하여(버전 7.1.28 / 7.2.17 / 7.3.4)

2019/04/22 - [서버 운영/서버 구축 꾸러미] - XAMPP for Windows 7.3.4 인스톨러 설치

2019/04/25 - [서버 운영/서버 구축 꾸러미] - XAMPP for Windows 설정

2019/06/03 - [서버 운영/서버 구축 꾸러미] - XAMPP 포터블(portable) 사용법

2019/06/05 - [서버 운영/서버 구축 꾸러미] - XAMPP for Linux 4.3.5 설치 및 사용법

 

서버 운영을 위한 관련 연재글

2018/11/07 - [리눅스/Ubuntu] - 방화벽 설정 - ufw

2018/11/12 - [서버 운영/버추얼박스(VirtualBox)] - 가상머신(Virtualbox) 내 서버 외부접속

2019/01/05 - [미디어위키/미디어위키 설치 및 관리] - 호스트 컴퓨터에서 가상머신 내 미디어위키 접속 및 작업을 위한 버추얼박스 포트포워딩 설정

2019/03/15 - [서버 운영/APM 서버 구축] - PHP 7.3으로의 업그레이드 및 사용 연기 권장 안내 - PHP Notice: compact(): Undefined variable:

 

[관련 웹문서]

https://mariadb.com/kb/en/authentication-plugin-unix-socket/#unix_socket

 

 

 

MariaDB의 Root 계정 보호 강화

MariaDB 보안설정 실행 시의 변화

이제 MariaDB 10.4부터는 설치 스크립트 또는 mariadb-secure-installation(= mysql_secure_installation) 보안 설정 시 MariaDB 루트 사용자를 위한 암호 설정을 강요하지 않습니다.

 

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

예를 들어 MariaDB 10.3 이전의 경우 보안 설정을 실행하면 위와 같이 루트 계정의 암호를 설정하면 적절한 권한 없이는 누구도 MariaDB 루트 사용자에 로그인 할 수 없다고 알려주며 암호 설정 여부를 물음으로써 간접적으로 암호 설정할 것을 권유합니다.

 

study@study-VirtualBox:~$ sudo mariadb-secure-installation
[sudo] study의 암호: 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] y
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

그러나 MariaDB 10.4 부터는 보안 설정을 실행하면 위와 같이 루트 계정이 이미 보호되어 있으므로 unix_socket 인증 설정이나 암호 설정 여부에 n(No)이라 답하더라도 안전하다고 설명하고 있습니다.

MariaDB 인증 방식(MariaDB 10.4 이후)

MariaDB는 계정 인증 방식으로 두 가지 방식이 있는데 하나는 mysql_native_password 인증 방식이고 또 다른 하나는 Unix socket 인증 방식입니다.

각 계정은 두 인증 방식을 동시에 사용할 수 있습니다. 실제로 root 계정은 두 인증 플러그인을 동시에 사용할 수 있도록 설정된 채 생성됩니다.

MariaDB가 설치되면 기본적으로 아래와 같은 명령이 실행된 것처럼 root와 mysql 계정이 생성됩니다.

 

CREATE USER root@localhost IDENTIFIED VIA unix_socket OR mysql_native_password USING 'invalid'
CREATE USER mysql@localhost IDENTIFIED VIA unix_socket OR mysql_native_password USING 'invalid'

위 명령을 보면 알 수 있듯이 두 인증 방식을 동시에 사용할 수 있도록 설정되어 있습니다. 참고로 위 기본설정은 MariaDB 10.4 이후 버전부터 적용됩니다.

unix_socket 인증 플러그인으로 인증을 시도하거나 mysql_native_password 인증 플러그인으로 인증을 시도할 수 있도록 구성됩니다. 주의할 점은 mysql_native_password 인증의 경우 초기에는 유효하지 않은 암호(invalid)가 설정되어 있으므로 이러한 방식으로 인증하려면 MariaDB 콘솔에 로그인하여 SET PASSWORD로 암호를 설정해주어야 합니다.

 

MariaDB [(none)]> set password = password("새로운 비밀번호 입력");

 

unix_socket 인증

unix_socket 인증을 간단히 설명하자면 유닉스 계열 운영체제의 사용자 계정과 MariaDB의 사용자 계정을 일치시키는 인증 방식을 일컫습니다.

즉 유닉스 계열 운영체제의 root 계정(또는 root 계정의 권한을 가진 계정)은 MariaDB의 root 계정을 소유하여 관리할 수 있도록 한 것입니다.

이 unix_socket 인증을 사용하면 유닉스 계열 운영 체제의 루트 사용자가 소유 및 실행한 프로세스에서 MariaDB 콘솔에 로그인하는 경우 소켓 시스템 변수에 정의된 로컬 Unix 소켓 파일을 통해 암호 입력 없이 로그인 할 수 있습니다.

 

mysql_native_password 인증

mysql_native_password 인증 방식은 전통적으로 쓰이던 방식으로 로그인 시 아래와 같이 계정명과 암호를 입력하여 로그인하는 방식입니다.

$ mariadb -u root -p

또는

$ mysql -u root -p

 


 

 

MariaDB 10.3 인증

MariaDB 10.3 버전 확인

 

study@study-VirtualBox:~$ mariadb -V
mariadb  Ver 15.1 Distrib 10.3.22-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
study@study-VirtualBox:~$ 

MariaDB 콘솔 접속

Unix_socket 인증 통한 로그인

 

 

study@study-VirtualBox:~$ sudo mariadb
[sudo] study의 암호: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 36
Server version: 10.3.22-MariaDB-1ubuntu1 Ubuntu 20.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

 

mysql_native_password 인증 통한 로그인 - 실패

 

study@study-VirtualBox:~$ mariadb -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
study@study-VirtualBox:~$ 

MariaDB 10.3 초기 설정값에서는 mysql_native_password 인증을 사용할 수 없습니다.

 

인증 플러그인 변경

 

 

study@study-VirtualBox:~$ sudo mariadb
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 59
Server version: 10.3.22-MariaDB-1ubuntu1 Ubuntu 20.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SELECT user,host,plugin,authentication_string FROM mysql.user;
+------+-----------+-------------+-----------------------+
| user | host      | plugin      | authentication_string |
+------+-----------+-------------+-----------------------+
| root | localhost | unix_socket |                       |
+------+-----------+-------------+-----------------------+
1 row in set (0.000 sec)

MariaDB [(none)]> 

유닉스 소켓 인증으로 로그인하여 인증 플그인을 확인해보면  unix_socket 인증 플러그인으로 설정되어 있는 것을 확인할 수 있습니다.

 

 

 

MariaDB [(none)]> ALTER USER root@localhost IDENTIFIED VIA mysql_native_password;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> set password = password("0000");
Query OK, 0 rows affected, 1 warning (0.029 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]>

위 방법으로 인증 플러그인을 변경하고 암호를 설정해줍니다.

 

 

MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> update user set plugin='mysql_native_password' where user='root';
Query OK, 1 row affected (0.012 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> set password = password("0000");
Query OK, 0 rows affected, 1 warning (0.001 sec)

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

MariaDB [mysql]>

ALTER USER 구문 대신 update user구문을 사용할 수도 있는데 이 구문을 사용하기 위해서는 mysql 데이터베이스에서 실행해야 합니다.

 

 

 

MariaDB [(none)]> SELECT user,host,plugin,authentication_string FROM mysql.user;
+------+-----------+-----------------------+-------------------------------------------+
| user | host      | plugin                | authentication_string                     |
+------+-----------+-----------------------+-------------------------------------------+
| root | localhost | mysql_native_password | *97E7471D816A37E38510728AEA47440F9C6E2585 |
+------+-----------+-----------------------+-------------------------------------------+
1 row in set (0.000 sec)

MariaDB [(none)]> exit;
Bye
study@study-VirtualBox:~$ 

위 방법으로 인증 플러그인과 인증 암호(문자열)을 확인할 수 있습니다.

MySQL 계열 DB 프로그램에서는 authentication_string값으로 'MySQLSHA1' 해시를 사용합니다.

그누보드 등 많은 CMS 프로그램이 초기 비밀번호로 '0000'을 사용하는데 이것을 'MySQLSHA1' 해시값로 변환화면 97E7471D816A37E38510728AEA47440F9C6E2585이 됩니다.

https://hash.darkbyte.ru/~MDAwMA==

 

 

study@study-VirtualBox:~$ sudo mariadb ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) study@study-VirtualBox:~$

인증 플러그인 변경 후에는 unix_socket 인증을 통한 로그인이 되지 않습니다.

 

 

 

study@study-VirtualBox:~$ mariadb -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 38
Server version: 10.3.22-MariaDB-1ubuntu1 Ubuntu 20.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> \q
Bye
study@study-VirtualBox:~$ 
mysql_native_password 인증 방식으로 계정명과 암호를 입력하여 로그인이 가능하게 됩니다.

 


 

 

MariaDB 10.5 인증

MariaDB 10.3 이전까지는 unix_socket인증과 mysql_native_password 인증 둘 중 하나만 사용 가능합니다.

MariaDB 10.4 이후부터는 두 인증을 동시에 사용할 수 있습니다.

MariaDB 버전 확인

 

study@study-VirtualBox:~$ mariadb -V
mariadb  Ver 15.1 Distrib 10.5.5-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
study@study-VirtualBox:~$ 

MariaDB 콘솔 접속

Unix_socket 인증 통한 로그인

 

 

study@study-VirtualBox:~$ sudo mariadb
[sudo] study의 암호: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 30
Server version: 10.5.5-MariaDB-1:10.5.5+maria~focal mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> \q
Bye
study@study-VirtualBox:~$ 

 

mysql_native_password 인증 통한 로그인 - 실패

study@study-VirtualBox:~$ mariadb -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
study@study-VirtualBox:~$ 
MariaDB 10.5 초기 설정값에서는 mysql_native_password 인증을 사용할 수 없습니다.

 

mysql_native_password 인증 통한 로그인 방식 추가

MariaDB [(none)]> SELECT user,host,plugin,authentication_string FROM mysql.user;
+-------------+-----------+-----------------------+-----------------------+
| User        | Host      | plugin                | authentication_string |
+-------------+-----------+-----------------------+-----------------------+
| mariadb.sys | localhost | mysql_native_password |                       |
| root        | localhost | mysql_native_password | invalid               |
| mysql       | localhost | mysql_native_password | invalid               |
+-------------+-----------+-----------------------+-----------------------+
3 rows in set (0.001 sec)

MariaDB [(none)]> 

MariaDB 10.3과는 인증 플러그인 기본값이 다릅니다.  인증 플러그인이 mysql_native_password로 설정되어 있으나 인증 문자열값이 invalid로 설정되어 있어 mariadb -u root -p 명령으로 로그인이 되지 않습니다.

 

 

MariaDB [(none)]> set password = password("0000");
Query OK, 0 rows affected (0.002 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> 

unix_socket 인증으로 로그인하여 위와 같이 암호를 설정해줍니다.

0000 대신 원하는 암호로 바꿔주시면 됩니다.

 

 

MariaDB [(none)]> SELECT user,host,plugin,authentication_string FROM mysql.user;
+-------------+-----------+-----------------------+-------------------------------------------+
| User        | Host      | plugin                | authentication_string                     |
+-------------+-----------+-----------------------+-------------------------------------------+
| mariadb.sys | localhost | mysql_native_password |                                           |
| root        | localhost | mysql_native_password | *97E7471D816A37E38510728AEA47440F9C6E2585 |
| mysql       | localhost | mysql_native_password | invalid                                   |
+-------------+-----------+-----------------------+-------------------------------------------+
3 rows in set (0.001 sec)

MariaDB [(none)]> \q
Bye
study@study-VirtualBox:~$ 

다시 한번 인증 플러그인과 인증 문자열값을 확인해보면 위와 같이 변경됨을 확인할 수 있습니다.

 

 

 

study@study-VirtualBox:~$ mariadb -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 32
Server version: 10.5.5-MariaDB-1:10.5.5+maria~focal mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> \q
Bye
study@study-VirtualBox:~$ 

위와 같이 mysql_native_password 인증을 통한 로그인이 가능합니다.

 

 

 

study@study-VirtualBox:~$ sudo mariadb
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 33
Server version: 10.5.5-MariaDB-1:10.5.5+maria~focal mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> \q
Bye
study@study-VirtualBox:~$ 

물론 unix_socket 인증을 통한 로그인도 가능합니다. MariaDB 10.3 이전 버전과 다른 점입니다.

 

mysql_native_password 인증 통한 로그인으로 고정

 

 

MariaDB [(none)]> ALTER USER root@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD("0000");
Query OK, 0 rows affected (0.005 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> 

위와 같이 ALTER USER 구문을 사용하면 로그인 인증 방식을 고정할 수 있습니다.

 

 

 

study@study-VirtualBox:~$ sudo mariadb
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
study@study-VirtualBox:~$

인증 방식을 mysql_native_password 인증으로 고정하면 unix_socket 인증은 위와 같이 실패하게 됩니다.

 

 

study@study-VirtualBox:~$ mariadb -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 38
Server version: 10.5.5-MariaDB-1:10.5.5+maria~focal mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> \q
Bye
study@study-VirtualBox:~$ 

 


 

 

MariaDB 사용자 계정, 암호 및 전역 권한 정보 저장 테이블 변경

이전에는 MariaDB의 모든 사용자 계정, 암호 및 전역 권한이 mysql.user 테이블에 저장되었습니다.

그러나 MariaDB 10.4부터는 해당 정보를 mysql.global_priv 테이블에 저장됩니다.

물론 과거와의 호환성 유지를 위해 mysql.user 테이블은 유지되지만 이 테이블은 이제 mysql.global_priv 테이블을 참조하는 일종의 뷰 기능을 할 뿐입니다.

 

https://mariadb.com/kb/en/mysqlglobal_priv-table/

 

MariaDB [(none)]> SELECT user,host,plugin,authentication_string FROM mysql.user;
+-------------+-----------+-----------------------+-------------------------------------------+
| User        | Host      | plugin                | authentication_string                     |
+-------------+-----------+-----------------------+-------------------------------------------+
| mariadb.sys | localhost | mysql_native_password |                                           |
| root        | localhost | mysql_native_password | *97E7471D816A37E38510728AEA47440F9C6E2585 |
| mysql       | localhost | mysql_native_password | invalid                                   |
+-------------+-----------+-----------------------+-------------------------------------------+
3 rows in set (0.001 sec)

MariaDB [(none)]> 

mysql.user 테이블 내용을 확인한 모습입니다. 실제로는 두 인증 플러그인을 사용할 수 있더라도 해당 테이블에는 인증 플러그인이 하나만 표시됩니다.

인증 플러그인의 정확한 정보는 아래와 같이 mysql.global_priv 테이블을 확인해야 합니다.

 

 

MariaDB [(none)]> select * from mysql.global_priv;
+-----------+-------------+--------------------------------------------------------------------------------------------------------------------------------------------+
| Host      | User        | Priv                                                                                                                                       |
+-----------+-------------+--------------------------------------------------------------------------------------------------------------------------------------------+
| localhost | mariadb.sys | {"access":0,"plugin":"mysql_native_password","authentication_string":"","account_locked":true,"password_last_changed":0}                   |
| localhost | root        | {"access":18446744073709551615,"plugin":"mysql_native_password","authentication_string":"invalid","auth_or":[{},{"plugin":"unix_socket"}]} |
| localhost | mysql       | {"access":18446744073709551615,"plugin":"mysql_native_password","authentication_string":"invalid","auth_or":[{},{"plugin":"unix_socket"}]} |
+-----------+-------------+--------------------------------------------------------------------------------------------------------------------------------------------+
3 rows in set (0.000 sec)

MariaDB [(none)]> 

이것을 가독성을 높여 표현 형식을 바꿔봅시다.

 

 

 

MariaDB [(none)]> select concat(user, '@', host, ' => ', json_detailed(priv)) from mysql.global_priv;
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| concat(user, '@', host, ' => ', json_detailed(priv))                                                                                                                                                                                                                 |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| mariadb.sys@localhost => {
    "access": 0,
    "plugin": "mysql_native_password",
    "authentication_string": "",
    "account_locked": true,
    "password_last_changed": 0
}                                                                                     |
| root@localhost => {
    "access": 18446744073709551615,
    "plugin": "mysql_native_password",
    "authentication_string": "invalid",
    "auth_or": 
    [
        
        {
        },
        
        {
            "plugin": "unix_socket"
        }
    ]
}  |
| mysql@localhost => {
    "access": 18446744073709551615,
    "plugin": "mysql_native_password",
    "authentication_string": "invalid",
    "auth_or": 
    [
        
        {
        },
        
        {
            "plugin": "unix_socket"
        }
    ]
} |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3 rows in set (0.000 sec)

MariaDB [(none)]> 

MariaDB 10.5의 초기값입니다. 여기서 우리가 볼 부분은 root@localhost 계정 정보입니다.

 

| root@localhost => {
    "access": 18446744073709551615,
    "plugin": "mysql_native_password",
    "authentication_string": "invalid",
    "auth_or":
    [
        
        {
        },
        
        {
            "plugin": "unix_socket"
        }
    ]
}  |

mysql.user 테이블에서 확인할 수 있는 정보와는 달리 플러그인이  mysql_native_password와 unix_socket 모두 활성화되어 있음을 확인할 수 있습니다. 단, mysql_native_password 인증 플러그인의 authentication_string값은 invalid로 설정되어 있어 실제로는 해당 플러그인을 사용할 수 없도록 되어 있습니다.

18446744073709551615에 대하여

숫자(정수) 18,446,744,073,709,551,615는 사람들이 한 눈에 보고 이해하기에는 큰수로 이것을 2의 거듭제곱수로 변환하면 2의 64승 -1을 의미합니다.

0을 제외하고 1부터 시작하는 일반적인 자연수 체계에서는 이 큰수가 2의 64승 -1이 맞지만 0과1 이진법을 채택하고 있는 컴퓨터의 정보 저장 방식에 있어서 첫 수가 1이 아닌 0부터 시작되므로 저 수는 2의 64승을 의미합니다.

왜 하필 2의 64승이냐면 현재 주류 컴퓨터 CPU의 BUS 단위가 64bit이기 때문입니다.

컴퓨터 세계에서 64비트란 우리가 알기 쉽게 비유하자면 64개의 초가 존재한 것과 같습니다. 초에 불이 꺼져 있는 상태(0)과 반대로 불이 켜져 있는 상태(1) 이 두 상태만 있습니다. 초가 하나도 안 켜져 있는 상태부터 모두 켜져 켜져있는 상태까지 모두하여 2의 64승의 경우의 수가 존재하는 것입니다.

 

MariaDB에서 계정 사용자의 access 상태는 On, Off 이 두 상태밖에 없습니다. 만약 비로그인상태라면 당연히 값이 0(64자리의 숫자가 모두 0)이 됩니다. 반대로 접속 중이라면 1이 될텐데 이것을 MariaDB는 64자리의 숫자를 모두 1로 저장하여 표시합니다. 이것을 우리가 사용하는 10진수로 변환하여 표시하니 18446744073709551615로 표시되는 것입니다.

 

18446744073709551615 이 수는 컴퓨터 정보 처리와 관련하여 최대 허용값으로 빈번히 사용되므로 알아두면 좋습니다.

 

MariaDB [(none)]> select concat(user, '@', host, ' => ', json_detailed(priv)) from mysql.global_priv;
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| concat(user, '@', host, ' => ', json_detailed(priv))                                                                                                                                                                                                                                                                                           |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| mariadb.sys@localhost => {
    "access": 0,
    "plugin": "mysql_native_password",
    "authentication_string": "",
    "account_locked": true,
    "password_last_changed": 0
}                                                                                                                                                               |
| root@localhost => {
    "access": 18446744073709551615,
    "plugin": "mysql_native_password",
    "authentication_string": "*97E7471D816A37E38510728AEA47440F9C6E2585",
    "auth_or": 
    [
        
        {
        },
        
        {
            "plugin": "unix_socket"
        }
    ],
    "password_last_changed": 1600166642
} |
| mysql@localhost => {
    "access": 18446744073709551615,
    "plugin": "mysql_native_password",
    "authentication_string": "invalid",
    "auth_or": 
    [
        
        {
        },
        
        {
            "plugin": "unix_socket"
        }
    ]
}                                                                           |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3 rows in set (0.000 sec)

MariaDB [(none)]> 

 

| root@localhost => {
    "access": 18446744073709551615,
    "plugin": "mysql_native_password",
    "authentication_string": "*97E7471D816A37E38510728AEA47440F9C6E2585",
    "auth_or":
    [
        
        {
        },
        
        {
            "plugin": "unix_socket"
        }
    ],
    "password_last_changed": 1600166642
} |

이번에는 두 인증 플러그인이 모두 설정되어 있고 mysql_native_password 플러그인의 authentication_string 값도 설정되어 있음을 확인할 수 있습니다.

참고로 최근 암호 변경 시점도 10자리 숫자로 확인할 수 있습니다. 이 우리가 이란적으로 쉽게 이해할 수 있는 정보로 변환하면 한국시각으로 2020. 09. 15. (화) 19:44:02가 됩니다.

이 10자리 숫자는 타임스탬프와 유닉스 시간에 대한  이해가 필요합니다. 이에 대한 내용은 조만간 따로 포스팅하도록 하겠습니다.

 

 

MariaDB [(none)]> select concat(user, '@', host, ' => ', json_detailed(priv)) from mysql.global_priv;
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| concat(user, '@', host, ' => ', json_detailed(priv))                                                                                                                                                                                                                                           |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| mariadb.sys@localhost => {
    "access": 0,
    "plugin": "mysql_native_password",
    "authentication_string": "",
    "account_locked": true,
    "password_last_changed": 0
}                                                                                                               |
| root@localhost => {
    "access": 274877906943,
    "plugin": "mysql_native_password",
    "authentication_string": "*97E7471D816A37E38510728AEA47440F9C6E2585",
    "auth_or": 
    [
        
        {
        }
    ],
    "password_last_changed": 1600166750,
    "version_id": 100505
} |
| mysql@localhost => {
    "access": 18446744073709551615,
    "plugin": "mysql_native_password",
    "authentication_string": "invalid",
    "auth_or": 
    [
        
        {
        },
        
        {
            "plugin": "unix_socket"
        }
    ]
}                           |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3 rows in set (0.001 sec)

MariaDB [(none)]> 

 

| root@localhost => {
    "access": 274877906943,
    "plugin": "mysql_native_password",
    "authentication_string": "*97E7471D816A37E38510728AEA47440F9C6E2585",
    "auth_or":
    [
        
        {
        }
    ],
    "password_last_changed": 1600166750,
    "version_id": 100505
} |

이번에는 unix_socket 플러그인 정보가 사라진 것을 확인할 수 있습니다. 이 상태에서는 unix_socket 인증을 통한 로그인이 불가능합니다.