Skip to content

Instantly share code, notes, and snippets.

@devwithpug
Last active September 19, 2021 13:08
Show Gist options
  • Save devwithpug/aaadbe1e04bc41fc79f293f92c9a0e75 to your computer and use it in GitHub Desktop.
Save devwithpug/aaadbe1e04bc41fc79f293f92c9a0e75 to your computer and use it in GitHub Desktop.
centos 8 에서 mariadb 설치 및 외부접속 설정

CentOS 8 에서 MariaDB 설치 및 외부접속 허용

  1. 패키지 저장소 업데이트
$ sudo dnf update
  1. https://mariadb.org/download/로 이동하여 자신에게 맞는 배포 및 버전 선택

distribution, MariaDB Server viersion, Mirror 모두 선택하면 아래에 다음과 비슷한 설정 파일이 나옴

  • /etc/yum/repos.d/MariaDB.repo 파일 생성 후 저장
# MariaDB 10.6 CentOS repository list - created 2021-09-19 12:52 UTC
# https://mariadb.org/download/
[mariadb]
name = MariaDB
baseurl = https://mirror.yongbok.net/mariadb/yum/10.6/centos8-amd64
module_hotfixes=1
gpgkey=https://mirror.yongbok.net/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
  1. MariaDB-server 설치
$ sudo dnf install MariaDB-server
  1. 초기 설정 시작
$ sudo mysql-secure-installation
  1. mariadb 서버 자동으로 시작되도록 설정
$ sudo systemctl enable mariadb
  1. 리눅스 포트 개방
  • /etc/my.cnf 에 아래와 같이 3306 포트 추가
#
# This group is read both by the client and the server
# use it for options that affect everything
#
[client-server]
port = 3306
  1. 방화벽 인바운드 포트 추가
$ sudo firewall-cmd --permanent --add-port=3306/tcp
$ sudo firewall-cmd --reload
  1. mariadb 서버 설정
  • /etc/my.cnf.d/server.cnf
# Allow server to accept connections on all interfaces.
#
bind-address=0.0.0.0
  1. mariadb 서비스 재시작
$ sudo systemctl restart mariadb
  1. mariadb 루트계정 외부접속 설정
$ mysql -u root -p

MariaDB [(none)]> create user 'root'@'%' identified via mysql_native_password using password ("비밀번호");
MariaDB [(none)]> grant all privileges on *.* to 'root'@'%' with grant option;
MariaDB [(none)]> flush privileges;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment