본문 바로가기

퍼블릭 클라우드

Amazon EC2 t4g.small 인스턴스에서 MySQL를 설치하는 방법

반응형

Amazon EC2 t4g.small 인스턴스에서 MySQL를 설치하는 방법

테스트 환경

  • 운영 체제 버전 정보 확인
$ lsb_release -d
Description:	Ubuntu 22.04.3 LTS
  • 운영 체제의 아키텍처 확인(Arm 기반 AWS Graviton 프로세서 사용)
$ uname -m
aarch64
  • 운영 체제의 비트 수
$ getconf LONG_BIT
64

MySQL 설치

Shell에서 mysql 계정 및 그룹 생성

sudo groupadd -g 28 mysql
sudo useradd -m -c "MySQL Server" -d /usr/local/mysql -s /bin/false -u 28 -g mysql mysql
$ egrep mysql /etc/passwd /etc/group
/etc/passwd:mysql:x:28:28:MySQL Server:/usr/local/mysql:/bin/false
/etc/group:mysql:x:28:

작업 디렉토리로 이동

cd /usr/local/src

MySQL

MySQL 패키지를 다운로드합니다.

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.35-linux-glibc2.28-aarch64.tar.xz

MySQL 압축 파일을 /usr/local/mysql 디렉토리에 압축을 풉니다.

sudo tar xf mysql-8.0.*.tar.xz -C /usr/local/mysql --strip-components=1

데이터 디렉토리 생성

sudo mkdir -p /usr/local/mysql/data

데이터 디렉토리 소유자 변경

sudo chown -R mysql:mysql /usr/local/mysql

데이터 디렉토리 퍼미션 변경

sudo chmod 750 /usr/local/mysql/data

MySQL 설치 디렉토리로 이동

cd /usr/local/mysql

MySQL 초기화

./bin/mysqld --initialize --user=mysql
$ ./bin/mysqld --initialize --user=mysql
2023-11-03T15:31:04.406477Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.35) initializing of server in progress as process 3184
2023-11-03T15:31:04.417723Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-11-03T15:31:05.029497Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-11-03T15:31:08.399063Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: sl8ncWzR(fK&

MySQL(my.conf) 환경 설정 파일 생성

sudo vim /usr/local/mysql/my.cnf
더보기

---

cat <<EOF > /usr/local/mysql/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
user=mysql
bind-address=0.0.0.0
port=3306
pid-file=/usr/local/mysql/data/mysqld.pid

### general log
general-log=TRUE
general-log-file=/usr/local/mysql/data/general.log

### error log
log-error-verbosity=1
log-error=/usr/local/mysql/data/error.log

### slow query log
slow-launch-time=5
slow-query-log=TRUE
slow-query-log-file=/usr/local/mysql/data/slow-query.log

#skip-grant-tables=FALSE
symbolic-links=FALSE
skip-name-resolve=TRUE

server-id=1
binlog-format=ROW
log-bin=/usr/local/mysql/data/mysql-bin
sync-binlog=1

relay-log=/usr/local/mysql/data/relay-log
relay-log-index=/usr/local/mysql/data/relay-log.index
relay-log-purge=TRUE
expire-logs-days=7
log-slave-updates=TRUE
EOF

---

MySQL 시작

 ./bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &
$ ./bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &
[1] 3245
2023-11-03T15:41:57.384631Z mysqld_safe Logging to '/usr/local/mysql/data/error.log'.
2023-11-03T15:41:57.384631Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
728x90

MySQL 클라이언트 설치

sudo apt-get install mysql-client

MySQL 서버에 접속

./bin/mysql -h localhost -uroot -p'sl8ncWzR(fK&'

MySQL Shell에서 root 패스워드 변경

ALTER USER 'root'@'localhost' IDENTIFIED WITH 'caching_sha2_password' BY 'new_password';

변경 사항 적용

FLUSH PRIVILEGES;

실행 결과

$ ./bin/mysql -h localhost -uroot -p'sl8ncWzR(fK&'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.35

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH 'caching_sha2_password' BY 'new_password';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

 

MySQL 8.0.35가 EC2 t4g.small 인스턴스에 설치되었습니다.

MySQL 데이터베이스 및 사용자 생성

MySQL 데이터베이스 생성

CREATE DATABASE my_database;

MySQL 사용자 생성

CREATE USER 'my_user'@'10.0.%' IDENTIFIED BY 'my_password';

MySQL 사용자에게 데이터베이스 액세스 권한을 부여

GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'10.0.%';

변경 사항 적용

FLUSH PRIVILEGES;

실행 결과

mysql> CREATE DATABASE my_database;
Query OK, 1 row affected (0.01 sec)

mysql> CREATE USER 'my_user'@'10.0.%' IDENTIFIED BY 'my_password';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'10.0.%';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

MySQL 정지

./bin/mysqladmin -u root -p'new_password' shutdown
./bin/mysqladmin -u root -p'new_password' shutdown
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
2023-11-03T15:58:51.432505Z mysqld_safe mysqld from pid file /usr/local/mysql/data/mysqld.pid ended
[1]+  Done                    ./bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf

 

참고URL

- MySQL Community Downloads : https://dev.mysql.com/downloads/mysql/

 

728x90
반응형