본문 바로가기

리눅스

CentOS 7에 yum 패키지 매니저를 사용하여 MySQL을 설치하는 방법

728x90

CentOS 7에 yum 패키지 매니저를 사용하여 MySQL을 설치하는 방법

MySQL Community 버전 다운로드 링크

m1

m2

1. MySQL Community Repository 다운로드 및 설치

  • MySQL Community Repository 다운로드
wget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
  • MySQL Community Repository 설치
yum install mysql80-community-release-el7-7.noarch.rpm
  • MySQL 저장소 목록
yum repolist enabled | grep mysql
$ yum repolist enabled | grep mysql
mysql-connectors-community/x86_64                     MySQL Connectors Co    206
mysql-tools-community/x86_64                          MySQL Tools Communi     94
mysql80-community/x86_64                              MySQL 8.0 Community    367
yum search mysql-community
$ yum search mysql-community
...
==================== N/S matched: mysql-community ====================
mysql-community-client.i686 : MySQL database client applications and tools
mysql-community-client.x86_64 : MySQL database client applications and tools
mysql-community-client-plugins.i686 : Shared plugins for MySQL client applications
mysql-community-client-plugins.x86_64 : Shared plugins for MySQL client applications
mysql-community-common.i686 : MySQL database common files for server and client libs
mysql-community-common.x86_64 : MySQL database common files for server and client libs
mysql-community-devel.i686 : Development header files and libraries for MySQL database client applications
mysql-community-devel.x86_64 : Development header files and libraries for MySQL database client applications
mysql-community-embedded-compat.i686 : MySQL embedded compat library
mysql-community-embedded-compat.x86_64 : MySQL embedded compat library
mysql-community-icu-data-files.i686 : MySQL packaging of ICU data files
mysql-community-icu-data-files.x86_64 : MySQL packaging of ICU data files
mysql-community-libs.i686 : Shared libraries for MySQL database client applications
mysql-community-libs.x86_64 : Shared libraries for MySQL database client applications
mysql-community-libs-compat.i686 : Shared compat libraries for MySQL 5.6.37 database client applications
mysql-community-libs-compat.x86_64 : Shared compat libraries for MySQL 5.6.51 database client applications
mysql-community-release.noarch : MySQL repository configuration for yum
mysql-community-server.x86_64 : A very fast and reliable SQL database server
mysql-community-server-debug.x86_64 : The debug version of MySQL server
mysql-community-test.x86_64 : Test suite for the MySQL database server

2. MySQL Server(mysqld) 설치

sudo yum install -y mysql-community-server
728x90
  • MySQL Server(mysqld) 버전 정보 확인
mysqld -V
$ mysqld -V
/usr/sbin/mysqld  Ver 8.0.31 for Linux on x86_64 (MySQL Community Server - GPL)

3. MySQL Server(mysqld) 서비스 관리

MySQL Server를 시작하고 부팅 시 자동으로 시작되도록 활성화합니다.

systemctl --now enable mysqld
systemctl status mysqld
$ systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 화 2022-11-29 13:19:24 KST; 17s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 23448 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 23676 (mysqld)
   Status: "Server is operational"
    Tasks: 39
   Memory: 442.9M
   CGroup: /system.slice/mysqld.service
           └─23676 /usr/sbin/mysqld

11월 29 13:18:50 serv-24 systemd[1]: Starting MySQL Server...
11월 29 13:19:24 serv-24 systemd[1]: Started MySQL Server.

4. 임시 비밀번호 찾기

MySQL Server를 처음 시작할 때 임시 루트 비밀번호가 생성됩니다. 이 비밀번호를 찾으려면 다음 명령어를 사용합니다.

  • mysqld.log(/var/log/mysqld.log) 로그 확인
    • [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: i&lSAsQtu2Pq
vim /var/log/mysqld.log
$ vim /var/log/mysqld.log 
2022-11-29T04:18:52.510268Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.31) initializing of server in progress as process 23481
2022-11-29T04:18:52.563802Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-11-29T04:18:56.385512Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-11-29T04:19:04.608254Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: i&lSAsQtu2Pq
2022-11-29T04:19:23.480197Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.31) starting as process 23676
2022-11-29T04:19:23.503277Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-11-29T04:19:23.947482Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-11-29T04:19:24.663295Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-11-29T04:19:24.663381Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-11-29T04:19:24.720662Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2022-11-29T04:19:24.720686Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.31'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server - GPL.
cat /var/log/mysqld.log | egrep "A temporary password is generated"
$ cat /var/log/mysqld.log | egrep "A temporary password is generated"
2022-11-29T04:19:04.608254Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: i&lSAsQtu2Pq

5. MySQL에 접속 및 비밀번호 변경

  • 임시 비밀번호를 입력하고 MySQL에 접속합니다.
mysql -uroot -p'i&lSAsQtu2Pq'
$ mysql -uroot -p'i&lSAsQtu2Pq'
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.31

Copyright (c) 2000, 2022, 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>
  • MySQL ROOT 패스워드 변경
    • 임시 루트 비밀번호를 찾았다면 MySQL에 접속하여 비밀번호를 변경합니다.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'rootPassword1!';
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'rootPassword1!';
Query OK, 0 rows affected (0.05 sec)

6. MySQL 서비스 재시작

  • MySQL 서비스 재시작 비밀번호를 변경한 후 MySQL 서비스를 다시 시작합니다.
sudo systemctl restart mysqld

 

728x90