Skip to content

Instantly share code, notes, and snippets.

@centell
Last active May 16, 2019 07:17
Show Gist options
  • Select an option

  • Save centell/2d4fd905ca69cc64a0534bf80dd6a87c to your computer and use it in GitHub Desktop.

Select an option

Save centell/2d4fd905ca69cc64a0534bf80dd6a87c to your computer and use it in GitHub Desktop.
MySQL 외부 접근 허용하기

ODBC등 외부에서 MySQL에 접속을 하려면, MySQL 접속이 허용되어있어야 합니다.

일단 접속하자

mysql -uroot -p
  1. 테이블 살펴보기 먼저, mysql에 들어가서 다음 방법을 이용해 접근 상태를 확인합니다.
mysql> use mysql;
mysql> select host, user, password from user;

출력된 정보를 확인해보면, localhost127.0.0.1만 등록이 되어있는 것을 확인 할 수 있는데, 외부에서 접근이 되게 하려면, 따로 등록을 해줘야 합니다.

  1. 권한 설정 하기 설정을 할 때, 특정 IP나 특정 IP대역만 허용을 하거나, 전체를 허용되게 하는 방법이 있습니다.
  1. 특정 IP 접근 허용 설정
mysql> grant all privileges on *.* to ‘root’@‘192.168.56.101’ identified by ‘root의 패스워드’;
  1. 특정 IP 대역 접근 허용 설정
mysql> grant all privileges on *.* to ‘root’@‘192.168.%’ identified by ‘root의 패스워드’;
  1. 모든 IP의 접근 허용 설정
mysql> grant all privileges on *.* to ‘root’@‘%’ identified by ‘root의 패스워드’
  1. 등룩확인 후 적용시키기 등록이 끝났으면, 계정에 설정한 IP혹은 %가 등록 되어있는지 확인을합니다.
mysql> select host, user, password from user;
mysql> flush privileges;
  1. my.cnf에서 외부 접속 관련 내용 변경하기 my.cnf 설정파일에서 bind-address라는 부분을 주석처리 해줍니다.
vi /etc/my.cnf
# bind-address = 127.0.0.1
  1. mysql 재시작 주석처리가 끝났으면, mysql을 재시작 해줍니다.
/etc/init.d/mysqld restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment