리눅스

CentOS 7에 YUM을 사용하여 MySQL을 설치하는 방법

변군이글루 2024. 10. 6. 23:43
반응형

CentOS 7에 YUM을 사용하여 MySQL을 설치하는 방법

1. MySQL YUM 리포지토리 추가

MySQL을 설치하려면 MySQL의 공식 YUM 리포지토리를 CentOS 7에 추가하면 최신 MySQL을 설치할 수 있습니다.

 

MySQL 리포지토리 RPM 다운로드

wget https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm

MySQL 리포지토리 설치

sudo yum localinstall mysql80-community-release-el7-5.noarch.rpm

2. MySQL 설치

YUM을 사용하여 MySQL 서버 패키지를 GPG 키 확인을 비활성화하고 설치합니다.

sudo yum install -y mysql-server --nogpgcheck

3. MySQL 버전 확인

MySQL 버전을 확인할 수 있습니다.

mysql --version
$ mysql --version
mysql  Ver 8.0.39 for Linux on x86_64 (MySQL Community Server - GPL)

4. MySQL 서비스 시작

MySQL 서비스를 시작하고 자동으로 부팅 시 실행되도록 설정합니다.

sudo systemctl --now enable mysqld

5. MySQL 상태 확인

MySQL 서비스가 정상적으로 실행되고 있는지 확인하려면 다음 명령어로 상태를 확인할 수 있습니다.

sudo systemctl status mysqld

6. MySQL 초기 비밀번호 확인

MySQL 5.7 이상에서는 MySQL 설치 후 MySQL의 기본 루트 비밀번호가 /var/log/mysqld.log 파일에 기록됩니다.

sudo grep 'temporary password' /var/log/mysqld.log
2023-10-06T14:25:17.000345Z 1 [Note] A temporary password is generated for root@localhost: Abc123xyz!

7. MySQL 보안 설정

mysql_secure_installation 스크립트를 사용하여 보안 관련 설정을 완료합니다.

sudo mysql_secure_installation
$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:

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

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) : No

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

8. MySQL 로그인

기본적으로 root 사용자로 로그인하며 보안 설정 중에 지정한 비밀번호를 사용합니다.

mysql -u root -p
select version();
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.39    |
+-----------+
1 row in set (0.00 sec)

9. MySQL 재시작 및 중지

MySQL 재시작

sudo systemctl restart mysqld

MySQL 중지

sudo systemctl stop mysqld

 

CentOS 7에서 YUM을 사용하여 MySQL을 설치하고, 초기 설정을 완료할 수 있습니다.

 

728x90
반응형