우분투(Ubuntu) Linux MariaDB 설치 및 DB, 계정 생성

2024. 9. 19. 22:53·데이터베이스/MySQL•MariaDB
728x90
반응형


1. MariaDB 설치하기

  • MariaDB의 Server와 Client 패키지 설치
apt install mariadb-server mariadb-client
  • MariaDB 접속 확인
mariadb

2. MariaDB 보안 설정

  • 아래 명령어를 입력하면 root에 대한 패스워드 및 테스트 테이블에 대한 삭제 등을 진행하실 수 있습니다.
mariadb-secure-installation
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
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
 
Enter current password for root (enter for none):
OK, successfully used password, moving on...
 
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
## root 암호 설정 여부 : Y 권장
Set root password? [Y/n]

New password: mariadb!
Re-enter new password: mariadb! 
Password updated successfully!
Reloading privilege tables..
 ... Success!
 
 
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
## 익명 사용자 삭제 여부 : Y 권장
Remove anonymous users? [Y/n]

... Success!
 
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
## root 원격 접속 차단 여부 : Y 권장
Disallow root login remotely? [Y/n]

... Success!
 
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
## 테스트 DB 및 접속 정보 삭제 여부 : Y 권장
Remove test database and access to it? [Y/n]

- Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
 
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
## 지금까지 설정한 권한 정보 적용 여부 : Y 권장
Reload privilege tables now? [Y/n]

Cleaning up...
 
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
 
Thanks for using MariaDB!

## 설정 완료
  • 설정 후 MariaDB 정상적으로 접속되는지 확인
#관리자 권한으로 DB접속
mariadb
#일반 계정으로 DB접속
mariadb -uroot -p
password 입력

3. MariaDB 테이블 대소문자 구분 설정 해제 및 기본 포트 변경

📌 최초로 MariaDB를 설치하면 리눅스 파일 시스템 기본 설정 상 윈도우와 다르게 테이블 이름이 대소문자를 구분 윈도우와 함께 이용하는 에이전트등에 문제가 있을 수 있기에 해당 설정을 먼저 수정해 주는 편이나, 사내 정책에 맞춰 적용 필요
  • MariaDB 대소문자 구분 확인
# DB 접속
mariadb
## MariaDB 접속 후
show variables like 'lower_case_table_names';
lower_case_table_name 기능
0 테이블 대소문자 구분
1 테이블 대소문자 구분 없이 소문자로 저장
2 윈도우에서 테이블 대소문자 구분
  • MariaDB 서버 설정 파일을 관리자 권한으로 vi 문서 편집기를 이용하여 수정
vi /etc/mysql/mariadb.conf.d/50-server.cnf
  • 주석처리 된 port 부분을 주석 해제한 뒤 원하는 임의의 포트를 입력 (MariaDB의 기본포트는 3306)
# this is only for the mysqld standalone daemon
[mysqld]

#
# * Basic Settings
#

#user                  = mysql
pid-file               = /run/mysqld/mysqld.pid
basedir                = /usr
#datadir                = /var/lib/mysql
#tmpdir                 = /tmp
port                   = 3306
lower_case_table_names = 0
  • MariaDB의 서비스를 다시 시작
service mariadb restart
## 또는
systemctl restart mysql
  • lower_case_table_name 설정이 변경 됬는지 확인
## MariaDB 접속 후
show variables like 'lower_case_table_names';
  • 포트가 정상적으로 변경 되었는지 확인
telnet localhost 포트번호
## 또는
netstat -tnlp

4. 방화벽 설정

  • 위에서 지정한 포트(3306) UFW를 이용하여 방화벽 열기
## UFW 활성화
ufw enable

## 지정한 포트(3306) 방화벽 열기
ufw allow 3306

## UFW 상태 확인
ufw status verbose
  •  아래 우분투(Ubuntu) 방화벽(UFW) 설정 글 참고

2024.09.09 - [OS/Linux] - 우분투(Ubuntu) 방화벽(UFW) 설정


5. 외부 접속 설정

  • MariaDB 설정 파일 50-server.cnf 문서 편집기로 열기
## MariaDB 설정 경로로 이동
cd /etc/mysql/mariadb.conf.d/
## server 설정 파일을 vu 문서 편집기 열기
vi 50-server.cnf

 

  • 50-server.cnf 설정 파일 수정
## bind-address 항목을 0.0.0.0으로 변경합니다. (혹은 #을 통한 주석 처리로도 가능함.) 

# localhost which is more compatible and is not less secure.
## 아래 주석 처리 또는 0.0.0.0으로 변경
# bind-address                = 127.0.0.1

#
# * Find Tuning
#

#key_buffer_size           = 128M
#max_allowed_packet        = 1G
  • 변경이 완료된 후 설정 파일 적용을 위해 서비스 재시작
## MariaDB service 재시작
service mariadb restart
## 또는
systemctl restart mysql

6. DB, 계정 생성 및 권한 부여

  • DB, 계정 생성 및 권한 부여
## MariaDB에 접속
mariadb
## (dbname)으로 데이터베이스 생성
CREATE DATABASE DB명;
## (userID) 계정을 (password) 비밀번호로 모든 IP주소('%')를 통하여 접근 가능하게 생성
CREATE USER 'User명'@'%' IDENTIFIED BY '비밀번호';
## (dbname) 아래 있는 전체 테이블(*)에 대하여 생성된 (userID) 계정에 전체 권한을 줌
GRANT ALL PRIVILEGES ON (dbname).* TO '(User명)'@'%';
## 현재 설정된 유저 권한을 적용 함
FLUSH PRIVILEGES;
## MariaDB 접속 종료
EXIT;

7. MariaDB 삭제

  • MariaDB 패키지를 확인
sudo dpkg -l | grep mariadb 

ii  mariadb-client-10.3                        1:10.3.32-0ubuntu0.20.04.1            amd64        MariaDB database client binaries
ii  mariadb-client-core-10.3                   1:10.3.32-0ubuntu0.20.04.1            amd64        MariaDB database core client binaries
ii  mariadb-common                             1:10.3.32-0ubuntu0.20.04.1            all          MariaDB common metapackage
ii  mariadb-server                             1:10.3.32-0ubuntu0.20.04.1            all          MariaDB database server (metapackage depending on the latest version)
ii  mariadb-server-10.3                        1:10.3.32-0ubuntu0.20.04.1            amd64        MariaDB database server binaries
ii  mariadb-server-core-10.3                   1:10.3.32-0ubuntu0.20.04.1            amd64        MariaDB database core server files
  • MariaDB 패키지 삭제
sudo apt-get purge mariadb-server
sudo apt-get purge mariadb-server-10.3
sudo apt-get purge mariadb-client-10.3
sudo apt-get purge mariadb-server-core-10.3
sudo apt-get purge mariadb-client-core-10.3
sudo apt-get purge mariadb-common

728x90
반응형

'데이터베이스 > MySQL•MariaDB' 카테고리의 다른 글

Redhat 계열 Linux MariaDB 설치  (0) 2024.09.21
'데이터베이스/MySQL•MariaDB' 카테고리의 다른 글
  • Redhat 계열 Linux MariaDB 설치
키큰난쟁이
키큰난쟁이
개발 블로그
    반응형
    250x250
  • 키큰난쟁이
    키큰난쟁이의 놀이터
    키큰난쟁이
  • 전체
    오늘
    어제
    • 분류 전체보기 (38)
      • AI (1)
        • AI 응용 (1)
      • 프로그래밍 언어 (5)
        • Java (3)
        • PHP (1)
        • JavaScript (1)
      • 프레임워크 (3)
        • Spring (3)
      • 서버 (8)
        • Web Server (2)
        • WAS (2)
        • Hypervisor (4)
      • 데이터베이스 (5)
        • MySQL•MariaDB (2)
        • Oracle (1)
        • Cubrid (2)
      • 운영체제 (4)
        • Linux (4)
      • 클라우드 (1)
        • Ncloud (1)
      • 데브옵스 (7)
        • VCS (2)
        • CICD (3)
        • Docker (2)
      • 지식 (2)
        • Web (2)
      • 기타 (2)
        • 일상 (2)
  • 블로그 메뉴

    • 일상
  • 링크

    • Instagram
    • github
  • 공지사항

    • 라이믹스 → 티스토리 이사
  • 인기 글

  • 태그

    CI/CD
    docker
    mariadb
    GitHub
    리눅스
    DBMS
    자바
    devops
    Apple Silicon
    도커
    애플실리콘
    PROXMOX
    깃허브
    젠킨스
    jenkins
    db
    프록시모스
    java
    마리아디비
    우분투
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
키큰난쟁이
우분투(Ubuntu) Linux MariaDB 설치 및 DB, 계정 생성
상단으로

티스토리툴바