서버 운영/APM 서버 구축

MariaDB 설치

씨실과 날실 2018. 11. 14. 10:00

[관련 게시물]

Ubuntu 20.04 LTS에서 APM 설치

2020/09/14 - [서버 운영/APM 서버 구축] - 우분투(Ubuntu) 20.04에서 APM 설치 - 아파치(Apache2 설치

2020/09/16 - [서버 운영/APM 서버 구축] - 우분투(Ubuntu) 20.04에서 APM 설치 - 마리아DB(MariaDB) 10.3 설치

2020/09/18 - [서버 운영/APM 서버 구축] - 우분투(Ubuntu) 20.04에서 APM 설치 - 마리아DB(MariaDB) 10.5 설치

2020/09/20 - [서버 운영/APM 서버 구축] - 우분투(Ubuntu) 20.04에서 APM 설치 - PHP 7.4 설치

2020/09/22 - [서버 운영/APM 서버 구축] - 우분투(Ubuntu) 20.04에서 APM 설치 - APM 설치 후 방화벽 설정

2020/09/24 - [서버 운영/APM 서버 구축] - MariaDB 10.4 이후의 계정 인증 관련 변화(unix_socket, mysql_native_password 인증 / 계정, 암호 및 전역 권한 정보 저장 테이블 변경 등)

2020/09/26 - [서버 운영/APM 서버 구축] - 우분투 20.04 APM 서버 기본 환경 파일 설정 - apache2.conf 기본 설정

2020/09/28 - [서버 운영/APM 서버 구축] - 우분투 20.04 APM 서버 기본 환경 파일 설정 - php.ini 기본 설정


Ubuntu 18.04 LTS에서 APM 설치

2018/11/09 - [서버 운영/APM 서버 구축] - Apache 서버 설치

2018/11/14 - [서버 운영/APM 서버 구축] - MariaDB 설치

2018/11/16 - [서버 운영/APM 서버 구축] - MariaDB 업그레이드 1

2018/11/16 - [서버 운영/APM 서버 구축] - MariaDB 업그레이드 2 - ERROR 1524 (HY000): Plugin 'unix_socket' is not loaded

2018/11/16 - [서버 운영/APM 서버 구축] - MariaDB 업그레이드 3

2018/11/19 - [서버 운영/APM 서버 구축] - PHP7 설치

2018/11/21 - [서버 운영/APM 서버 구축] - 서버 환경 파일 수정 - php.ini, apache2.conf


Ubuntu 18.04 LTS에서 MariaDB 백업 및 업그레이드

2019/01/15 - [서버 운영/APM 서버 구축] - MariaDB & MySQL 백업과 복원 - Nextcloud 14

2019/06/27 - [서버 운영/APM 서버 구축] - MariaDB 업그레이드 (Upgrading from MariaDB 10.3 to MariaDB 10.4)


Ubuntu 18.04 LTS에서 PHP 버전 전환

2019/07/05 - [서버 운영/APM 서버 구축] - Apache와 Shell에서 PHP 버전 전환하기(How to Switch between Multiple PHP Version)


Ubuntu 18.04 LTS에서 phpmyadmin 설치 및 운용

2018/11/23 - [서버 운영/APM 서버 구축] - phpmyadmin 설치 - APT 패키지 관리자를 통한 설치

2019/06/18 - [서버 운영/APM 서버 구축] - APT 패키지 관리자를 통해 설치한 phpMyAdmin 업그레이드 방법(업그레이드 버전 4.9.0.1)

2019/07/01 - [서버 운영/APM 서버 구축] - phpMyAdmin 수동 설치 01 - 일반 설치

2019/07/03 - [서버 운영/APM 서버 구축] - phpMyAdmin 수동 설치 02 - 심볼릭 링크를 이용한 보안 접속

2019/06/16 - [서버 운영/APM 서버 구축] - phpMyAdmin 4.6.6deb5와 PHP 7.2 간 호환성 문제 해결 - Warning in ./libraries/sql.lib.php#613


XAMPP 설치 및 운용

2019/04/20 - [서버 운영/서버 구축 꾸러미] - XAMPP에 대하여(버전 7.1.28 / 7.2.17 / 7.3.4)

2019/04/22 - [서버 운영/서버 구축 꾸러미] - XAMPP for Windows 7.3.4 인스톨러 설치

2019/04/25 - [서버 운영/서버 구축 꾸러미] - XAMPP for Windows 설정

2019/06/03 - [서버 운영/서버 구축 꾸러미] - XAMPP 포터블(portable) 사용법

2019/06/05 - [서버 운영/서버 구축 꾸러미] - XAMPP for Linux 4.3.5 설치 및 사용법


서버 운영을 위한 관련 연재글

2018/11/07 - [리눅스/Ubuntu] - 방화벽 설정 - ufw

2018/11/12 - [서버 운영/버추얼박스(VirtualBox)] - 가상머신(Virtualbox) 내 서버 외부접속

2019/01/05 - [미디어위키/미디어위키 설치 및 관리] - 호스트 컴퓨터에서 가상머신 내 미디어위키 접속 및 작업을 위한 버추얼박스 포트포워딩 설정

2019/03/15 - [서버 운영/APM 서버 구축] - PHP 7.3으로의 업그레이드 및 사용 연기 권장 안내 - PHP Notice: compact(): Undefined variable:


[관련 웹문서]

https://mariadb.com/kb/en/authentication-plugin-unix-socket/#unix_socket



APT 패키지 관리자를 통한 MariaDB 설치

2018/11/14 - [서버 운영/APM 서버 구축] - MariaDB 설치

MariaDB 업그레이드 후 기존 DB 업그레이드

2018/11/16 - [서버 운영/APM 서버 구축] - MariaDB 업그레이드 1

2018/11/16 - [서버 운영/APM 서버 구축] - MariaDB 업그레이드 2 - ERROR 1524 (HY000): Plugin 'unix_socket' is not loaded

2018/11/16 - [서버 운영/APM 서버 구축] - MariaDB 업그레이드 3

APT 패키지 관리자를 통한 MariaDB 업그레이드

Upgrading from MariaDB 10.2 to MariaDB 10.3

2018/11/16 - [서버 운영/APM 서버 구축] - MariaDB 업그레이드 1

2018/11/16 - [서버 운영/APM 서버 구축] - MariaDB 업그레이드 2 - ERROR 1524 (HY000): Plugin 'unix_socket' is not loaded

2018/11/16 - [서버 운영/APM 서버 구축] - MariaDB 업그레이드 3

Upgrading from MariaDB 10.3 to MariaDB 10.4

2019/06/27 - [서버 운영/APM 서버 구축] - MariaDB 업그레이드 (Upgrading from MariaDB 10.3 to MariaDB 10.4)

[관련 링크]

https://mariadb.com/kb/en/library/changes-improvements-in-mariadb-104/
https://mariadb.com/kb/en/library/upgrading-from-mariadb-103-to-mariadb-104/#how-to-upgrade


안녕하세요. LAMP 중 L(Linux - Ubuntu)과 A(Apache2 서버)를 설치했으므로 이제 M을 설치할 차례입니다.

DB로 예전에는 Mysql이 절대적인 점유율을 자랑했었습니다. 그러나 MySQL의 개발사인 썬 마이크로시스템즈가 오라클에 인수되면서 MySQL의 장래가 불투명해지게 되었습니다. 오라클에는 자체 상용 DB인 오라클 데이터베이스가 존재한데다 외부에서 보기에 오픈소스에 대한 오라클의 태도가 호의적이지 않은 것으로 보여 많은 이들이 걱정을 내비치고 있었습니다. 게다가 구글 대 오라클의 JAVA 저작권 분쟁은 그러한 불안감을 가속화시켰습니다.

그래서 많은 기업과 개인들은 DB를 MySQL에서 MariaDB로 갈아타게 되었습니다.

아직까지 MySQL과 MariaDB는 DB 자체는 호환이 되어 손쉽게 백업, 이전이 가능합니다.

저는 MariaDB를 DB로 선택하여 콘텐츠를 관리하고자 합니다.

터미널에서 다음과 같은 명령을 입력해줍니다.

study@study-VirtualBox:~$ sudo apt install mariadb-server
잘 설치되었는지 확인할 겸 버전 체크를 해보지요.

study@study-VirtualBox:~$ mysql -V
mysql  Ver 15.1 Distrib 10.1.34-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
study@study-VirtualBox:~$ 
위와 같이 나온다면 설치가 제대로 된 것입니다.

이제 MariaDB를 초기화 작업을 시작합니다.

study@study-VirtualBox:~$ sudo mysql_secure_installation

그러면 영어로 간략한 설명이 나온 후 다음과 같은 질문이 나옵니다.

Enter current password for root (enter for none):

현재 암호가 설정되어 있지 않으므로 Enter키를 눌러 넘어갑니다.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation. 
MariaDB의 암호를 설정해주라는 안내가 나옵니다. 반드시 설정해주도록 합시다. 특정 CMS는 DB 접속 암호를 기입하지 않으면 설치 자체가 되지 않는 경우도 있습니다.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!
위는 MariaDB의 암호 설정 과정입니다. 쉬우므로 굳이 해석하지는 않겠습니다.

이후는 아래와 같은 안내가 나옵니다.

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.

이후 몇 가지 질문이 나오는데요. 모두 y를 눌러 설정해줍니다. 아래는 그 과정을 보여줍니다.

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
 ... 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
 ... 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
 - 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
 ... 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!
study@study-VirtualBox:~$

터미널에서 할 수 있는 기본 설정은 끝났습니다.




이제 MariaDB 기초 사용법입니다.

study@study-VirtualBox:~$ sudo mysql -u root -p

위 명령을 입력해줍니다.

-u는 user의, -p는 password의 약자입니다. 해석하면 다음과 같습니다.

sudo : 관리자 권한으로 다음의 명령을 실행하라

mysql : mysql 또는 mariadb를

-u root : 사용자는 root로

-p : 암호를 입력한다

그럼 다음과 같이 나오게 될 것입니다.

study@study-VirtualBox:~$ sudo mysql -u root -p
[sudo] study의 암호: 
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 30
Server version: 10.1.34-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.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)]> 

현재 존재하는 DB 목록을 확인하는 방법은 다음과 같습니다.

MariaDB [(none)]> show databases; 

그럼 다음과 같은 형식으로 목록를 보여줍니다.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.02 sec)
 

캐릭터셋(= 문자셋 = 문자집합)은 다음과 같은 명령으로 확인할 수 있습니다.

MariaDB [(none)]> show variables like 'c%'; 

현재 주류 캐릭터셋은 utf8mb4입니다.

MariaDB [(none)]> show variables like 'c%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8mb4                    |
| character_set_connection | utf8mb4                    |
| character_set_database   | utf8mb4                    |
| character_set_filesystem | binary                     |
| character_set_results    | utf8mb4                    |
| character_set_server     | utf8mb4                    |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
| collation_connection     | utf8mb4_general_ci         |
| collation_database       | utf8mb4_general_ci         |
| collation_server         | utf8mb4_general_ci         |
| completion_type          | NO_CHAIN                   |
| concurrent_insert        | AUTO                       |
| connect_timeout          | 10                         |
+--------------------------+----------------------------+
14 rows in set (0.00 sec)

MariaDB [(none)]> 

특정 DB에 접속에 사용하려면 다음과 같이 입력해줍니다.

MariaDB [(none)]> use DB명
예는 다음과 같습니다.

MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> 
DB 사용을 그만두고 빠져나오려면 다음과 같이 입력해주면 됩니다.

MariaDB [mysql]> \q

또는

MariaDB [mysql]> exit

DB 생성, 삭제, 테이블 생성, 삭제, 수정 등 본격적인 사용법은 전문서적이나 다른 분들이 공개해주신 MariaDB 사용법을 참고하시기 바랍니다.




아래는 예전에 MariaDB 설치시 추가되는 과정입니다.

예전에는 설치 후 MariaDB가 자동으로 실행되지 않았습니다. 그래서 실행명령을 입력해주어야 했습니다.. 아파치처럼 설치하자마자 자동으로 실행되지는 않으므로 실행명령을 입력해주어야 했습니다.

study@study-VirtualBox:~$ sudo systemctl start mariadb
아무런 진행 과정도 나타나지 않고 바로 프롬프트만 나옵니다.

이제 MariaDB를 우분투가 부팅될 때마다 자동으로 실행되도록 설정을 해주어야 합니다. 아래와 같은 명령어를 입력해주세요.

study@study-VirtualBox:~$ sudo systemctl enable mariadb

이제 우분투가 부팅될 때마다 아파치처럼 자동으로 실행될 것입니다.