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 LibVLC 미디어 재생기 프로그래밍 방법 C++, QT 엉뚱도마뱀 2018.04.20 2504
83 CMM / CMMI 란 무엇인가? digipine 2017.10.28 2467
82 [ubuntu, 우분투] sendmail 설치 digipine 2017.11.02 2317
81 Ubuntu Server OS 한국어 모드로 설치 후 서버 콘솔에서 한글 깨짐 해결 방법 digipine 2017.10.31 2247
80 How to FFMpeg Windows Build with msys 1.0 and MinGW_64 file lizard2019 2019.06.05 2209
79 C/C++ struct 패딩(padding) 원리 이해 lizard2019 2019.03.04 2150
78 Git Http Backend Upload Size 설정 - Http 500 Error 해결 digipine 2017.11.02 2074
77 XOR Encryption : 단순하면서도 강력한 암호/복호화 기법 digipine 2017.11.02 1737
76 대칭키 암호화관련 개념 정리 digipine 2017.11.09 1641
75 우분투 Nabi 한글 입력기 Tray(트레이) 상단 메뉴바로 옮기기 digipine 2017.11.03 1630
74 리눅스 /dev/random을 이용한 랜덤값 생성 엉뚱도마뱀 2017.11.22 1556
73 MacOS 10.12.2 (OSX) 보안 취약점 공격 코드 2 file digipine 2017.11.02 1556
» Ubuntu 16 에 mysql 5.7 설치 및 원격 설정 file digipine 2017.11.08 1484
71 [Qt] QSettings 클래스의 설명과 사용법, 설정 저장위치 digipine 2017.11.02 1470
70 MacOS 10.12.2 (OSX) KERNEL DEBUGGING file digipine 2017.11.02 1469
69 How to Build FFMpeg for LAVFilters file lizard2019 2019.06.05 1449
68 Ubuntu 16 에 JAVA 1.7.0 jdk 설치 하기 digipine 2017.11.07 1417
67 Docker에서 Phabricator 최신버전 설치 및 버전 확인 방법 file lizard2019 2021.04.15 1401
66 IPv6 프로그래밍 가이드 digipine 2017.11.02 1350
65 윈도우즈 도스 커멘드(Command) 네트워크 관련 명령어 lizard2019 2019.02.07 1342
Board Pagination Prev 1 2 3 4 5 6 Next
/ 6