본문 바로가기

DB관련

테스트 용 Rocky Linux9 에 Maria DB 설치

728x90

1. 설치

1. sudo dnf -y install mariadb-server
2. sudo systemctl enable --now mariadb
3. sudo systemctl status mariadb

 

1.2 보안 설정(운영자가 아니다 보니 이게 필요한지는 모르겠음..)

1. sudo mariadb-secure-installation

Switch to unix_socket authentication [Y/n] → Y

그 다음 질문들은 보통 이렇게.

Remove anonymous users?        Y
Disallow root login remotely?  Y
Remove test database?          Y
Reload privilege tables?       Y

 

1.3 로컬 접속 테스트

sudo mariadb

혹은 

mariadb -u root -p

이때 로그인 안 되면, 
1. ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewRootPass!1234';
2. FLUSH PRIVILEGES;
시도해 볼 것.

[실행 결과]
[app@test11 ~]$ mariadb -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 10.5.29-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)]>

 

원격에서 접속하는 방법

2-1 서버가 리슨하는 주소 확인(바인드)

MariaDB 설정 파일은 환경에 따라 다르지만 보통 아래 중 하나.

  • /etc/my.cnf.d/mariadb-server.cnf
  • /etc/my.cnf

[mysqld] 아래에 아래처럼 지정(예: 사내망 IP로만 제한)

[mysqld]
bind-address=0.0.0.0 # (권장X) 전체 오픈
# bind-address=192.168.56.101 # (권장) 특정 IP로 제한

 

적용은 마리아DB 재시작

sudo systemctl restart mariadb

 

2-2 DB 사용자 생성/권한 부여

1. CREATE DATABASE appdb DEFAULT CHARACTER SET utf8mb4;
2. CREATE USER 'appuser'@'192.168.56.%' IDENTIFIED BY '강력한비번';
3. GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'192.168.56.%';
4. FLUSH PRIVILEGES;

%는 전체를 의미하는 것이니, 대역대로 설정하려거든 %를 써서 진행

 

 

 

heidisql 설치해서 생성한 계정으로 로그인 되는지 확인해보면 된다.

 

추가적으로 버전 확인은 db 접속하면 나오기도 하는데,

db 접속후 selcet version(); 해도 나온다.

MariaDB [(none)]> select version();
+-----------------+
| version()       |
+-----------------+
| 10.5.29-MariaDB |
+-----------------+
1 row in set (0.000 sec)