Linux Server

[Linux]Ubuntu 20.04 웹 서버 구축(4) - MySQL 설치

톰아저씨의 오두막 2021. 7. 7. 21:01

[Linux]Ubuntu 20.04 웹 서버 구축(4) - MySQL 설치

[Linux] Ubuntu 20.04 web server build (4) - MySQL installation

 

Ubuntu 20.04 and MySQL

 

Server Version : Ubuntu 18.04, Ubuntu 20.04
php Version 7.2
Apache/2.4.29 (Ubuntu)

작업 환경

 

MySQL 개요

MySQL은《RDBMS, Relational Database Management System》로 MariaDB와 함께 가장 폭넓게 사용되고 있습니다. 오픈 라이센스이기 때문에 무료로 사용이 가능하며 윈도우, 유닉스, 리눅스 등 다양한 운영체제에서 PHP, JAVA, C, C++ 등의 여러 프로그램 언어를 위한 API를 제공합니다. 또한 표준 SQL 포맷을 지원하며 다중 사용자, 다중 스레드를 지원합니다.

 

1995년《MySQL AB사》에 의해 첫 번째 버전이 발표되었고 2008년《썬마이크로시스템즈》가《MySQL AB》를 인수하였습니다. 다음 해 2009년에 썬마이크로시스템즈가 오라클에 인수합병되면서 현재까지 오라클이 MySQL에 대한 권리를 행사하고 있습니다.

 

MySQL에서 파생되어 MySQL과 동일한 코드기반으로한 DBMS인 《MariaDB》와의 관계는 아래 글을 참조하시기 바랍니다.

 

 

[Linux]Ubuntu 20.04 웹 서버 구축(2) - MariaDB 설치

[Linux]Ubuntu 20.04 웹 서버 구축(2) - MariaDB 설치 [Linux] Ubuntu 20.04 Web Server Construction - MariaDB Installation MariaDB 개요 MariaDB의 기원은 MySQL Community Code Base 입니다. 오픈 소스의 관..

tomcabin.tistory.com

 

지금 부터《Ubuntu 20.04》에 MySQL을 설치하는 방법을 소개합니다. 

 

MySQL 패키지 설치 전 사전 필수 작업

Ubuntu 에서 리눅스 패키지를 배포하거나 설치하기 전에는 필수적으로 시스템 내에 설치된 패키지들을 업그레이드하여 최신 버전으로 유지해 주는 것이 좋습니다. 패키지 설치 전 필수 작업은 다음 글을 참고바랍니다.

 

 

[Linux]Ubuntu 20.04 패키지 설치 전 사전 필수 작업

[Linux]Ubuntu 20.04 패키지 설치 전 사전 필수 작업 [Linux] Prerequisite tasks before installing Ubuntu 20.04 package Ubuntu 에서 리눅스 패키지를 배포하거나 설치하기 전에는 필수적으로 시스템 내에 설..

tomcabin.tistory.com

 

설치하기 전에《Ubuntu 20.04》또는《Ubuntu 18.04》가 설치되어 있어야 합니다.《Ubuntu 20.04》설치 방법은 아래 글을 참고하시기 바랍니다.

 

 

[가상머신]VMware에 Ubuntu 20.04 LTS 설치하기

[가상머신]VMware에 Ubuntu 20.04 LTS 설치하기 Ubuntu(우분투)는 리눅스를 기반으로 한 운영체제로 많은 사용자를 확보하고 있는 배포판입니다. 영국에 소재한 소프트웨어 업체인 캐노니컬과 우분투 재

tomcabin.tistory.com

 

또한《Apache Server》가 설치되어 있어야 합니다.《Apache Server》설치 방법은 아래 글을 참고하시기 바랍니다.

 

 

[Linux]Ubuntu 20.04 웹 서버 구축(1)-아파치 설치

[Linux]Ubuntu 20.04 웹 서버 구축(1)-아파치 설치 [UBUNTU] UBUNTU 20.04 Web Server Construction(1) - Apache Installation 웹 서버 개요 아파치 서버 설치에 앞서 웹 서버에 대하여 간단하게 설명드립니다...

tomcabin.tistory.com

 

MySQL 설치

 

사전 필수 작업이 완료되었으면 다음 절차에 따라 설치를 진행합니다.

 

ⓐ CLI 터미널 모드에서 다음 명령어를 입력하여 MySQL을 설치합니다.

 

1
uncletom@uncletomvm:~$ sudo apt-get install mysql-server

 

설치가 진행됩니다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
uncletom@uncletomvm:~$ sudo apt-get install mysql-server
[sudo] uncletom의 암호: 
패키지 목록을 읽는 중입니다... 완료
의존성 트리를 만드는 중입니다       
상태 정보를 읽는 중입니다... 완료
다음의 추가 패키지가 설치될 것입니다 :
  libaio1 libcgi-fast-perl libcgi-pm-perl libevent-core-2.1-7 libevent-pthreads-2.1-7
  libfcgi-perl libhtml-template-perl libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils
  mysql-client-8.0 mysql-client-core-8.0 mysql-server-8.0 mysql-server-core-8.0
제안하는 패키지:
  libipc-sharedcache-perl mailx tinyca
다음 새 패키지를 설치할 것입니다:
  libaio1 libcgi-fast-perl libcgi-pm-perl libevent-core-2.1-7 libevent-pthreads-2.1-7
  libfcgi-perl libhtml-template-perl libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils
  mysql-client-8.0 mysql-client-core-8.0 mysql-server mysql-server-8.0 mysql-server-core-8.0
0개 업그레이드, 16개 새로 설치, 0개 제거 및 0개 업그레이드 안 함.
31.0 M바이트 아카이브를 받아야 합니다.
이 작업 후 258 M바이트의 디스크 공간을 더 사용하게 됩니다.
계속 하시겠습니까? [Y/n] Y
받기:1 http://kr.archive.ubuntu.com/ubuntu focal-updates/main amd64 
mysql-client-core-8.0 amd64 8.0.25-0ubuntu0.20.04.1 [4,216 kB]
받기:2 http://kr.archive.ubuntu.com/ubuntu focal-updates/main amd64 
mysql-client-8.0 amd64 8.0.25-0ubuntu0.20.04.1 [22.0 kB]
 
------------------------------<생략>-------------------------------------
 
내려받기 31.0 M바이트, 소요시간 9초 (3,622 k바이트/초)                                        
패키지를 미리 설정하는 중입니다...
Selecting previously unselected package mysql-client-core-8.0.
(데이터베이스 읽는중 ...현재 190893개의 파일과 디렉터리가 설치되어 있습니다.)
Preparing to unpack .../00-mysql-client-core-8.0_8.0.25-0ubuntu0.20.04.1_amd64.deb ...
Unpacking mysql-client-core-8.0 (8.0.25-0ubuntu0.20.04.1) ...
Selecting previously unselected package mysql-client-8.0.
Preparing to unpack .../01-mysql-client-8.0_8.0.25-0ubuntu0.20.04.1_amd64.deb ...
 
------------------------------<생략>-------------------------------------
 
Unpacking mysql-server (8.0.25-0ubuntu0.20.04.1) ...
libmecab2:amd64 (0.996-10build1) 설정하는 중입니다 ...
mysql-client-core-8.0 (8.0.25-0ubuntu0.20.04.1) 설정하는 중입니다 ...
libcgi-pm-perl (4.46-1) 설정하는 중입니다 ...
libhtml-template-perl (2.97-1) 설정하는 중입니다 ...
mecab-utils (0.996-10build1) 설정하는 중입니다 ...
libevent-core-2.1-7:amd64 (2.1.11-stable-1) 설정하는 중입니다 ...
mysql-client-8.0 (8.0.25-0ubuntu0.20.04.1) 설정하는 중입니다 ...
libfcgi-perl (0.79-1) 설정하는 중입니다 ...
libaio1:amd64 (0.3.112-5) 설정하는 중입니다 ...
libevent-pthreads-2.1-7:amd64 (2.1.11-stable-1) 설정하는 중입니다 ...
mecab-ipadic (2.7.0-20070801+main-2.1) 설정하는 중입니다 ...
Compiling IPA dictionary for Mecab.  This takes long time...
reading /usr/share/mecab/dic/ipadic/unk.def ... 40
emitting double-array: 100|###########################################| 
/usr/share/mecab/dic/ipadic/model.def is not found. skipped.
reading /usr/share/mecab/dic/ipadic/Verb.csv ... 130750
reading /usr/share/mecab/dic/ipadic/Symbol.csv ... 208
reading /usr/share/mecab/dic/ipadic/Adnominal.csv ... 135
 
------------------------------<생략>-------------------------------------
 
 
reading /usr/share/mecab/dic/ipadic/Noun.demonst.csv ... 120
reading /usr/share/mecab/dic/ipadic/Auxil.csv ... 199
emitting double-array: 100|###########################################| 
reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316
emitting matrix      : 100|###########################################| 
 
done!
update-alternatives: using /var/lib/mecab/dic/ipadic to provide 
/var/lib/mecab/dic/debian (mecab-dictionary) in auto mode
libcgi-fast-perl (1:2.15-1) 설정하는 중입니다 ...
mysql-server-core-8.0 (8.0.25-0ubuntu0.20.04.1) 설정하는 중입니다 ...
mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) 설정하는 중입니다 ...
Compiling IPA dictionary for Mecab.  This takes long time...
reading /usr/share/mecab/dic/ipadic/unk.def ... 40
emitting double-array: 100|###########################################| 
/usr/share/mecab/dic/ipadic/model.def is not found. skipped.
reading /usr/share/mecab/dic/ipadic/Verb.csv ... 130750
reading /usr/share/mecab/dic/ipadic/Symbol.csv ... 208
reading /usr/share/mecab/dic/ipadic/Adnominal.csv ... 135
 
------------------------------<생략>-------------------------------------
 
reading /usr/share/mecab/dic/ipadic/Noun.demonst.csv ... 120
reading /usr/share/mecab/dic/ipadic/Auxil.csv ... 199
emitting double-array: 100|###########################################| 
reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316
emitting matrix      : 100|###########################################| 
 
done!
update-alternatives: using /var/lib/mecab/dic/ipadic-utf8 to provide 
/var/lib/mecab/dic/debian (mecab-dictionary) in auto mode
mysql-server-8.0 (8.0.25-0ubuntu0.20.04.1) 설정하는 중입니다 ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Renaming removed key_buffer and myisam-recover options (if present)
mysqld will log errors to /var/log/mysql/error.log
mysqld is running as pid 4989
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → 
/lib/systemd/system/mysql.service.
mysql-server (8.0.25-0ubuntu0.20.04.1) 설정하는 중입니다 ...
Processing triggers for systemd (245.4-4ubuntu3.7) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
uncletom@uncletomvm:~$ 

 

 

ⓑ MySQL이 설치되었으면 다음 명령어로 보안 관련 추가 패키지 설치를 진행합니다. 

 

1
root@uncletom:/# sudo mysql_secure_installation

 

 

ⓒ 설치 과정에서 MySQL 암호 관련해서《암호 유효성에 대한 설정 유무》를 질의하는 부분이 있습니다. 'Y'를 입력합니다.

 

1
2
3
4
5
6
7
8
9
10
11
12
root@uncletom:/# sudo 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|for Yes, any other key for No: Y

 

 

ⓓ 다음은《암호 유효성 정책》중 암호 복잡도에 대한 레벨을 선택합니다.

 

1
2
3
4
5
6
7
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: 1

 

 

ⓔ MySQL에서 사용할《root》계정의 암호를 입력하고 입력이 완료되면 암호에 대한 보안 강도를 측정한 후 결과를 표시합니다. 입력한 암호를 사용할 것인지 질의합니다.

 

1
2
3
4
5
6
7
8
Please set the password for root here.
 
New password: 
 
Re-enter new password: 
 
Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|for Yes, any other key for No) : Y

 

 

ⓕ 기본적으로 MySQL 설치하면 기본적으로《익명의 사용자, Anonymous User》가 있습니다. 서버가 테스트용이 아닌 프로덕션용 서버 환경이면 지우는 것이 좋습니다.

 

1
2
3
4
5
6
7
8
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|for Yes, any other key for No) : N

 

 

ⓖ 일반적으로 MySQL의《root》사용자는《Localhost》에서만 접속이 가능합니다. 원활한 관리를 위해서 원격에서 사용가능하도록 설정합니다. 임의의 키로 'N"을 누르면 원격 접속을 허용합니다.

 

1
2
3
4
5
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|for Yes, any other key for No) : Y

 

 

ⓗ 모든 사용자가 접속 가능한 테스트용 DB를 생성할 것인지 묻습니다. 프로덕션 환경으로 가정하고 지우도록 합니다.

 

1
2
3
4
5
6
7
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|for Yes, any other key for No) : Y

 

 

ⓘ 이제 보안 설정의 마지막 단계로 설정한 권한 테이블을 변경된 내용으로 적용되도록 다시 로드 할 것인지 묻습니다. 'Y'를 입력하여 재로드합니다.

 

1
2
3
4
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
 
Reload privilege tables now? (Press y|for Yes, any other key for No) : Y

 

 

ⓙ 이제 모든 설정이 완료되었습니다.

 

1
2
3
4
5
6
7
8
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
 
Reload privilege tables now? (Press y|for Yes, any other key for No) : Y
Success.
 
All done! 
root@uncletom:/#

 

ⓚ MySQL에 접속하여 정상적으로 설치가 되었는지 확인합니다.

 

SQL 문 'show variables like "validate_password%";'을 입력하고 실행해 보면 암호 관련 유효정 정보를 조회해 볼 수 있습니다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
root@uncletom:/# sudo mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.25-0ubuntu0.20.04.1 (Ubuntu)
 
Copyright (c) 20002021, 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> show variables like 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             | 8      |
| validate_password.mixed_case_count   | 1      |
| validate_password.number_count       | 1      |
| validate_password.policy             | MEDIUM |
| validate_password.special_char_count | 1      |
+--------------------------------------+--------+
7 rows in set (0.01 sec)
 
mysql> 
 

 

이상으로《Ubuntu 20.04》에 MySQL을 설치하는 방법을 설명드렸습니다. 데이터베이스 및 사용자 추가 등록 등 관련 정보를 다음에 소개하도록 하겠습니다.

 

감사합니다.