[MySQL & MariaDB] CentOS7 에 MariaDB 설치하기, 최적화, 설정
출처1 : https://zetawiki.com/wiki/CentOS7_MariaDB_%EC%84%A4%EC%B9%98
출처2 : https://www.centos.org/forums/viewtopic.php?t=43909
출처4 : https://slobell.com/blogs/38
출처5 : https://www.lesstif.com/pages/viewpage.action?pageId=14745775
다음과 같은 방법으로 CentOS 7 버전에 MariaDB 10.3 버전을 설치할 수 있다.
# repo 파일 만들기
$ vi /etc/yum.repos.d/MariaDB.repo
# 마리아db 공식 가이드북
# https://downloads.mariadb.org/mariadb/repositories/#mirror=kaist&distro=CentOS&distro_release=centos7-amd64--centos7&version=10.3
# MariaDB 10.3 CentOS repository list - created 2018-10-22 07:06 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
# 그냥 설치하면 인증서가 깨진다고 나오기 때문에 해당 인증서를 설치해줘야 한다(?)
$ rpm --import http://yum.mariadb.org/RPM-GPG-KEY-MariaDB
# 실제 설치
$ yum install MariaDB-server MariaDB-client
# 서비스 시작
$ systemctl start mysql
# root 계정의 패스워드 설정
$ /usr/bin/mysqladmin -u root password 'root'
# 포트 검색
$ netstat -anp | grep 3306
# 마리아db 접속
$ mysql -u root -p
# 사용자 조회
mariadb > use mysql;
mariadb > select host, user from user;
# 외부 계정 생성
mariadb > CREATE USER `username`@`%` IDENTIFIED BY 'password';
# 변경사항 적용
mariadb > FLUSH PRIVILEGES;
# utf-8 설정
# character-set 확인
mariadb > show variables like 'c%';
# 다음 파일 3가지 작성
$ vi /etc/my.cnf.d/client.cnf
[client]
default-character-set=utf8
$ vi /etc/my.cnf.d/mysql-clients.cnf
[mysql]
default-character-set=utf8
[mysqldump]
default-character-set=utf8
$ vi /etc/my.cnf (이게 공식)
$ vi /etc/my.cnf.d/server.cnf
[mysqld]
collation-server = utf8_general_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
port=3306
# 테이블명 대소문자 구별없이
lower_case_table_names = 1
# 메모리 설정
innodb_buffer_pool_size = 2G
# 커넥션 설정
max_connections = 2048
thread_pool_max_threads = 2048
init_connect="SET collation_connection = utf8_general_ci"
# 그 외 기타 설정들
sql_mode = "STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
default_storage_engine = innodb
innodb_log_file_size = 50M
# default time zone은 10.4에서 지원하지 않는 것 같다
;default-time-zone = utc
skip-name-resolve
max_allowed_packet = 1G
thread_handling = pool-of-threads
performance_schema = 1
transaction-isolation = READ-COMMITTED
slow-query-log = 1
long_query_time = 0.1
tmp_table_size = 1024M
max_heap_table_size = 1024M
table_open_cache = 8192
innodb_open_files = 8192
table_definition_cache = 8192
innodb_sync_spin_loops = 10
;init-file = "E:/DB_MySQL/start.sql"
# 서비스 재시작
$ systemctl restart mysql
# 메모리 설정 확인
mariadb > SHOW GLOBAL VARIABLES LIKE 'innodb_buffer_pool_size%';
# 커넥션 설정 확인
mariadb > SHOW GLOBAL VARIABLES LIKE 'max_connections%';