데이터베이스 · 5 min read · Sep 26, 2025
우분투 22.04에 MySQL 8 설치 및 사용 방법

MySQL은 Oracle Cloud에서 제공하는 무료 오픈 소스 관계형 데이터베이스 관리 플랫폼입니다. 검증된 신뢰성, 빠른 처리 속도, 용이성 및 유연성 덕분에 매우 인기가 높습니다. MySQL은 구조적 쿼리 언어를 사용하여 데이터베이스의 내용을 추가, 접근 및 관리합니다. MySQL 8.0은 InnoDB라는 검증된 트랜잭션 저장 엔진에 메타 데이터를 저장합니다. 클라이언트/서버 아키텍처에서 작동하며 우분투, 윈도우, 센트OS 및 데비안 등 모든 주요 운영 체제에 설치할 수 있습니다.
이 튜토리얼에서는 우분투 22.04 서버에 MySQL 8을 설치하는 방법을 보여줍니다.
전제 조건
- 우분투 22.04가 실행되는 서버.
- 서버에 루트 비밀번호가 설정되어 있어야 합니다.
시작하기
먼저, 다음 명령어를 실행하여 모든 시스템 패키지를 최신 버전으로 업데이트하고 업그레이드합니다:
apt update -y
apt upgrade -y모든 패키지가 업데이트되면 다음 단계로 진행할 수 있습니다.
우분투 22.04에 MySQL 8 설치
기본적으로 최신 버전의 MySQL 서버는 우분투 기본 저장소에 포함되어 있습니다. 다음 명령어를 실행하여 설치할 수 있습니다:
apt install mysql-server -yMySQL 서버가 설치되면 다음 명령어를 사용하여 MySQL 버전을 확인할 수 있습니다:
mysql --version다음 출력에서 MySQL 버전을 확인할 수 있습니다:
mysql Ver 8.0.30-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))모든 패키지가 업데이트되면 다음 단계로 진행할 수 있습니다.
MySQL 서비스 관리
기본적으로 MySQL 서비스는 systemd에 의해 관리됩니다. systemctl 명령어를 사용하여 MySQL을 쉽게 시작, 중지 및 상태를 확인할 수 있습니다.
MySQL 서비스를 시작하려면 다음 명령어를 실행합니다:
systemctl start mysqlMySQL 서비스를 중지하려면 다음 명령어를 실행합니다:
systemctl stop mysql다음 명령어를 사용하여 MySQL 서비스의 상태를 확인할 수 있습니다:
systemctl status mysql다음과 같은 출력을 확인할 수 있습니다:
? mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2022-08-21 12:47:24 UTC; 28s ago
Process: 26157 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 26185 (mysqld)
Status: "Server is operational"
Tasks: 41 (limit: 2242)
Memory: 359.8M
CPU: 1.383s
CGroup: /system.slice/mysql.service
??26185 /usr/sbin/mysqld
Aug 21 12:47:23 ubuntu2204 systemd[1]: Starting MySQL Community Server...
Aug 21 12:47:24 ubuntu2204 systemd[1]: Started MySQL Community Server.기본적으로 MySQL은 포트 3306에서 수신 대기합니다. 다음 명령어로 확인할 수 있습니다:
ss -antpl | grep -i mysql다음 출력에서 MySQL 수신 포트를 확인할 수 있습니다:
LISTEN 0 70 127.0.0.1:33060 0.0.0.0:* users:(("mysqld",pid=26185,fd=21))
LISTEN 0 151 127.0.0.1:3306 0.0.0.0:* users:(("mysqld",pid=26185,fd=23)) 모든 패키지가 업데이트되면 다음 단계로 진행할 수 있습니다.
MySQL 설치 보안
다음으로, mysql_secure_installation 스크립트를 실행하여 새로운 MySQL 루트 비밀번호 설정, 익명 사용자 제거 및 원격 로그인 비활성화와 같은 추가 보안 기능을 활성화하는 것이 좋습니다.
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.Y를 입력하고 Enter 키를 눌러 익명 사용자를 제거합니다.
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.Y를 입력하고 Enter 키를 눌러 원격 루트 로그인을 비활성화합니다.
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) : YY를 입력하고 Enter 키를 눌러 테스트 데이터베이스를 제거합니다.
- 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 루트 비밀번호는 설정되어 있지 않습니다. 설정하려면 MySQL 셸에 연결합니다:
mysqlMySQL 셸에 연결되면 다음 명령어로 MySQL 비밀번호를 설정합니다:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'securepassword';다음으로, 다음 명령어를 실행하여 변경 사항을 저장합니다:
mysql> FLUSH PRIVILEGES;다음으로, 다음 명령어를 사용하여 MySQL 셸에서 종료합니다:
mysql> EXIT;다음으로, 루트 비밀번호를 확인하기 위해 MySQL 셸에 다시 로그인합니다:
mysql -u root -p로그인하면 다음과 같이 MySQL 셸에 들어갑니다:
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.30-0ubuntu0.22.04.1 (Ubuntu)
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에서 데이터베이스 및 사용자 생성
다음 명령어를 사용하여 db1이라는 데이터베이스를 생성해 보겠습니다:
mysql> CREATE DATABASE db1;다음 명령어를 사용하여 생성한 데이터베이스를 확인할 수 있습니다:
mysql> SHOW databases;다음과 같은 출력을 확인할 수 있습니다:
+--------------------+
| Database |
+--------------------+
| db1 |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+db1로 데이터베이스를 변경하려면 다음 명령어를 실행합니다:
mysql> USE db1;dbuser라는 사용자를 생성하려면 다음 명령어를 실행합니다:
mysql> CREATE USER 'dbuser'@'%' IDENTIFIED BY 'password';모든 데이터베이스에 대해 dbuser에게 모든 권한을 부여하려면 다음 명령어를 실행합니다:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'dbuser'@'%' WITH GRANT OPTION;변경 사항을 저장하려면 다음 명령어를 실행합니다:
mysql> FLUSH PRIVILEGES;다음 명령어를 사용하여 MySQL 셸에서 종료할 수 있습니다:
mysql> EXIT;작업이 완료되면 다음 단계로 진행할 수 있습니다.
MySQL 서버 제거
서버에서 MySQL 서버를 제거하려면 다음 명령어를 실행합니다:
apt remove mysql-server --purge다음으로, 다음 명령어를 사용하여 원하지 않는 모든 패키지를 제거합니다:
apt autoremove결론
이 게시물에서는 우분투 22.04에 MySQL 8을 설치하는 방법을 배웠습니다. 또한 MySQL 서비스를 관리하고 데이터베이스 및 사용자를 생성하는 방법도 배웠습니다. 이제 MySQL에서 새로운 데이터베이스와 데이터베이스 사용자를 생성할 수 있습니다.
새 게시물을 받은 편지함에서 받기
스팸은 없습니다. 언제든지 구독 해지 가능합니다.