trouble-shooting

alpine linux에 mysql 설치하며 해결한 문제 기록

fffman 2024. 9. 5. 15:50

우선 alpine의 패키지 관리자 apk를 사용해서 mysql을 설치했다.

/ # apk update && apk add mysql

 

 

 

 

여기까지 설치하면 mysql 서버까지만 설치가 완료된다. 잘 동작하는지 확인해보기 위해 클라이언트까지 설치해본다.

/ # apk add mysql-client

 

아래처럼 mysql 명령어로 클라이언트에 접속해보려하면 에러가 발생한다.

/ # mysql
ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (2)

 

mysql 서버가 실행중이지 않아서 생긴 문제같다. mysqld 명령어로 데몬서버를 실행시켜본다. 그런데 아래와 같이 문제가 발생한다.

/ # mysqld &
2024-09-05  6:06:17 0 [Warning] Can't create test file '/var/lib/mysql/86501fa56ad3.lower-test' (Errcode: 2 "No such file or directory")
mysqld: Can't change dir to '/var/lib/mysql/' (Errcode: 2 "No such file or directory")
2024-09-05  6:06:17 0 [ERROR] Aborting

 

 

디렉토리가 생성되어 있지 않아서 생긴 문제같다. 직접 디렉토리를 생성해주고 다시 데몬서버를 실행시켜본다. 그러면 아래와 같이 문제가 발생한다.

/ # mkdir -p /var/lib/mysql
/ # mysqld &
mysqld: Please consult the Knowledge Base to find out how to run mysqld as root!
2024-09-05  6:07:44 0 [ERROR] Aborting

 

루트 계정으로 실행함을 명시해주지 않은 문제같다. 아래와 같이 명시해주면 또 다른 문제가 발생한다.

/ # mysqld --user=root &
2024-09-05  6:10:19 0 [Note] Starting MariaDB 10.11.6-MariaDB source revision fecd78b83785d5ae96f2c6ff340375be803cd299 as process 32
2024-09-05  6:10:19 0 [Note] InnoDB: The first data file './ibdata1' did not exist. A new tablespace will be created!
2024-09-05  6:10:19 0 [Note] InnoDB: Compressed tables use zlib 1.3.1
2024-09-05  6:10:19 0 [Note] InnoDB: Number of transaction pools: 1
2024-09-05  6:10:19 0 [Note] InnoDB: Using ARMv8 crc32 + pmull instructions
2024-09-05  6:10:19 0 [Note] InnoDB: Using Linux native AIO
2024-09-05  6:10:19 0 [Note] InnoDB: Initializing buffer pool, total size = 128.000MiB, chunk size = 2.000MiB
2024-09-05  6:10:19 0 [Note] InnoDB: Completed initialization of buffer pool
2024-09-05  6:10:19 0 [Note] InnoDB: Setting file './ibdata1' size to 12.000MiB. Physically writing the file full; Please wait ...
2024-09-05  6:10:19 0 [Note] InnoDB: File './ibdata1' size is now 12.000MiB.
2024-09-05  6:10:19 0 [Note] InnoDB: Buffered log writes (block size=512 bytes)
2024-09-05  6:10:19 0 [Note] InnoDB: Doublewrite buffer not found: creating new
2024-09-05  6:10:19 0 [Note] InnoDB: 128 rollback segments are active.
2024-09-05  6:10:19 0 [Note] InnoDB: Setting file './ibtmp1' size to 12.000MiB. Physically writing the file full; Please wait ...
2024-09-05  6:10:19 0 [Note] InnoDB: File './ibtmp1' size is now 12.000MiB.
2024-09-05  6:10:19 0 [Note] InnoDB: log sequence number 0; transaction id 3
2024-09-05  6:10:19 0 [Note] Plugin 'FEEDBACK' is disabled.
2024-09-05  6:10:19 0 [ERROR] Could not open mysql.plugin table: "Table 'mysql.plugin' doesn't exist". Some plugins may be not loaded
2024-09-05  6:10:19 0 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist
2024-09-05  6:10:19 0 [ERROR] Can't start server : Bind on unix socket: No such file or directory
2024-09-05  6:10:19 0 [ERROR] Do you already have another server running on socket: /run/mysqld/mysqld.sock ?
2024-09-05  6:10:19 0 [ERROR] Aborting

 

경로를 찾지 못해 소켓파일을 만들지 못하는 문제같다. 디렉토리를 생성해주고 다시 실행해봤다. 그러니 또 다른 문제가 발생했다.

/ # mkdir -p /run/mysqld
/ # mysqld --user=root &
2024-09-05  6:16:05 0 [Note] Starting MariaDB 10.11.6-MariaDB source revision fecd78b83785d5ae96f2c6ff340375be803cd299 as process 68
2024-09-05  6:16:05 0 [Note] InnoDB: Compressed tables use zlib 1.3.1
2024-09-05  6:16:05 0 [Note] InnoDB: Number of transaction pools: 1
2024-09-05  6:16:05 0 [Note] InnoDB: Using ARMv8 crc32 + pmull instructions
2024-09-05  6:16:05 0 [Note] InnoDB: Using Linux native AIO
2024-09-05  6:16:05 0 [Note] InnoDB: Initializing buffer pool, total size = 128.000MiB, chunk size = 2.000MiB
2024-09-05  6:16:05 0 [Note] InnoDB: Completed initialization of buffer pool
2024-09-05  6:16:05 0 [Note] InnoDB: Buffered log writes (block size=512 bytes)
2024-09-05  6:16:05 0 [Note] InnoDB: End of log at LSN=36397
2024-09-05  6:16:05 0 [Note] InnoDB: 128 rollback segments are active.
2024-09-05  6:16:05 0 [Note] InnoDB: Setting file './ibtmp1' size to 12.000MiB. Physically writing the file full; Please wait ...
2024-09-05  6:16:05 0 [Note] InnoDB: File './ibtmp1' size is now 12.000MiB.
2024-09-05  6:16:05 0 [Note] InnoDB: log sequence number 36397; transaction id 4
2024-09-05  6:16:05 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2024-09-05  6:16:05 0 [Note] Plugin 'FEEDBACK' is disabled.
2024-09-05  6:16:05 0 [ERROR] Could not open mysql.plugin table: "Table 'mysql.plugin' doesn't exist". Some plugins may be not loaded
2024-09-05  6:16:05 0 [Note] InnoDB: Buffer pool(s) load completed at 240905  6:16:05
2024-09-05  6:16:05 0 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist
2024-09-05  6:16:05 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.db' doesn't exist
2024-09-05  6:16:05 0 [ERROR] Aborting

 

정확한 원인은 잘 모르겠지만, 관련해서 서치해본 결과 mysql_install_db로 초기화가 필요한 문제같다. 아래와 같이 초기화하고 난 후 실행시켜봤다. 그런데 port가 0으로 설정되는 문제가 생겼다.

 

/ # mysql_install_db --user=root --socket=/run/mysqld/mysqld.sock --datadir=/var/lib/mysql
/ # mysqld --user=root &
/ # 2024-09-05  6:42:53 0 [Note] Starting MariaDB 10.11.6-MariaDB source revision fecd78b83785d5ae96f2c6ff340375be803cd299 as process 13
2024-09-05  6:42:53 0 [Note] InnoDB: Compressed tables use zlib 1.3.1
2024-09-05  6:42:53 0 [Note] InnoDB: Number of transaction pools: 1
2024-09-05  6:42:53 0 [Note] InnoDB: Using ARMv8 crc32 + pmull instructions
2024-09-05  6:42:53 0 [Note] InnoDB: Using Linux native AIO
2024-09-05  6:42:53 0 [Note] InnoDB: Initializing buffer pool, total size = 128.000MiB, chunk size = 2.000MiB
2024-09-05  6:42:53 0 [Note] InnoDB: Completed initialization of buffer pool
2024-09-05  6:42:53 0 [Note] InnoDB: Buffered log writes (block size=512 bytes)
2024-09-05  6:42:53 0 [Note] InnoDB: End of log at LSN=45518
2024-09-05  6:42:53 0 [Note] InnoDB: 128 rollback segments are active.
2024-09-05  6:42:53 0 [Note] InnoDB: Setting file './ibtmp1' size to 12.000MiB. Physically writing the file full; Please wait ...
2024-09-05  6:42:53 0 [Note] InnoDB: File './ibtmp1' size is now 12.000MiB.
2024-09-05  6:42:53 0 [Note] InnoDB: log sequence number 45518; transaction id 15
2024-09-05  6:42:53 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2024-09-05  6:42:53 0 [Note] Plugin 'FEEDBACK' is disabled.
2024-09-05  6:42:54 0 [Note] InnoDB: Buffer pool(s) load completed at 240905  6:42:54
2024-09-05  6:42:54 0 [Note] mysqld: ready for connections.
Version: '10.11.6-MariaDB'  socket: '/run/mysqld/mysqld.sock'  port: 0  Alpine Linux

 

일단 실행중인 mysqld의 프로세스를 kill해주고 mysql의 설정파일을 수정해서 다시 실행해주니 잘 동작했다. 설정파일을 아래와 같은 방법으로 수정했다.

/ # cat > /etc/my.cnf
# This group is read both both by the client and the server
# use it for options that affect everything
[client-server]

# This group is read by the server
[mysqld]
socket = /run/mysqld/mysqld.sock
datadir = /var/lib/mysql

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# include all files from the config directory
^C
/ #

 

드디어 잘 동작하는 모습이다.

/ # mysqld --user=root &
/ # 2024-09-05  6:49:28 0 [Note] mysqld: Aria engine: starting recovery
recovered pages: 0% 38% 52% 89% 100% (0.0 seconds); tables to flush: 1 0
 (0.0 seconds); 
2024-09-05  6:49:28 0 [Note] mysqld: Aria engine: recovery done
2024-09-05  6:49:28 0 [Note] InnoDB: Compressed tables use zlib 1.3.1
2024-09-05  6:49:28 0 [Note] InnoDB: Number of transaction pools: 1
2024-09-05  6:49:28 0 [Note] InnoDB: Using ARMv8 crc32 + pmull instructions
2024-09-05  6:49:28 0 [Note] InnoDB: Using Linux native AIO
2024-09-05  6:49:28 0 [Note] InnoDB: Initializing buffer pool, total size = 128.000MiB, chunk size = 2.000MiB
2024-09-05  6:49:28 0 [Note] InnoDB: Completed initialization of buffer pool
2024-09-05  6:49:28 0 [Note] InnoDB: Buffered log writes (block size=512 bytes)
2024-09-05  6:49:28 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=45518
2024-09-05  6:49:28 0 [Note] InnoDB: End of log at LSN=47008
2024-09-05  6:49:28 0 [Note] InnoDB: To recover: 9 pages
2024-09-05  6:49:28 0 [Note] InnoDB: 128 rollback segments are active.
2024-09-05  6:49:28 0 [Note] InnoDB: Removed temporary tablespace data file: "./ibtmp1"
2024-09-05  6:49:28 0 [Note] InnoDB: Setting file './ibtmp1' size to 12.000MiB. Physically writing the file full; Please wait ...
2024-09-05  6:49:28 0 [Note] InnoDB: File './ibtmp1' size is now 12.000MiB.
2024-09-05  6:49:28 0 [Note] InnoDB: log sequence number 47008; transaction id 16
2024-09-05  6:49:28 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2024-09-05  6:49:28 0 [Note] Plugin 'FEEDBACK' is disabled.
2024-09-05  6:49:28 0 [Note] InnoDB: Buffer pool(s) load completed at 240905  6:49:28
2024-09-05  6:49:28 0 [Note] Server socket created on IP: '0.0.0.0'.
2024-09-05  6:49:28 0 [Note] Server socket created on IP: '::'.
2024-09-05  6:49:28 0 [Note] mysqld: ready for connections.
Version: '10.11.6-MariaDB'  socket: '/run/mysqld/mysqld.sock'  port: 3306  Alpine Linux