logo

English

이곳의 프로그래밍관련 정보와 소스는 마음대로 활용하셔도 좋습니다. 다만 쓰시기 전에 통보 정도는 해주시는 것이 예의 일것 같습니다. 질문이나 오류 수정은 siseong@gmail.com 으로 주세요. 감사합니다.

Ubuntu 16 에 mysql 5.7 설치 및 원격 설정

by digipine posted Nov 08, 2017
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print Attachment
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print Attachment

1. MySQL 설치 

 

먼저 설치 가능한 MySQL 버전을 확인 한다.

 

sudo apt-cache search mysql-server

mysql-server - MySQL database server (metapackage depending on the latest version)
mysql-server-5.7 - MySQL database server binaries and system database setup
mysql-server-core-5.7 - MySQL database server binaries
auth2db - Powerful and eye-candy IDS logger, log viewer and alert generator
mariadb-server-10.0 - MariaDB database server binaries
mariadb-server-core-10.0 - MariaDB database core server files
percona-server-server-5.6 - Percona Server database server binaries
percona-xtradb-cluster-server-5.6 - Percona XtraDB Cluster database server binaries  

 

여기서는 5.7 버전이 설치 가능하다고 합니다.

 

sudo apt-get install mysql-server-5.7
 

 

설치 도중에 root password 를 두번 물어 보는데 같은 것을 두번 입력해서 확인 하면됩니다.

우분투서버-mysql설치-3.jpg

 

설치가 끝났으면 루트 계정으로 아래와 같이 확인 해봅니다.

 

루트 계정 설정 법은 다음과 같습니다.

sudo passwd root
암호 입력

su -​ 

netstat -ntlp | grep mysqld
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      
44533/mysqld 

 

이렇게 나오면 정상 힙니다.

 

2.  외부 접속 가능 설정

 

로컬 계정에서만 사용하면 상관없지만 외부 서버나 클라이언트에서 접근하려면 반드시 해제 해야 합니다.

먼저 방화벽에서 MySQL에서 사용하는 포트를 해제 합니다. 위에서 보면 127.0.0.1:3306에서 3306 포트를 사용하는 것을 알 수 있습니다.

sudo ufw allow 3306/tcp

 

이제 mysqld.cnf에서 로컬연결만 허용된 부분을 수정합니다.

nano /etc/mysql/mysql.conf.d/mysqld.cnf 

혹은 vi 입력하고

user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address           = 127.0.0.1
#
# * Fine Tuning
#
key_buffer_size         = 16M
max_allowed_packet      = 16M
thread_stack            = 192K

 편집기에서 bind-address = 127.0.0.1 부분을 찾아 # 로 주석 처리해줍니다.

 

sudo service mysql restart

 

서비스를 재시작 합니다.

 

 

이제 마지막으로 mysql user 권한을 설정해야 합니다.

 

mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2017, 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> 

mysql> select host, user from mysql.user
    -> ;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | debian-sys-maint |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.00 sec)


 

위와 같이 명령을 입력해보면  root 계정이 localhost만 접속이 가능하다고 나옵니다.

 

mysql>use mysql 

mysql> grant all privileges on *.* to 'root'@'%' identified by 'root123' with grant option;

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

 

이렇게 해주면 root 계정이 password 'root123' 으로 모든 ip 대역에서 접속 허용됩니다.

ip 대역을 주거나 특정 ip 만 접속하려면 'root'@'192.168.0.%' 혹은 'root'@'192.168.0.10' 이런 식으로 설정하시면 됩니다.

 

이제 외부에서 접속 가능한지 확인해보시면 됩니다.

netstat -ntlp | grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      
46110/mysqld 


List of Articles
No. Subject Author Date Views
104 TCP/IP State Transition - TCP 스택 포팅 시 참조 file digipine 2017.11.02 194828
103 언어 IDE 별로 git ignore 파일을 자동으로 만들어 주는 사이트 엉뚱도마뱀 2018.12.17 122387
102 What is Android Repo? and Manual, Download file digipine 2017.11.02 99553
101 [Linux] ubuntu 16.04에 QT Creator 설치하기 digipine 2017.11.02 24329
100 [Swift, MacOS] 맥 한글 파일명이 윈도우에서 자소 분리되는 현상 해결, NFD, NFC 엉뚱도마뱀 2018.12.11 20072
99 Linux init.d 에서 등록하기. 부팅 시 자동실행 설정 digipine 2017.11.03 12565
98 FFT (Fast Fourier Transform) 고속 푸리에 변환 예제 소스 digipine 2017.10.29 12544
97 Photoshop CC 2018 한글 영문 변환 언어팩, 포토샵 언어변경 file 엉뚱도마뱀 2018.07.04 8525
96 Phabricator 설치 가이드 우분투 16.04 기준 digipine 2017.11.02 6193
95 ATmega8 MCU 간의 TWI 기능을 이용한 I2C 통신 digipine 2017.11.02 5986
94 WinPCap과 Ethereal, Wireshark 을 이용한 스니핑(Sniffing) digipine 2017.10.29 5428
93 공짜 무료 C/C++ 컴파일러들 file digipine 2017.10.28 4376
92 난수발생기 개론 엉뚱도마뱀 2017.11.22 4311
91 비밀번호 해쉬에 Salt(소금) 첨가하기 file 엉뚱도마뱀 2017.11.23 4272
90 [iOS] Bluetooth로 App을 백그라운드 모드로 실행는 방법 lizard2019 2020.02.11 3514
89 OpenAL 사용법 정리 1 digipine 2017.11.01 3397
88 [Linux, OSX] pfctl - Packet FIlter Control 사용법 digipine 2017.11.02 3179
87 Xcode 없이 맥에 '명령어 라인 도구(Command Line Tools)'를 설치하는 방법 엉뚱도마뱀 2018.12.26 2859
86 WIN CE, GPS - NMEA protocol - GPS Virtual Driver digipine 2017.10.28 2829
85 초고속망 통신사 DNS 서버 주소 모음 - DNS 설정 digipine 2017.11.03 2630
Board Pagination Prev 1 2 3 4 5 6 Next
/ 6