웹사이트 검색

Ubuntu 22.04에서 MariaDB를 설치하고 사용하는 방법


이 페이지에서

  1. 전제 조건
  2. MariaDB 설치 및 구성
  3. MariaDB 버전 확인\n
  4. 결론

MariaDB는 애플리케이션 데이터를 저장하는 데 사용되는 강력한 무료 오픈 소스 데이터베이스 관리 시스템입니다. 안정적인 관계형 데이터베이스 관리 시스템이며 널리 사용되는 MySQL 데이터베이스 시스템의 포크입니다. 확장성과 미션 크리티컬 배포를 위해 특별히 설계되었습니다. 이 튜토리얼을 작성할 당시 MariaDB의 최신 버전은 10.6.7입니다. 모든 주요 릴리스는 최소 5년 동안 유지됩니다. 따라서 MariaDB 10.6.7은 2026년까지 지원됩니다.

이 튜토리얼에서는 Ubuntu 22.04 서버에 MariaDB 10.6을 설치하는 방법을 보여줍니다.

전제 조건

  • Ubuntu 22.04를 실행하는 서버.\n
  • 루트 암호는 서버에서 구성됩니다.\n

MariaDB 설치 및 구성

먼저 다음 명령을 사용하여 모든 시스템 패키지를 업데이트합니다.

apt update -y

모든 패키지가 업데이트되면 다음 명령을 사용하여 최신 버전의 MariaDB 서버 및 클라이언트를 설치합니다.

apt-get install mariadb-server mariadb-client -y

성공적으로 설치한 후 MariaDB 서비스를 시작하고 시스템 재부팅 시 시작되도록 활성화합니다.

systemctl start mariadb
systemctl enable mariadb
systemctl status mariadb

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

? mariadb.service - MariaDB 10.6.7 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-06-25 14:34:47 UTC; 39s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 3174 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
    Process: 3175 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 3177 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $?>
    Process: 3218 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 3220 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
   Main PID: 3206 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 13 (limit: 4579)
     Memory: 57.2M
        CPU: 582ms
     CGroup: /system.slice/mariadb.service
             ??3206 /usr/sbin/mariadbd

Jun 25 14:34:47 ubuntu2204 mariadbd[3206]: 2022-06-25 14:34:47 0 [Note] /usr/sbin/mariadbd: ready for connections.
Jun 25 14:34:47 ubuntu2204 mariadbd[3206]: Version: '10.6.7-MariaDB-2ubuntu1'  socket: '/run/mysqld/mysqld.sock'  port: 3306  Ubuntu 22.04
Jun 25 14:34:47 ubuntu2204 systemd[1]: Started MariaDB 10.6.7 database server.
Jun 25 14:34:47 ubuntu2204 /etc/mysql/debian-start[3222]: Upgrading MySQL tables if necessary.

다음으로 MariaDB 설치를 보호하고 MariaDB 루트 암호를 설정해야 합니다. 다음 스크립트를 실행하여 수행할 수 있습니다.

mysql_secure_installation

아래와 같이 현재 루트 암호를 제공하라는 메시지가 표시됩니다.

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 

Enter 키를 누르십시오. 아래와 같이 unix_socket 인증으로 전환하라는 메시지가 표시됩니다.

OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorization.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] Y

Y를 입력하고 Enter 키를 누릅니다. 아래와 같이 루트 암호를 변경하라는 메시지가 표시됩니다.

Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] Y

Y를 입력하고 Enter 키를 눌러 루트 암호를 변경합니다.

New password: 
Re-enter new password: 

보안 암호를 입력하고 Enter 키를 누르십시오. 다음 출력이 표시되어야 합니다.

Password updated successfully!
Reloading privilege tables..
 ... Success!


Next, you will be asked to remove anonymous users as shown below:

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] Y

Y를 입력하고 Enter 키를 눌러 익명 사용자를 제거합니다. 아래와 같이 원격 루트 로그인을 허용하지 않겠다는 메시지가 표시됩니다.

 ... 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? [Y/n] Y

Y를 입력하고 Enter 키를 누릅니다. 아래와 같이 테스트 데이터베이스를 제거하라는 메시지가 표시됩니다.

 ... Success!

By default, MariaDB 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? [Y/n] Y

Y를 입력하고 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? [Y/n] Y

Y를 입력하고 Enter 키를 누르면 다음과 같은 결과가 표시됩니다.

 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

MariaDB 버전 확인

이 시점에서 MariaDB가 설치되고 보호됩니다. 다음으로 설치된 MariaDB 버전을 확인해야 합니다.

먼저 다음 명령을 사용하여 MariaDB 셸에 로그인합니다.

mysql -u root -p

MariaDB 루트 비밀번호를 제공하고 Enter를 누르십시오. 로그인하면 다음 출력이 표시됩니다.

Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 41
Server version: 10.6.7-MariaDB-2ubuntu1 Ubuntu 22.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

다음 명령을 실행하여 MariaDB 버전을 확인합니다.

MariaDB [(none)]> SELECT VERSION();

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

+-------------------------+
| VERSION()               |
+-------------------------+
| 10.6.7-MariaDB-2ubuntu1 |
+-------------------------+
1 row in set (0.000 sec)

결론

축하합니다! Ubuntu 22.04 서버에 MariaDB 10.6을 성공적으로 설치하고 보호했습니다. 이제 새 데이터베이스를 만들고 사용자가 응용 프로그램과 연결할 수 있습니다.