서버 환경
하드웨어 : CPU - 1 vCore, MEM - 1 GB, DISK - 25 GB )
운영체제 : Rocky Linux 9.4
MariaDB 버전 : MariaDB-Server 11.4.3
계정속성 : 관리자 권한이 부여된 사용자
외부 접근 권한 설정
MariaDB 접속
- MariaDB 서버에서 root 계정으로 접속한다.
$ mysql -u root -p
mysql: Deprecated program name. It will be removed in a future release, use '/usr/bin/mariadb' instead
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 11.4.3-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.
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]> select Host, User, Password from user;
+-----------+-------------+-------------------------------------------+
| Host | User | Password |
+-----------+-------------+-------------------------------------------+
| localhost | mariadb.sys | |
| localhost | root | *FC8770076242EAAE228D16BF3AED93C7328F81FE |
| localhost | mysql | invalid |
| | PUBLIC | |
+-----------+-------------+-------------------------------------------+
4 rows in set (0.001 sec)
- root 계정의 host가 localhost 이므로, 해당 서버에서만 접속이 가능하다.
외부에서 접속이 가능한 계정 생성
MariaDB [mysql]> create user 'root'@'%' identified by 'zerobase';
Query OK, 0 rows affected (0.003 sec)
MariaDB [mysql]> select Host, User, Password from user;
+-----------+-------------+-------------------------------------------+
| Host | User | Password |
+-----------+-------------+-------------------------------------------+
| localhost | mariadb.sys | |
| localhost | root | *FC8770076242EAAE228D16BF3AED93C7328F81FE |
| localhost | mysql | invalid |
| | PUBLIC | |
| % | root | *54CD1E3A9315150E5D35C734A348C8DF80049F9C |
+-----------+-------------+-------------------------------------------+
5 rows in set (0.001 sec)
- root 계정을 생성하는 데, 모든 host에서의 접근을 허용한다는 것을 의미한다.
- identified by '패스워드'는 해당 계정에 사용할 패스워드를 설정한다.
생성한 계정에 권한 부여 하기
/*
기본 구조
GRANT ALL PRIVILEGES ON DB명.테이블 TO '계정'@'접속호스트' IDENTIFIED BY '비밀번호';
계정이 이미 존재하는 경우, IDENTIFIED BY '비밀번호' 구문은 생략할 수 있다.
해당 구문을 입력하는 경우 작성된 비밀번호로 계정의 패스워드가 변경된다.
*/
MariaDB [mysql]> grant all privileges on root.* to 'root'@'%' identified by 'zerobase';
Query OK, 0 rows affected (0.003 sec)
MariaDB [mysql]> show grants for 'root'@'%';
+-----------------------------------------------------------------------------------------------------+
| Grants for root@% |
+-----------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `root`@`%` IDENTIFIED BY PASSWORD '*54CD1E3A9315150E5D35C734A348C8DF80049F9C' |
| GRANT ALL PRIVILEGES ON `root`.* TO `root`@`%` |
+-----------------------------------------------------------------------------------------------------+
2 rows in set (0.000 sec)
계정 권한 설정 적용 하기
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
- 계정과 관련된 정보가 변경되었을 때는 필히 수행하여야 한다.
만약, 작업 후 해당 쿼리를 수행하지 않고 빠져나올 경우 변경된 사항이 적용되지 않는다.
외부에서 접속 확인 하기
- MariaDB Server와 동일한 버전의 설치 파일 또는 포터블 파일을 다운로드 받는다. ( 포터블 파일을 기준으로 작성됨. )
- 터미널을 실행하여 포터블 압축 파일을 압축 해제한 폴더의 bin 폴더로 이동한다.
- ".\mysql.exe -h 서버IP -P 포트 -u 계정 -p" 입력 후 엔터를 누른다.
( MariaDB의 설치파일을 내려받아 클라이언트를 설치한 경우, "mysql -h 서버IP -P 포트 -u 계정 -p"로 입력하면 된다. )
- 이후 정상적으로 접속이 되면은 아래의 블럭처럼 나오는 것을 확인할 수 있다.
PS D:\mariadb-11.4.3-winx64\bin> .\mysql.exe -h '서버IP" -P "포트" -u "계정" -p
Enter password: ********
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 11.4.3-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.
MariaDB [(none)]>