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
84 Certbot으로 무료 인증서 발급 받기 digipine 2020.09.03 522
83 MongoDB 설치 및 C 개발 도구 설정 1 digipine 2020.09.03 449
82 mongoose 3.8 싱글 파일 소스 코드 file digipine 2020.09.01 335
81 [iOS] Bluetooth로 App을 백그라운드 모드로 실행는 방법 lizard2019 2020.02.11 3514
80 How to Build FFMpeg for LAVFilters file lizard2019 2019.06.05 1449
79 How to FFMpeg Windows Build with msys 1.0 and MinGW_64 file lizard2019 2019.06.05 2208
78 C/C++ struct 패딩(padding) 원리 이해 lizard2019 2019.03.04 2149
77 gcc thread and mutex 사용법 lizard2019 2019.02.27 1198
76 윈도우즈 도스 커멘드(Command) 네트워크 관련 명령어 lizard2019 2019.02.07 1342
75 Ubuntu 우분투 설치 가이드 lizard2019 2019.01.29 780
74 Linux/OSX bash에서 source 명령어 lizard2019 2019.01.07 779
73 Xcode 없이 맥에 '명령어 라인 도구(Command Line Tools)'를 설치하는 방법 엉뚱도마뱀 2018.12.26 2859
72 언어 IDE 별로 git ignore 파일을 자동으로 만들어 주는 사이트 엉뚱도마뱀 2018.12.17 122391
71 [Swift, MacOS] 맥 한글 파일명이 윈도우에서 자소 분리되는 현상 해결, NFD, NFC 엉뚱도마뱀 2018.12.11 20072
70 수학적 구조물 모델링 만들기 소개 비디오 엉뚱도마뱀 2018.09.24 1050
69 Photoshop CC 2018 한글 영문 변환 언어팩, 포토샵 언어변경 file 엉뚱도마뱀 2018.07.04 8525
68 LibVLC 미디어 재생기 프로그래밍 방법 C++, QT 엉뚱도마뱀 2018.04.20 2500
67 select 와 epoll 엉뚱도마뱀 2017.12.11 827
66 비밀번호 해쉬에 Salt(소금) 첨가하기 file 엉뚱도마뱀 2017.11.23 4272
65 Linux /dev/random vs /dev/urandom 삽질 후기 엉뚱도마뱀 2017.11.22 957
Board Pagination Prev 1 2 3 4 5 6 Next
/ 6