허당 레몬도리

https://www.fun25.co.kr/blog/ubuntu-16-04-mysql-server-install/

OS: Ubuntu 16.04

# apt-get update
# apt-get install mysql-server

MySQL 서버의 root 계정의 암호를 설정한다. 이 암호는 설치 후 반드시 필요하니 꼭 메모해 두도록 한다.

enter image description here

설치시에 나오는 메시지이다.

패키지 목록을 읽는 중입니다... 완료
의존성 트리를 만드는 중입니다       
상태 정보를 읽는 중입니다... 완료
The following additional packages will be installed:
  apparmor libaio1 libapparmor-perl libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.0-5 libfcgi-perl
  libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl
  liblwp-mediatypes-perl libnuma1 libtimedate-perl liburi-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common
  mysql-server-5.7 mysql-server-core-5.7 psmisc
제안하는 패키지:
  apparmor-profiles apparmor-profiles-extra apparmor-docs apparmor-utils libdata-dump-perl libipc-sharedcache-perl libwww-perl
  mailx tinyca
다음 새 패키지를 설치할 것입니다:
  apparmor libaio1 libapparmor-perl libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.0-5 libfcgi-perl
  libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl
  liblwp-mediatypes-perl libnuma1 libtimedate-perl liburi-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server
  mysql-server-5.7 mysql-server-core-5.7 psmisc
0개 업그레이드, 25개 새로 설치, 0개 제거 및 74개 업그레이드 안 함.
19.5 M바이트 아카이브를 받아야 합니다.
이 작업 후 165 M바이트의 디스크 공간을 더 사용하게 됩니다.
계속 하시겠습니까? [Y/n] 
받기:1 http://ftp.daumkakao.com/ubuntu xenial-updates/main amd64 mysql-common all 5.7.17-0ubuntu0.16.04.2 [15.7 kB]
받기:2 http://ftp.daumkakao.com/ubuntu xenial-updates/main amd64 libapparmor-perl amd64 2.10.95-0ubuntu2.6 [31.4 kB]
받기:3 http://ftp.daumkakao.com/ubuntu xenial-updates/main amd64 apparmor amd64 2.10.95-0ubuntu2.6 [450 kB]
받기:4 http://ftp.daumkakao.com/ubuntu xenial/main amd64 libaio1 amd64 0.3.110-2 [6,356 B]
받기:5 http://ftp.daumkakao.com/ubuntu xenial/main amd64 libnuma1 amd64 2.0.11-1ubuntu1 [21.0 kB]
받기:6 http://ftp.daumkakao.com/ubuntu xenial-updates/main amd64 mysql-client-core-5.7 amd64 5.7.17-0ubuntu0.16.04.2 [6,516 kB]
받기:7 http://ftp.daumkakao.com/ubuntu xenial-updates/main amd64 mysql-client-5.7 amd64 5.7.17-0ubuntu0.16.04.2 [1,666 kB]
받기:8 http://ftp.daumkakao.com/ubuntu xenial-updates/main amd64 mysql-server-core-5.7 amd64 5.7.17-0ubuntu0.16.04.2 [7,564 kB]
받기:9 http://ftp.daumkakao.com/ubuntu xenial/main amd64 psmisc amd64 22.21-2.1build1 [48.0 kB]
받기:10 http://ftp.daumkakao.com/ubuntu xenial-updates/main amd64 libevent-core-2.0-5 amd64 2.0.21-stable-2ubuntu0.16.04.1 [70.6 kB]
받기:11 http://ftp.daumkakao.com/ubuntu xenial-updates/main amd64 mysql-server-5.7 amd64 5.7.17-0ubuntu0.16.04.2 [2,466 kB]
받기:12 http://ftp.daumkakao.com/ubuntu xenial/main amd64 libhtml-tagset-perl all 3.20-2 [13.5 kB]
받기:13 http://ftp.daumkakao.com/ubuntu xenial/main amd64 liburi-perl all 1.71-1 [76.9 kB]
받기:14 http://ftp.daumkakao.com/ubuntu xenial/main amd64 libhtml-parser-perl amd64 3.72-1 [86.1 kB]
받기:15 http://ftp.daumkakao.com/ubuntu xenial/main amd64 libcgi-pm-perl all 4.26-1 [185 kB]
받기:16 http://ftp.daumkakao.com/ubuntu xenial/main amd64 libfcgi-perl amd64 0.77-1build1 [32.3 kB]
받기:17 http://ftp.daumkakao.com/ubuntu xenial/main amd64 libcgi-fast-perl all 1:2.10-1 [10.2 kB]
받기:18 http://ftp.daumkakao.com/ubuntu xenial/main amd64 libencode-locale-perl all 1.05-1 [12.3 kB]
받기:19 http://ftp.daumkakao.com/ubuntu xenial/main amd64 libhtml-template-perl all 2.95-2 [60.4 kB]
받기:20 http://ftp.daumkakao.com/ubuntu xenial/main amd64 libtimedate-perl all 2.3000-2 [37.5 kB]
받기:21 http://ftp.daumkakao.com/ubuntu xenial/main amd64 libhttp-date-perl all 6.02-1 [10.4 kB]
받기:22 http://ftp.daumkakao.com/ubuntu xenial/main amd64 libio-html-perl all 1.001-1 [14.9 kB]
받기:23 http://ftp.daumkakao.com/ubuntu xenial/main amd64 liblwp-mediatypes-perl all 6.02-1 [21.7 kB]
받기:24 http://ftp.daumkakao.com/ubuntu xenial/main amd64 libhttp-message-perl all 6.11-1 [74.3 kB]
받기:25 http://ftp.daumkakao.com/ubuntu xenial-updates/main amd64 mysql-server all 5.7.17-0ubuntu0.16.04.2 [10.8 kB]
내려받기 19.5 M바이트, 소요시간 5초 (3,442 k바이트/초)
패키지를 미리 설정하는 중입니다...
Selecting previously unselected package mysql-common.
(데이터베이스 읽는중 ...현재 14946개의 파일과 디렉터리가 설치되어 있습니다.)
Preparing to unpack .../mysql-common_5.7.17-0ubuntu0.16.04.2_all.deb ...
Unpacking mysql-common (5.7.17-0ubuntu0.16.04.2) ...
Selecting previously unselected package libapparmor-perl.
Preparing to unpack .../libapparmor-perl_2.10.95-0ubuntu2.6_amd64.deb ...
Unpacking libapparmor-perl (2.10.95-0ubuntu2.6) ...
Selecting previously unselected package apparmor.
Preparing to unpack .../apparmor_2.10.95-0ubuntu2.6_amd64.deb ...
Unpacking apparmor (2.10.95-0ubuntu2.6) ...
Selecting previously unselected package libaio1:amd64.
Preparing to unpack .../libaio1_0.3.110-2_amd64.deb ...
Unpacking libaio1:amd64 (0.3.110-2) ...
Selecting previously unselected package libnuma1:amd64.
Preparing to unpack .../libnuma1_2.0.11-1ubuntu1_amd64.deb ...
Unpacking libnuma1:amd64 (2.0.11-1ubuntu1) ...
Selecting previously unselected package mysql-client-core-5.7.
Preparing to unpack .../mysql-client-core-5.7_5.7.17-0ubuntu0.16.04.2_amd64.deb ...
Unpacking mysql-client-core-5.7 (5.7.17-0ubuntu0.16.04.2) ...
Selecting previously unselected package mysql-client-5.7.
Preparing to unpack .../mysql-client-5.7_5.7.17-0ubuntu0.16.04.2_amd64.deb ...
Unpacking mysql-client-5.7 (5.7.17-0ubuntu0.16.04.2) ...
Selecting previously unselected package mysql-server-core-5.7.
Preparing to unpack .../mysql-server-core-5.7_5.7.17-0ubuntu0.16.04.2_amd64.deb ...
Unpacking mysql-server-core-5.7 (5.7.17-0ubuntu0.16.04.2) ...
Selecting previously unselected package psmisc.
Preparing to unpack .../psmisc_22.21-2.1build1_amd64.deb ...
Unpacking psmisc (22.21-2.1build1) ...
Selecting previously unselected package libevent-core-2.0-5:amd64.
Preparing to unpack .../libevent-core-2.0-5_2.0.21-stable-2ubuntu0.16.04.1_amd64.deb ...
Unpacking libevent-core-2.0-5:amd64 (2.0.21-stable-2ubuntu0.16.04.1) ...
Processing triggers for systemd (229-4ubuntu10) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
mysql-common (5.7.17-0ubuntu0.16.04.2) 설정하는 중입니다 ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Selecting previously unselected package mysql-server-5.7.
(데이터베이스 읽는중 ...현재 15287개의 파일과 디렉터리가 설치되어 있습니다.)
Preparing to unpack .../mysql-server-5.7_5.7.17-0ubuntu0.16.04.2_amd64.deb ...
Unpacking mysql-server-5.7 (5.7.17-0ubuntu0.16.04.2) ...
Selecting previously unselected package libhtml-tagset-perl.
Preparing to unpack .../libhtml-tagset-perl_3.20-2_all.deb ...
Unpacking libhtml-tagset-perl (3.20-2) ...
Selecting previously unselected package liburi-perl.
Preparing to unpack .../liburi-perl_1.71-1_all.deb ...
Unpacking liburi-perl (1.71-1) ...
Selecting previously unselected package libhtml-parser-perl.
Preparing to unpack .../libhtml-parser-perl_3.72-1_amd64.deb ...
Unpacking libhtml-parser-perl (3.72-1) ...
Selecting previously unselected package libcgi-pm-perl.
Preparing to unpack .../libcgi-pm-perl_4.26-1_all.deb ...
Unpacking libcgi-pm-perl (4.26-1) ...
Selecting previously unselected package libfcgi-perl.
Preparing to unpack .../libfcgi-perl_0.77-1build1_amd64.deb ...
Unpacking libfcgi-perl (0.77-1build1) ...
Selecting previously unselected package libcgi-fast-perl.
Preparing to unpack .../libcgi-fast-perl_1%3a2.10-1_all.deb ...
Unpacking libcgi-fast-perl (1:2.10-1) ...
Selecting previously unselected package libencode-locale-perl.
Preparing to unpack .../libencode-locale-perl_1.05-1_all.deb ...
Unpacking libencode-locale-perl (1.05-1) ...
Selecting previously unselected package libhtml-template-perl.
Preparing to unpack .../libhtml-template-perl_2.95-2_all.deb ...
Unpacking libhtml-template-perl (2.95-2) ...
Selecting previously unselected package libtimedate-perl.
Preparing to unpack .../libtimedate-perl_2.3000-2_all.deb ...
Unpacking libtimedate-perl (2.3000-2) ...
Selecting previously unselected package libhttp-date-perl.
Preparing to unpack .../libhttp-date-perl_6.02-1_all.deb ...
Unpacking libhttp-date-perl (6.02-1) ...
Selecting previously unselected package libio-html-perl.
Preparing to unpack .../libio-html-perl_1.001-1_all.deb ...
Unpacking libio-html-perl (1.001-1) ...
Selecting previously unselected package liblwp-mediatypes-perl.
Preparing to unpack .../liblwp-mediatypes-perl_6.02-1_all.deb ...
Unpacking liblwp-mediatypes-perl (6.02-1) ...
Selecting previously unselected package libhttp-message-perl.
Preparing to unpack .../libhttp-message-perl_6.11-1_all.deb ...
Unpacking libhttp-message-perl (6.11-1) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_5.7.17-0ubuntu0.16.04.2_all.deb ...
Unpacking mysql-server (5.7.17-0ubuntu0.16.04.2) ...
Processing triggers for systemd (229-4ubuntu10) ...
Processing triggers for ureadahead (0.100.0-19) ...
libapparmor-perl (2.10.95-0ubuntu2.6) 설정하는 중입니다 ...
apparmor (2.10.95-0ubuntu2.6) 설정하는 중입니다 ...
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
diff: /var/lib/apparmor/profiles/.apparmor.md5sums: No such file or directory
libaio1:amd64 (0.3.110-2) 설정하는 중입니다 ...
libnuma1:amd64 (2.0.11-1ubuntu1) 설정하는 중입니다 ...
mysql-client-core-5.7 (5.7.17-0ubuntu0.16.04.2) 설정하는 중입니다 ...
mysql-client-5.7 (5.7.17-0ubuntu0.16.04.2) 설정하는 중입니다 ...
mysql-server-core-5.7 (5.7.17-0ubuntu0.16.04.2) 설정하는 중입니다 ...
psmisc (22.21-2.1build1) 설정하는 중입니다 ...
libevent-core-2.0-5:amd64 (2.0.21-stable-2ubuntu0.16.04.1) 설정하는 중입니다 ...
mysql-server-5.7 (5.7.17-0ubuntu0.16.04.2) 설정하는 중입니다 ...
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)
libhtml-tagset-perl (3.20-2) 설정하는 중입니다 ...
liburi-perl (1.71-1) 설정하는 중입니다 ...
libhtml-parser-perl (3.72-1) 설정하는 중입니다 ...
libcgi-pm-perl (4.26-1) 설정하는 중입니다 ...
libfcgi-perl (0.77-1build1) 설정하는 중입니다 ...
libcgi-fast-perl (1:2.10-1) 설정하는 중입니다 ...
libencode-locale-perl (1.05-1) 설정하는 중입니다 ...
libhtml-template-perl (2.95-2) 설정하는 중입니다 ...
libtimedate-perl (2.3000-2) 설정하는 중입니다 ...
libhttp-date-perl (6.02-1) 설정하는 중입니다 ...
libio-html-perl (1.001-1) 설정하는 중입니다 ...
liblwp-mediatypes-perl (6.02-1) 설정하는 중입니다 ...
libhttp-message-perl (6.11-1) 설정하는 중입니다 ...
mysql-server (5.7.17-0ubuntu0.16.04.2) 설정하는 중입니다 ...
Processing triggers for systemd (229-4ubuntu10) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...

설치된 MySQL 버전을 확인해 볼려면 아래와 같이 dkpg 명령어를 이용한다. MySQL 5.7 버전으로 설치가 되었다.

# dpkg --list | grep mysql
ii  mysql-client-5.7           5.7.17-0ubuntu0.16.04.2         amd64        MySQL database client binaries
ii  mysql-client-core-5.7      5.7.17-0ubuntu0.16.04.2         amd64        MySQL database core client binaries
ii  mysql-common               5.7.17-0ubuntu0.16.04.2         all          MySQL database common files, e.g. /etc/mysql/my.cnf
ii  mysql-server               5.7.17-0ubuntu0.16.04.2         all          MySQL database server (metapackage depending on the latest version)
ii  mysql-server-5.7           5.7.17-0ubuntu0.16.04.2         amd64        MySQL database server binaries and system database setup
ii  mysql-server-core-5.7      5.7.17-0ubuntu0.16.04.2         amd64        MySQL database server binaries

MySQL 서버 시작

# service mysql start

MySQL 서버 종료

# service mysql stop

설정 파일 위치는 /etc/mysql/my.cnf 이다. 아래와 같이 클라이언트와 서버쪽 설정 파일을 include 하도록 되어 있다.

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

서버쪽 설정을 변경할려면 /etc/mysql/mysql/conf.d/mysqld.cnf 를 수정하면 된다. MySQL 서버는 초기 설치시에 바인딩 어드레스가 127.0.0.1 로 되어 있기 때문에 리모트에서 접속이 불가하다. 리모트에서 접속을 할려면 아래와 같이 bind-address 를 0.0.0.0 으로 한 후 MySQL 서버를 재시작한다.

#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 0.0.0.0

MySQL 서버로 접속해 본다.

root@api_mysql_dev:~# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.17-0ubuntu0.16.04.2 (Ubuntu)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

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> 

외부 접속 설정(https://zetawiki.com/wiki/MySQL_%EC%9B%90%EA%B2%A9_%EC%A0%91%EC%86%8D_%ED%97%88%EC%9A%A9)

모든 IP 허용
INSERT INTO mysql.user (host,user,authentication_string,ssl_cipher, x509_issuer, x509_subject) VALUES ('%','root',password('패스워드'),'','','');
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
FLUSH PRIVILEGES;
IP 대역 허용 ( 예: 111.222.xxx.xxx )
  • 다음과 같이 설정하면 111.222로 시작하는 모든 IP가 허용된다.
INSERT INTO mysql.user (host,user,authentication_string,ssl_cipher, x509_issuer, x509_subject) VALUES ('111.222.%','root',password('패스워드'),'','','');
GRANT ALL PRIVILEGES ON *.* TO 'root'@'111.222.%';
FLUSH PRIVILEGES;
특정 IP 1개 허용 ( 예: 111.222.33.44 )
INSERT INTO mysql.user (host,user,authentication_string,ssl_cipher, x509_issuer, x509_subject) VALUES ('111.222.33.44','root',password('패스워드'),'','','');
GRANT ALL PRIVILEGES ON *.* TO 'root'@'111.222.33.44';
FLUSH PRIVILEGES;
  • 모든 IP를 허용한 경우 다음과 같이 원래 상태로 복구할 수 있다.
DELETE FROM mysql.user WHERE Host='%' AND User='root';
FLUSH PRIVILEGES;


profile

허당 레몬도리

@LemonDory

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!