Development/MySQL
MySQL 외부 인터넷에서 접속하도록 설정
Bryan_
2017. 1. 19. 14:08
반응형
Tested OS: Ubuntu 14.04 또는 Ubuntu 16.04
MySQL version: 5.5~5.7
설정 파일(my.cnf)과 mysql 콘솔에서의 설정 두 가지를 적용하면 된다.
/etc/mysql/my.cnf 또는 /etc/mysql/mysql.conf.d/mysqld.cnf 파일에서
bind-address에 원래 127.0.0.1로 되어 있는 것을 0.0.0.0으로 바꾼다.
bind-address = 0.0.0.0
참고로, root 계정을 외부에서 접속할 수 있게 만드는 것은 그다지 좋은 방법이 아니다. 따라서 외부 접속용 계정을 따로 만들고, 그 계정이 특정 데이터베이스에만 접근할 수 있도록 설정해 주는 것이 좋다.
*DB 생성
mysql> create database testdb;
*사용자 생성
mysql> create user 'testuser'@'%' identified by 'testpassword';
*생성한 사용자의 접근 권한 설정
- 로컬 접속:
mysql> grant all privileges on testdb.* to 'testuser'@localhost identified by 'testpassword';
- 외부 접속:
mysql> grant all privileges on testdb.* to 'testuser'@'%' identified by 'testpassword';
MySQL 서비스 재시작:
$ sudo service mysql restart
반응형