본문으로 바로가기

[MySQL] 컴파일 설치

category DATABASE/MY-SQL 2020. 9. 29. 21:37

01. 준비

컴파일 설치전에 환경설정 및 설치파일이 필요하다.

 

▶설치파일

 

MySQL :: Download MySQL Community Server (Archived Versions)

Please note that these are old versions. New releases will have recent bug fixes and features! To download the latest release of MySQL Community Server, please visit MySQL Downloads. MySQL open source software is provided under the GPL License.

downloads.mysql.com

▶패키지 설치

  • 컴파일에 필요한 패키지 설치
yum -y install ncurses-devel
yum -y install perl
yum -y install perl-Data-Dumper
yum -y install cmake
yum -y install wget
yum -y install gcc-c++
yum -y install bison
yum -y --enablerepo=PowerTools install rpcgen
yum -y install libtirpc-devel

 

02. mysql 그룹/유저 추가

  • Root 계정으로 MySQL을 실행 하는건 보안성 위험.
  • 소유권만 가지는 nologin계정 생성과정
groupadd mysql
useradd mysql -g mysql

 

03. 디렉터리, 파일 생성 및 권한설정

  • my.cnf에서 설정한 에러로그 파일 생성
  • 경로설정에 필요한, 혹은 필요에 의해 추가한 디렉터리 추가
  • 위에서 생성한 mysql계정으로 권한,소유권 수정
mkdir -m=700 -pv /DB/data
mkdir -m=700 -pv /DB/infile
mkdir -m=755 -pv /DBLog
mkdir -m=700 -pv /DBTmp

touch /DBLog/slow_log.log
touch /DBLog/error_log.log
chown mysql. /DB/data
chown mysql. /DBLog
chown mysql. /DB/infile
chown mysql. /DB/
chown mysql. /DBTmp
chown -R mysql. /DBLog

 

04. 압축해제

  • 다운로드 받은 압축파일 해제과정
tar -xvzf /home/minstone/Downloads/mysql-boost-5.7.26.tar.gz -C /usr/local/

/home/minstone/Downloads/ 경로의 mysql-boost-5.7.26.tar.gz 파일을 /usr/local/에 압축푼다.

 

05. Cmake

  • 압축풀린 경로에서 실행
  • 버전에 따라 옵션을 다르게 설정해야 할 경우가 있다.
  • 해당과정에서 오류가 날 경우 상단의 패키지를 재설치해본다.(혹은 Cmake옵션문제)
cd /usr/local/mysql-5.7.26

cmake \
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql \
-DMYSQL_DATADIR=/DB/data \
-DMYSQL_UNIX_ADDR=/DBTmp/mysql.sock \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_SSL=bundled \
-DWITH_ZLIB=bundled \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DDOWNLOAD_BOOST=0 \
-DWITH_BOOST=./boost/

Cmake 완료

 

05. make

  • 4스레드로 make와 make install 진행. 속도에대한 이점이 있다.

메모리와 코어가 충분치 않다면 병렬 스레드 옵션 ( -j 4)는 제외하고 실행한다. (에러발생)

make VERBOSE=1 -j 4 && make install

make 진행중
make 완료

 

06. my.cnf 작성

  • mysql에서 사용하는 configure 파일
  • mysql 아래 경로의 폴더(data 등) 의 경로를 관리차원에서 /DB/data로 변경. (앞선 cmake도 동일하게 작업)
  • InnoDB Log과 InnoDB file 사이즈, buuffer pool 사이즈 설정 등이 있다.
[mysqld]
port            = 3306
socket          = /DBTmp/mysql.sock
datadir         = /DB/data
 
#*** performance schema on
performance_schema
performance_schema_events_waits_history_size      = 20
performance_schema_events_waits_history_long_size = 15000
performance_schema_max_file_instances             = 1000
 
#sql_mode='NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES'
#sql_mode='NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,ONLY_FULL_GROUP_BY'
sql_mode='NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

#*** Connection Options
wait_timeout=20
max_allowed_packet = 256M
back_log = 50
max_connections = 1000
max_connect_errors = 9999
max_user_connections = 1000

#*** THREAD Options
thread_cache_size = 60
 
#*** Query Cache Options
query_cache_type = OFF
query_cache_size = 0
 
#table_cache
table_definition_cache = 2048

#*** Application-specific options
table_open_cache = 2048
#binlog_cache_size = 1M
max_heap_table_size = 200M
sort_buffer_size = 8M
join_buffer_size = 8M
ft_min_word_len = 2
ft_stopword_file = ""
tmp_table_size = 200M
long_query_time = 1
group_concat_max_len = 10240
 
character-set-server=utf8
init_connect = "set names utf8"
character-set-client-handshake = FALSE

log_error_verbosity=2
slow_query_log = 1
slow_query_log_file = /DBLog/slow_log.log
log-error = /DBLog/error_log.log
skip-external-locking
skip-name-resolve
default-storage-engine = innodb
#skip-innodb
skip-stack-trace
#load data local infile -> ON 1
local-infile = 1
secure-file-priv=/DB/infile
#default_authentication_plugin=caching_sha2_password
default_authentication_plugin=mysql_native_password

explicit_defaults_for_timestamp
log_timestamps = SYSTEM
 
tmpdir = /DBTmp

#*** innodb Specific options
# Uncomment the following if you are using InnoDB tables
innodb_file_per_table
innodb_data_home_dir = /DB/data
innodb_data_file_path = ibdata1:100M;ibdata2:100M;ibdata3:100M;ibdata4:100M;ibdata5:100M:autoextend
innodb_log_group_home_dir = /DBLog
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 1G
innodb_buffer_pool_instances = 8
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_thread_concurrency = 0
innodb_flush_log_at_trx_commit = 1
innodb_io_capacity = 1000
innodb_flush_method = O_DIRECT
innodb_log_files_in_group = 3

# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 200M
innodb_log_buffer_size = 32M
innodb_lock_wait_timeout = 120

#PMM
innodb_monitor_enable=all

#SSL
ssl=0
 
#innodb_force_recovery = 1
 
!include /etc/replication.cnf
 
[mysqldump]
quick
max_allowed_packet = 64M
default_character_set = utf8
 
[mysql]
no_auto_rehash
prompt=mysql (\d)>
 
[mysqld_safe]
open-files-limit = 65535

 

07. Initialize

  • 초기화 과정이다. my.cnf 작성 후 진행해야 한다.
  • 완료 시 datadir 과 logdir 에 ibdata*, ib_logfile* 이 생성된다.
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize-insecure --user=mysql

 

data폴더 아래 생선된 파일

 

08. 데몬 복사/수정/실행

  • 기존 경로에서 /etc/init.d/ 경로에 복사해 사용 (선택사항)
  • basedir 과 datadir의 경로가 달라져 데몬파일 수정 필요함.
  • 수정 완료시 데몬 실행
#복사/편집#
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/
vi /etc/init.d/mysql.server

#수정할내용#
basedir=/usr/local/mysql
datadir=/DB/data

#데몬실행#
/etc/init.d/mysql.server start

 

데몬 구동 성공

 

09. root계정 로그인

  • 초기 root계정은 별도의 패스워드 없이 로그인 가능
/usr/local/mysql/bin/mysql -u root

로그인후 화면


VELOG로 이사갑니다✋
블로그 이미지 DongGle_ 님의 블로그
VISITOR 오늘 / 전체