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 Visual Studio 단축키 정리 digipine 2024.03.28 17
103 프로그래밍 언어 순위 2023년 file digipine 2023.10.30 157
102 Docker 모든 컨테이너를 Stop 또는 Remove 하는 방법 digipine 2021.09.01 202
101 FFServer RTSP Audio Server Config digipine 2023.05.12 238
100 OBS Studio for Http Interface EXE lizard2019 2023.02.15 248
99 이벤트 텍소노미(Event Taxonomy)란 무엇인가요? digipine 2023.08.11 261
98 Git Commnd 사용법 정리 digipine 2017.11.02 264
97 Git 서버 구축 - 우분투[Ubuntu] digipine 2017.11.02 307
96 Compile FFmpeg on Ubuntu, Debian, or Mint digipine 2017.11.02 327
95 mongoose 3.8 싱글 파일 소스 코드 file digipine 2020.09.01 335
94 WPA_SUPPLICANT 빌드 방법 digipine 2017.11.01 338
93 AWS EC2 Ubuntu 용 Docker 설치 스크립트 digipine 2021.09.01 348
92 Windows API - 안전한 문자열 함수들 digipine 2017.10.28 354
91 JDK Install ubuntu digipine 2017.11.02 355
90 Remove all .git files, recursively digipine 2021.11.26 366
89 Ubuntu 18.04 에서 vsftpd 설치하기 lizard2019 2021.03.02 373
88 Ubuntu Git - Latest Version Install digipine 2017.11.02 375
87 ALM의 등장 배경, 오해와 진실 digipine 2017.10.28 377
86 MAC Screen Sharing을 위한 VNC 접속을 위한 Port 변경 방법 digipine 2022.09.05 382
85 xcode xib encountered an error communicating with ibagent-ios 해결 digipine 2022.10.06 384
Board Pagination Prev 1 2 3 4 5 6 Next
/ 6