개발자/리눅스

[CentOS] MariaDB 설치 및 설정

푸루닉 2024. 3. 27. 14:01

금일 포스팅은 마리아 db를 설치하고 설정 후 dbeaver에 연결하는 것 까지 진행할 예정이다.

이전 포스팅의 방화벽 여는것까지 설정되어 있는 것을 가정하고 진행할 것이다.

https://hwo7513565.tistory.com/125

 

[CentOS] CentOS 환경에서 Putty 연결(SSH,FTP,PUTTY) / jar 파일 구동 전 방화벽 열기/ VMWare Player 17 외부 인

https://hwo7513565.tistory.com/124 이전 포스팅에서 CentOS까지 구동했다는 가정하고 진행하겠습니다. jar파일을 구동하기 전 리눅스 환경에서 putty(ssh), 알드라이브 or 파일질라(FTP)에 접속할 수 있는 환경

hwo7513565.tistory.com

 

1. 마리아 db 설치

  가. mariadb repo 파일 생성

vi /etc/yum.repos.d/MariaDB.repo

 

편집모드에서 아래 내용을 입력한다. 필자는 10.11.2 버전을 사용하는데 각자 설정에 맞는 버전을 넣어주면 된다.

[mariadb]
name = MariaDB
baseurl = https://archive.mariadb.org/mariadb-10.11.2/yum/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

 

  나. yum으로 mariadb를 설치한다.

yum install epel-release -y

yum install -y MariaDB MariaDB-server MariaDB-client

epel-release를 다운로드 하지 않을 시 정상진행이 안되기때문에 먼저 다운로드 받은 후 

마리아 db 관련된 것을 다운로드 받는다.

 

  다.my.cnf 설정(마리아db 초기설정)

utf8 설정 및 테이블명 대소문자 구분하지 않도록 설정을 추가한다.

vi /etc/my.cnf
#
# This group is read both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include *.cnf from the config directory
#
!includedir /etc/my.cnf.d

[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
lower_case_table_names = 1

 

  라. mariadb 서버 시작

systemctl start mariadb 
또는 
service mariadb start
# 서버동작확인
systemctl status mariadb.service
# 부팅시 자동시작되도록 하려면
systemctl enable mariadb

 

  마. maraiDB 접속

mysql -u root –p

 

  바. 데이터베이스 확인

show databases;

 

  사. 데이터베이스 생성

create database [데이터베이스이름] default character set utf8 collate utf8_general_ci;

 

  아. 계정 권한 부여(root 계정이라 가정)

GRANT ALL PRIVILEGES ON *.* to 'root'@'%' IDENTIFIED BY 'dusrn!23';

  

2. DBeaver 툴에서 확인

이전 포스팅에 지정한 ip를 이용하여 DB를 연결합니다.

이때, 방화벽이 열려 있어야 하며 어디서든 접속이 가능하도록 권한이 설정되어 있어야 합니다.

(특정 ip만 접속가능하도록 설정도 가능함)