웹사이트 검색

CentOS 8에 MySQL 8 데이터베이스 서버를 설치하는 방법


이 페이지에서

  1. 전제 조건
  2. MySQL 저장소에서 MySQL 8.0 설치
  3. AppStream 리포지토리에서 MySQL 8.0 설치
  4. 결론

MySQL은 무료 오픈 소스이며 전 세계에서 가장 널리 사용되는 데이터베이스 시스템 중 하나입니다. Oracle Cloud에서 제공하는 관계형 데이터베이스 관리 플랫폼입니다. 데이터베이스의 콘텐츠를 추가, 액세스 및 관리하기 위해 Structured Query Language를 사용합니다. 입증된 신뢰성, 빠른 처리, 사용 편의성 및 유연성으로 유명합니다. MySQL 8에는 JSON 지원, 트랜잭션 데이터 사전, 영구 런타임 구성, 문서 저장소, 옵티마이저 힌트, SQL 역할, CTE 및 창 함수, 보이지 않는 인덱스 등 여러 가지 새로운 기능이 추가되었습니다.

참고: MySQL 8을 설치하기 전에 MySQL 8에는 일부 애플리케이션이 이 버전과 호환되지 않는 몇 가지 새로운 기능 및 변경 사항이 있으므로 공식 문서를 참조하세요.

이 튜토리얼에서는 CentOS 8 서버에 MySQL 8 데이터베이스를 설치하는 방법을 보여줍니다.

전제 조건

  • CentOS 8을 실행하는 서버.\n
  • 서버에 루트 암호가 설정되어 있습니다.\n

MySQL 리포지토리에서 MySQL 8.0 설치

기본적으로 MySQL 8.0은 CentOS 8 기본 리포지토리에서 사용할 수 없습니다. 따라서 시스템에 MySQL 8.0 커뮤니티 저장소를 설치해야 합니다. 다음 명령으로 설치할 수 있습니다.

rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm

다음 출력이 표시되어야 합니다.

Retrieving https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
warning: /var/tmp/rpm-tmp.hF0m5V: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql80-community-release-el8-1  ################################# [100%]

다음으로 다음 명령을 사용하여 MySQL 8.0 리포지토리가 활성화되었는지 여부를 확인합니다.

dnf repolist all | grep mysql | grep enabled

다음 출력이 표시되어야 합니다.

CentOS-8 - AppStream                            3.1 MB/s | 6.5 MB     00:02    
CentOS-8 - Base                                 3.0 MB/s | 5.0 MB     00:01    
CentOS-8 - Extras                               5.3 kB/s | 2.1 kB     00:00    
MySQL 8.0 Community Server                       24 MB/s | 543 kB     00:00    
MySQL Connectors Community                      1.9 MB/s |  19 kB     00:00    
MySQL Tools Community                           677 kB/s |  62 kB     00:00    
mysql-connectors-community         MySQL Connectors Community     enabled:    42
mysql-tools-community              MySQL Tools Community          enabled:    19
mysql80-community                  MySQL 8.0 Community Server     enabled:    31

다음으로 AppStream 리포지토리를 일시적으로 비활성화하고 다음 명령을 사용하여 MySQL 커뮤니티 리포지토리에서 최신 버전의 MySQL 8.0을 설치합니다.

dnf --disablerepo=AppStream install mysql-community-server -y

설치가 성공적으로 완료되면 다음 명령을 사용하여 설치된 MySQL 버전을 확인할 수 있습니다.

mysql -Version

다음 출력이 표시되어야 합니다.

mysql  Ver 8.0.19 for Linux on x86_64 (MySQL Community Server - GPL)

그런 다음 MySQL 서비스를 시작하고 다음 명령을 사용하여 시스템 재부팅 후 시작되도록 활성화합니다.

systemctl start mysqld
systemctl enable mysqld

다음 명령을 사용하여 MySQL의 상태를 확인할 수도 있습니다.

systemctl status mysqld

다음 출력이 표시되어야 합니다.

? mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-03-05 09:37:46 EST; 12s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 3244 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 3329 (mysqld)
   Status: "Server is operational"
    Tasks: 39 (limit: 12537)
   Memory: 587.7M
   CGroup: /system.slice/mysqld.service
           ??3329 /usr/sbin/mysqld

Mar 05 09:37:01 centos8 systemd[1]: Starting MySQL Server...
Mar 05 09:37:46 centos8 systemd[1]: Started MySQL Server.

다음으로 mysql_secure_installation 스크립트를 실행하여 새 MySQL 루트 암호 설정, 익명 사용자 제거 및 원격 로그인 비활성화를 비롯한 몇 가지 추가 보안 기능을 활성화하는 것이 좋습니다.

먼저 다음 명령을 사용하여 MySQL 기본 루트 암호를 찾습니다.

cat /var/log/mysqld.log | grep -i 'temporary password'

산출:

2020-03-05T14:37:40.273796Z 5 [Note] [MY-010454] [Server] A temporary password is generated for : GN2uNx-vPqwS

위의 암호를 기록하고 mysql_secure_installation 스크립트를 사용하여 변경하십시오.

mysql_secure_installation

아래와 같이 모든 질문에 답하십시오.

Securing the MySQL server deployment.

Enter password for user root:   Provide your temporary MySQL root password

The existing password for the user account root has expired. Please set a new password.

New password:   Provide new root password

Re-enter new password:   Re-enter new root password
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) : N  Type N and Enter to continue

 ... skipping.
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!

AppStream 리포지토리에서 MySQL 8.0 설치

CentOS 8의 기본 AppStream 리포지토리에서 MySQL 8.0을 설치할 수도 있습니다. 다음 명령을 사용하여 설치할 수 있습니다.

dnf install @mysql -y

설치가 완료되면 다음 명령을 사용하여 MySQL 버전을 확인합니다.

mysql -Version

다음 출력이 표시되어야 합니다.

mysql  Ver 8.0.17 for Linux on x86_64 (Source distribution)

그런 다음 MySQL 서비스를 시작하고 다음 명령을 사용하여 시스템 재부팅 후 시작되도록 활성화합니다.

systemctl start mysqld
systemctl enable mysqld

기본적으로 CentoS 8에는 MySQL 루트 암호가 설정되어 있지 않으므로 mysql_secure_installation 스크립트를 사용하여 설정해야 합니다.

mysql_secure_installation

아래와 같이 모든 질문에 답하십시오.

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.

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 커뮤니티 리포지토리와 CentOS 8의 AppStream 리포지토리에서 MySQL 8을 설치하는 방법을 배웠습니다. 이제 새 데이터베이스 및 데이터베이스 사용자 생성을 시작할 수 있습니다.