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
24 Mac Address 를 String 으로 변환하는 간편한 방법 digipine 2017.11.02 437
23 What is Android Repo? and Manual, Download file digipine 2017.11.02 99670
22 Compile FFmpeg on Ubuntu, Debian, or Mint digipine 2017.11.02 327
21 Wi-Fi display (miracast) FFMpeg MpegTs Supported digipine 2017.11.02 1302
20 Iconv 사용법 소스 digipine 2017.11.01 1262
19 WPA_SUPPLICANT 빌드 방법 digipine 2017.11.01 544
18 WPA_SUPPLICANT 빌드 방법 digipine 2017.11.01 338
17 OpenAL 사용법 정리 1 digipine 2017.11.01 3398
16 QCAD 1.1 한국 최초의 2D CAD 소프트웨어 file digipine 2017.11.01 830
15 Ubuntu Server OS 한국어 모드로 설치 후 서버 콘솔에서 한글 깨짐 해결 방법 digipine 2017.10.31 2247
14 Linux(리눅스) 파일 시스템 정리 (ext, ext2, ext3, ext4) digipine 2017.10.29 1109
13 FFT (Fast Fourier Transform) 고속 푸리에 변환 예제 소스 digipine 2017.10.29 12548
12 WinPCap과 Ethereal, Wireshark 을 이용한 스니핑(Sniffing) digipine 2017.10.29 5428
11 Windows에서 SVN 용 폴더 한 번에 삭제하기 digipine 2017.10.29 463
10 NMEA-0183을 이용한 GPS 애플리케이션 제작 digipine 2017.10.28 446
9 WIN CE, GPS - NMEA protocol - GPS Virtual Driver digipine 2017.10.28 2830
8 WIN CE C++ 시리얼 제어 방법 digipine 2017.10.28 631
7 Windows API - 안전한 문자열 함수들 digipine 2017.10.28 354
6 Thread간 동기화관리자 digipine 2017.10.28 572
5 CMM / CMMI 란 무엇인가? digipine 2017.10.28 2467
Board Pagination Prev 1 2 3 4 5 6 Next
/ 6