열렬히.뛰기

mariaDB

école 42 > inception > inception : 기타 지식 > mariaDB

간략한 소개

  • mysql을 포크 따서 만든 데이터베이스
  • 높은 성능과 안정성을 자랑하며, 오픈소스로 제공됨

1. test : 순수 데비안

  1. 순수한 데비안을 도커 위에 올린다.
  2. mariadb를 깐다. (하단 명령어 실행 시 자동실행)
  3. 도커 안으로 들어간다. (하단 명령어 실행 시 자동접속)
  4. 설정파일을 찾아본다.
bash
docker run -it debian:buster
-----
cd etc/mysql
cat my.cnf
bash
# The MariaDB/MySQL tools read configuration files in the following order:
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
bash
mysql --help

# Default options are read from the following files in the given order:
# /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf 
# The following groups are read: mysql client client-server client-mariadb
# The following options may be given as the first argument:

설정파일의 종류 : .cnf 파일

어디로 복사해야 하는가? /etc/mysql/mariadb.conf.d/50-server.cnf

2. 느낌 잡아보기

  1. 도커에 깐다
  2. 쉘 스크립트를 설정
    1. 설치되어 있는지 판단
    2. 되어있지 않으면, SQL 구문을 입력
    3. DB의 기반을 제작
  3. 이걸 복사한다
  4. 쉘 스크립트를 실행

3. 실제 쉘 스크립트

dockerfile
# 데비안 가져오기
FROM debian:buster

# apt 업데이트 및 nginx, openssl 설치
RUN apt -y update && apt -y install nginx && apt -y install openssl

# openssl 설정하기
RUN mkdir /etc/nginx/ssl
RUN openssl req \
	-x509 -nodes -days 365 \
    -newkey rsa:2048 \
    -keyout /etc/nginx/ssl/my_ssl.key \
    -out /etc/nginx/ssl/my_ssl.crt \
	-subj "/C=KO/ST=Seoul/L=Gaepo/O=42Seoul/OU=inchoi/CN=inchoi.42.fr"

# conf 파일 복사
COPY ./nginx.conf /etc/nginx/sites-enabled/default

# port 공개
EXPOSE 443

# nginx 시작
CMD ["nginx", "-g", "daemon off;"]
bash
#!/bin/bash

chown -R mysql:mysql /var/lib/mysql

service mariadb start
sleep 0.1

echo "CREATE DATABASE IF NOT EXISTS $DB_NAME ;" > init.sql
echo "CREATE USER IF NOT EXISTS '$DB_USER'@'%' IDENTIFIED BY '$DB_PWD' ;" >> init.sql
echo "GRANT ALL PRIVILEGES ON $DB_NAME.* TO '$DB_USER'@'%' ;" >> init.sql
echo "FLUSH PRIVILEGES;" >> init.sql

mysql < init.sql

service mariadb stop
sleep 0.1

# 포그라운드로 설정
mariadbd 
shell
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see

# this is read by the standalone daemon and embedded servers
[server]

# 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
lc-messages-dir         = /usr/share/mysql
lc-messages             = en_US
skip-external-locking

# Broken reverse DNS slows down connections considerably and name resolve is
# safe to skip if there are no "host by domain name" access grants
#skip-name-resolve

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 0.0.0.0

#
# * Fine Tuning
#

#key_buffer_size        = 128M
#max_allowed_packet     = 1G
#thread_stack           = 192K
#thread_cache_size      = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
#myisam_recover_options = BACKUP
#max_connections        = 100
#table_cache            = 64

#
# * Logging and Replication
#

# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# Recommend only changing this at runtime for short testing periods if needed!
#general_log_file       = /var/log/mysql/mysql.log
#general_log            = 1

# When running under systemd, error logging goes via stdout/stderr to journald
# and when running legacy init error logging goes to syslog due to
# /etc/mysql/conf.d/mariadb.conf.d/50-mysqld_safe.cnf
# Enable this if you want to have error logging into a separate file
#log_error = /var/log/mysql/error.log
# Enable the slow query log to see queries with especially long duration
#slow_query_log_file    = /var/log/mysql/mariadb-slow.log
#long_query_time        = 10
#log_slow_verbosity     = query_plan,explain
#log-queries-not-using-indexes
#min_examined_row_limit = 1000

# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id              = 1
#log_bin                = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
#max_binlog_size        = 100M

#
# * SSL/TLS
#

# For documentation, please read
# https://mariadb.com/kb/en/securing-connections-for-client-and-server/
#ssl-ca = /etc/mysql/cacert.pem
#ssl-cert = /etc/mysql/server-cert.pem
#ssl-key = /etc/mysql/server-key.pem
#require-secure-transport = on

#
# * Character sets
#

# MySQL/MariaDB default is Latin1, but in Debian we rather default to the full
# utf8 4-byte character set. See also client.cnf
character-set-server  = utf8mb4
collation-server      = utf8mb4_general_ci

#
# * InnoDB
#

# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
# Most important is to give InnoDB 80 % of the system RAM for buffer use:
# https://mariadb.com/kb/en/innodb-system-variables/#innodb_buffer_pool_size
#innodb_buffer_pool_size = 8G

# this is only for embedded server
[embedded]

# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]

# This group is only read by MariaDB-10.5 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-10.5]

확인절차

  1. docker exec -it [컨테이너 이름] /bin/bash 를 터미널창에 친다.
  2. 컨테이너 안으로 들어간다.