본문 바로가기

리눅스

Ubuntu에 MySQL 5.7을 바이너리 파일로 설치하는 방법

728x90

Ubuntu에 MySQL 5.7을 바이너리 파일로 설치하는 방법

1. 바이너리 파일 다운로드

MySQL 5.7 바이너리 파일을 MySQL 공식 웹사이트에서 다운로드합니다. 원하는 버전의 바이너리 파일을 선택하고, 다운로드한 파일을 원하는 디렉토리에 저장합니다.

cd /usr/local/src/
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.41-linux-glibc2.12-x86_64.tar
tar xf mysql-5.7.41-linux-glibc2.12-x86_64.tar
mkdir /usr/local/mysql-5.7.41
tar xfz mysql-5.7.41-linux-glibc2.12-x86_64.tar.gz -C /usr/local/mysql-5.7.41 --strip-components=1
ln -s /usr/local/mysql-5.7.41 /usr/local/mysql

2. MySQL 사용자 및 그룹 생성

MySQL을 실행할 사용자와 그룹을 생성합니다. 다음 명령어를 실행하여 MySQL 사용자와 그룹을 생성합니다.

sudo groupadd --gid 121 mysql
sudo useradd -r -u 121 -g mysql -s /bin/false mysql

3. 디렉토리 및 파일 권한 설정

MySQL을 실행할 디렉토리 및 파일에 필요한 권한을 부여합니다. 다음 명령어를 실행하여 권한을 설정합니다.

sudo mkdir /usr/local/mysql/data
sudo chown -R mysql:mysql /usr/local/mysql-5.7.41

4. 설정 파일 작성

MySQL 설정 파일(my.cnf)을 작성합니다. 원하는 디렉토리에 my.cnf 파일을 생성하고, 다음과 같은 내용을 추가합니다.

vim /usr/local/mysql/my.cnf
[mysqld]
user = mysql
port = 3306
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /usr/local/mysql/mysql.sock

log-error = /usr/local/mysql/data/error.log
log-error-verbosity = 3

symbolic-links = 0

[client]
port = 3306
socket = /usr/local/mysql/mysql.sock

5. MySQL 초기화

MySQL 데이터 디렉토리를 초기화합니다. 다음 명령어를 실행하여 초기화합니다.

cd /usr/local/mysql
./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
$ ./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2023-05-19T07:46:19.053275Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-05-19T07:46:20.639599Z 0 [Warning] InnoDB: New log files created, LSN=45790
2023-05-19T07:46:20.852094Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2023-05-19T07:46:20.926447Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 3ef5caf4-f619-11ed-96e6-080027704bff.
2023-05-19T07:46:20.931796Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2023-05-19T07:46:21.189529Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2023-05-19T07:46:21.191199Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2023-05-19T07:46:21.192634Z 0 [Warning] CA certificate ca.pem is self signed.
2023-05-19T07:46:21.291882Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
728x90

6. MySQL 서비스 등록

MySQL을 시스템 서비스로 등록하고 부팅 시 자동으로 시작되도록 설정합니다.

7. MySQL 서비스 시작

MySQL 서비스를 시작합니다.

./bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf --user=mysql &
$ ./bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf --user=mysql &
[1] 1070

Logging to '/usr/local/mysql/data/error.log'.
2023-05-19T07:47:57.320112Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

8. MySQL 보안 강화

MySQL 보안을 강화하기 위해 다음 명령어를 실행하여 보안 스크립트를 실행합니다.

스크립트는 여러 보안 관련 질문을 하며, 암호 정책 설정, 불필요한 사용자 계정 제거 등을 포함합니다.

sudo apt-get install -y libncurses5
./bin/mysql -uroot

 

MySQL 5.7이 Ubuntu 시스템에 바이너리 파일로 성공적으로 설치되었습니다. 이제 MySQL을 사용할 수 있으며, 필요한 데이터베이스 및 사용자를 생성하여 작업을 시작할 수 있습니다.

 

MySQL 스크립트로 설치하기

테스트 환경

$ lsb_release -d
Description:	Ubuntu 22.04.2 LTS

Installing_MySQL_on_Linux_Using_Generic_Binaries.sh 스크립트

wget -q https://raw.githubusercontent.com/anti1346/zz/main/ubuntu/Installing_MySQL_on_Linux_Using_Generic_Binaries.sh
chmod +x Installing_MySQL_on_Linux_Using_Generic_Binaries.sh
bash Installing_MySQL_on_Linux_Using_Generic_Binaries.sh
$ bash Installing_MySQL_on_Linux_Using_Generic_Binaries.sh

Packages Install
packages : libaio1 libnuma1 libncurses5

MySQL User Create
username : mysql
home directory : /usr/local/mysql

MySQL Base Directory Create
base dir : /usr/local/mysql

MySQL Packages Download
mysql-8.0.33-linux-glibc2.17-aarch  84%[===========================>        ] 773.74M  8.51MB/s    in 78s
mysql-8.0.33-linux-glibc2.17-aarch 100%[++++++++++++++++++++++++++++=======>] 919.07M  15.8MB/s    in 10s

MySQL Data Directory Create
data dir : /usr/local/mysql/data

Setting MySQL Base Directory Ownership
Owner: mysql
Directory: /usr/local/mysql

MySQL Configure File(my.cnf) Create
my.cnf path : /usr/local/mysql/my.cnf

Initialize MySQL
2023-05-20T01:51:36.575223Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.33) initializing of server in progress as process 2939
2023-05-20T01:51:36.582327Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-05-20T01:51:36.764085Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-05-20T01:51:37.370512Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

Start MySQL
Logging to '/usr/local/mysql/data/error.log'.
2023-05-20T01:51:39.774323Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

Connect MySQL
/usr/local/mysql/bin/mysql -uroot --socket /usr/local/mysql/mysql.sock

Shutdown MySQL
/usr/local/mysql/bin/mysqladmin -u root shutdown --socket /usr/local/mysql/mysql.sock

 

728x90