Skip to content

Instantly share code, notes, and snippets.

@sigridjineth
Last active April 8, 2020 06:18
Show Gist options
  • Save sigridjineth/d1a737c825c54b9acd5a4d479f55149e to your computer and use it in GitHub Desktop.
Save sigridjineth/d1a737c825c54b9acd5a4d479f55149e to your computer and use it in GitHub Desktop.
[MySQL Tip] AWS EC2에서 MySQL 데이터베이스에 원격으로 접속하는 방법

How to Allow Remote Connections to MySQL Database Server

문제 상황

  • MySQL은 기본적으로 localhost에서 작동된다.
  • EC2 인스턴스에서 MySQL을 설치하고 원격으로 접속하고 싶은 경우가 있을텐데, 이럴 떄는 별도로 설정을 변경해주어야 한다.

해결 방법 1 (추천하지 않음)

  • MySQL 서버가 특정한 IP만 듣도록 하거나 또는 모든 IP의 접속을 허용하도록 설정을 변경할 수 있다.
  • MySQL Configuration 설정에 들어가서 bind-address 부분을 127.0.0.1 에서 0.0.0.0 으로 변경해주면 된다.
  • 설정을 변경할 수 있는 파일의 위치가 운영체제 별로 다르다는 사실에 주의하면 된다.
    • Ubuntu 계열: /etc/mysql/mysql.conf.d/mysqld.cnf
    • 아마존 리눅스 등 CentOS 계열: /etc/my.cnf
  • sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
  • mysqld.cnf에서 다음과 같이 추가한다. bind-address = 0.0.0.0
  • MySQL 8 버전 이상에서는 [mysqld] 섹션을 추가하고 위의 설정을 넣어주어야 한다.
  • 다음으로 시스템을 재구동한다. sudo systemctl restart mysql
  • 경로가 잘못된 파일로 수정하면 MySQL의 재시작이 되지 않음에 유의한다.

https://linuxize.com/post/mysql-remote-access/

해결 방법 2 (추천)

@sigridjineth
Copy link
Author

NginX Reverse Proxy 설정 방법 및 프론트 산출물 저장경로 알아내기를 정리했습니다.
https://gist.github.com/ksundong/7a1c78c2ffbf743e851bf8bfb2762e7f#file-readme-md

thanks to dion & sunny

@sigridjineth
Copy link
Author

sigridjineth commented Apr 8, 2020

local에서 h2 embedded database를 사용하기 위한 설정

spring.datasource.initialization-mode=embedded
application.properties에서 profile이 분리되어 있을 때, 분리된 profile에 위의 내용을 작성해주면,
embedded database가 실행될 때, scheme.sql같은 파일을 읽어줄 수 있습니다.

thks to dion

@sigridjineth
Copy link
Author

SSH 터널링 알아보기 https://swalloow.github.io/ssh-tunneling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment