Rocky Linux MySQL8 설치

@lim · July 18, 2024

개요

RedHat 계열 리눅스에서 MySQL 8 최신 버전을 설치하는 방법을 정리했다.
계열 중 하나인 Rocky Linux을 이용했는데, 록키 리눅스의 기본 데이터베이스는 MariaDB이기에 추가 설정이 필요하다.

MySQL Community Repository 설치

리포지토리를 추가하는 패키지는 아래 링크에서 확인할 수 있다.

https://dev.mysql.com/downloads/repo/yum/

여기서 자신의 버전에 맞춰 다운로드 하거나 링크를 복사해두면 된다.

dnf install https://repo.mysql.com//mysql84-community-release-el9-1.noarch.rpm
[root@mysql ~]# dnf repolist all | grep mysql
mysql-8.4-lts-community                      MySQL 8.4 LTS Community Se enabled
mysql-8.4-lts-community-debuginfo            MySQL 8.4 LTS Community Se disabled
mysql-8.4-lts-community-source               MySQL 8.4 LTS Community Se disabled
mysql-cluster-8.0-community                  MySQL Cluster 8.0 Communit disabled
mysql-cluster-8.0-community-debuginfo        MySQL Cluster 8.0 Communit disabled
mysql-cluster-8.0-community-source           MySQL Cluster 8.0 Communit disabled
mysql-cluster-8.4-lts-community              MySQL Cluster 8.4 LTS Comm disabled
mysql-cluster-8.4-lts-community-debuginfo    MySQL Cluster 8.4 LTS Comm disabled
mysql-cluster-8.4-lts-community-source       MySQL Cluster 8.4 LTS Comm disabled
mysql-cluster-innovation-community           MySQL Cluster Innovation R disabled
mysql-cluster-innovation-community-debuginfo MySQL Cluster Innovation R disabled
mysql-cluster-innovation-community-source    MySQL Cluster Innovation R disabled
mysql-connectors-community                   MySQL Connectors Community enabled
mysql-connectors-community-debuginfo         MySQL Connectors Community disabled
mysql-connectors-community-source            MySQL Connectors Community disabled
mysql-innovation-community                   MySQL Innovation Release C disabled
mysql-innovation-community-debuginfo         MySQL Innovation Release C disabled
mysql-innovation-community-source            MySQL Innovation Release C disabled
mysql-tools-8.4-lts-community                MySQL Tools 8.4 LTS Commun enabled
mysql-tools-8.4-lts-community-debuginfo      MySQL Tools 8.4 LTS Commun disabled
mysql-tools-8.4-lts-community-source         MySQL Tools 8.4 LTS Commun disabled
mysql-tools-community                        MySQL Tools Community      disabled
mysql-tools-community-debuginfo              MySQL Tools Community - De disabled
mysql-tools-community-source                 MySQL Tools Community - So disabled
mysql-tools-innovation-community             MySQL Tools Innovation Com disabled
mysql-tools-innovation-community-debuginfo   MySQL Tools Innovation Com disabled
mysql-tools-innovation-community-source      MySQL Tools Innovation Com disabled
mysql80-community                            MySQL 8.0 Community Server disabled
mysql80-community-debuginfo                  MySQL 8.0 Community Server disabled
mysql80-community-source                     MySQL 8.0 Community Server disabled

MySQL Community 설치

다음 명령어로 설치한다.

dnf install mysql-community-server
[root@mysql ~]# dnf install mysql-community-server
Last metadata expiration check: 0:01:47 ago on Thu 18 Jul 2024 07:48:03 AM UTC.
Dependencies resolved.
===========================================================================================
 Package                        Arch   Version               Repository               Size
===========================================================================================
Installing:
 mysql-community-server         x86_64 8.4.1-1.el9           mysql-8.4-lts-community  50 M
 ...

MySQL 초기화

패키지 매니저(dnf, yum, apt 등)를 통해 설치하였다면 설치 과정에서 자동으로 수행되기 때문에 패스하면된다.

다음 두 명령어 중 하나를 통해 초기화 작업을 진행한다.
단 이미 설치된 상태에서 명령어를 사용하게되면 기존 데이터와 설정이 모두 초기화가 되므로 주의해야한다.

mysqld --initialize-insecure
mysqld --initialize

두 명령어의 차이는 다음과 같다.

  • --initialize : root 계정을 생성하면서 임시 비밀번호를 생성 (log를 통해 확인 가능)
  • --initialize-insecure : 비밀번호 없이 root 계정을 생성

MySQL 데몬 실행

설치가 끝나면 Debian 계열(Ubuntu)과 달리 바로 실행되어 있지 않다.

[root@mysql ~]# systemctl status mysqld
○ mysqld.service - MySQL Server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled)
     Active: inactive (dead)
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html

다음 명령어를 통해 MySQL 데몬을 실행한다.

systemctl start mysqld

실행하고나서 다음 명령어를 통해 임시로 발급된 패스워드를 확인할 수 있다.

grep 'temporary password' /var/log/mysqld.log
[root@mysql ~]# grep 'temporary password' /var/log/mysqld.log
2024-07-18T08:51:39.206722Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: <비밀번호>

MySQL 보안 설정

mysql_secure_installation 를 통해 MySQL의 기본 보안 설정을 진행한다.
설정되는 항목은 다음과 같다.

  • root 계정 비밀번호 설정
    • 비밀번호 복잡성 검사
  • 익명 사용자 제거
  • 원격 root 로그인 비활성화
  • 테스트 데이버테이스 제거
설정 자세히 보기
[root@mysql ~]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y   

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

MySQL 접속

설정이 끝났다면 다음 명령를 통해 접속할 수 있다.

mysql -u root -p
@lim
기억은 기록기록