MySQL 8.4 LTS 컴파일 설치
MySQL 8 에서 버전관리에 변화가 있었다. MySQL 도 이제는 LTS 버전과 그렇지 않은 버전으로 나누어 릴리즈 된다고 한다. MySQL 8.4 LTS 에서 변경사항이 있다. 설치는 Ubuntu 22.04 에서 진행 되었다.
의존성 패키지 설치
MySQL 8.4 는 GCC 10 버전 이상을 필요로 한다. 그래서 Ubuntu 20.04 에서는 설치할 수 없다.
다음과 같이 의존성 패키지를 설치한다.
1 |
apt install build-essential gcc libaio-dev libncurses-dev libssl-dev libevent-dev libnuma-dev cmake automake autoconf bison |
Configure
WITH_BOOST, DOWNLOAD_BOOST 옵션이 없어졌다. 추가로 FIDO 관련해 설정을 해줘야 한다. 사용하지 않는다면 none 으로 지정해줘야 한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql-8.4.5.lts \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DFORCE_INSOURCE_BUILD=1 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_SYSTEMD=1 \ -WITH_EDITLINE=/usr \ -WITH_LIBEVENT=/usr \ -WITH_ZLIB=/usr \ -DWITH_FIDO=none |
에러가 발생한다면 다시 해줘야 하는데, 다음과 같이 파일과 디렉토리를 삭제하면 된다.
1 2 |
rm -rf CMakeCache.txt rm -rf CMakeFiles |
설치
컴파일을 하고 설치를 하면된다. 충분한 용량을 필요로 하기 때문에 디스크 공간이 충분해야 한다.
1 2 |
make make install |
MySQL 설치디렉토리에 mysql 심볼릭 링크를 만들어 준다.
1 2 |
cd /opt/ ln -s mysql-8.4.5.lts mysql |
계정 생성
MySQL 운영을 위한 시스템 계정을 생성해 준다.
1 2 |
/usr/sbin/groupadd -g 47 -o -r mysql /usr/sbin/useradd -M -g mysql -o -r -d /opt/mysql/logs -s /bin/false -c "MySQL Server" -u 47 mysql |
my.cnf 파일 작성
여러설정이 있지만 디렉토리 구조화에 대한 것만 기술하도록 하겠다.
1 2 3 4 5 6 7 8 9 10 11 12 |
datadir = /opt/dbstorage/mysql/data tmpdir = /opt/dbstorage/mysql/tmp log_bin = /opt/dbstorage/mysql/binlog/localhost-01-bin log_error = /opt/dbstorage/mysql/logs/mysqld_error.log general_log_file = /opt/dbstorage/mysql/logs/general_query_all.log slow_query_log_file = /opt/dbstorage/mysql/logs/slow_query.log innodb_data_home_dir = /opt/dbstorage/InnoDB/ibData innodb_temp_tablespaces_dir = /opt/dbstorage/InnoDB/innodb_tmp innodb_log_group_home_dir = /opt/dbstorage/InnoDB/redoLogs innodb_undo_directory = /opt/dbstorage/InnoDB/undoLogs innodb_tmpdir = /opt/dbstorage/InnoDB/tmp innodb_doublewrite_dir = /opt/dbstorage/InnoDB/doublewrite |
위 내용을 기반으로 내용을 추가하면 된다.
데이터베이스 디렉토리 생성
데이터베이스를 위한 디렉토리를 생성해 준다. 소유권도 mysql 로 바꿔준다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
cd /opt chgrp mysql -R mysql-8.4.5.lts; cd mysql-8.4.5.lts mkdir logs run chown mysql.mysql logs; chown mysql.mysql run mkdir -p /opt/dbstorage/InnoDB/redoLogs mkdir -p /opt/dbstorage/InnoDB/undoLogs mkdir -p /opt/dbstorage/InnoDB/tmp mkdir -p /opt/dbstorage/InnoDB/innodb_tmp mkdir -p /opt/dbstorage/InnoDB/ibData mkdir -p /opt/dbstorage/InnoDB/doublewrite mkdir -p /opt/dbstorage/mysql/tmp mkdir -p /opt/dbstorage/mysql/data mkdir -p /opt/dbstorage/mysql/binlog mkdir -p /opt/dbstorage/mysql/logs chown -R mysql: /opt/dbstorage |
/opt/dbstorage 디렉토리는 my.cnf 설정파일과 관련이 되어 있음으로 이를 고려해서 생성해야 한다.
데이터베이스 초기화
MySQL 시스템 테이블을 비롯한 데이터베이스를 생성하는 초기화를 진행해 준다.
1 2 |
cd /opt/mysql bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql |
초기화하면서 root 사용자의 패스워드도 생성되는데, 이는 error 로그 파일에 작성된다. my.cnf 설정에 따라 error 로그는 ‘/opt/dbstorage/mysql/logs/mysqld_error.log’ 이며 다음과 같이 확인할 수 있다.
1 2 |
grep 'temporary password' /opt/dbstorage/mysql/logs/mysqld_error.log 2025-07-20T11:16:12.888668Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: JjCXX9qV2)K= |
mysqld.service
mysql 데몬 관리를 위한 systemd 유닛 파일을 작성한다. 대략 다음과 같이 작성할 수 있다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
[Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Install] WantedBy=multi-user.target [Service] User=mysql Group=mysql Type=notify # Disable service start and stop timeout logic of systemd for mysqld service. TimeoutSec=0 # Execute pre and post scripts as root # hence, + prefix is used # Needed to create system tables ExecStartPre=+/opt/mysql/bin/mysqld_pre_systemd # Start main service ExecStart=/opt/mysql/bin/mysqld $MYSQLD_OPTS # Use this to switch malloc implementation EnvironmentFile=-/etc/sysconfig/mysql # Sets open_files_limit LimitNOFILE = 10000 Restart=on-failure RestartPreventExitStatus=1 # Set enviroment variable MYSQLD_PARENT_PID. This is required for restart. Environment=MYSQLD_PARENT_PID=1 PrivateTmp=false |
파일을 작성하고 난 후에 다음과 같이 mysql 를 시작할 수 있다.
1 |
systemctl start mysqld.service |
root 패스워드 변경
초기화시 생성한 임시패스워드로는 작업을 할 수 없도록 되어 있다. 따라서 패스워드를 변경해 줘야 한다.
1 |
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword'; |