데이터베이스

<MySql> Can't connect to MySQL server 'server.ip' (10060)

xxvigrufv 2022. 10. 3. 14:48
반응형

환경: Mariadb 10.2.44
서버환경: Ubuntu 20.04 LTS
원격 위치에서 서버의 MySQL 서비스에 접속하려고 하면 클라이언트는 다음과 같은 오류를 반환한다.

연결하려는 시스템의 서비스와 연결할 수 없는 경우 MySQL 클라이언트에서 오류 10060을 반환한다. 
이는 일반적으로 연결을 방해하는 방화벽 차단 또는 네트워크 문제로 인해 발생한다.

MySQL 설치 후 외부에서 접속하기 위해 접근 허용 IP를 등록하는 방법이다.

***MySQL Database 설정  
> 권한확인   
- 처음 설치 후 로컬에서 접속하여 권한을 확인해보면 localhost 또는 127.0.0.1만 등록되어 있다.

MariaDB [(none)]> use mysql;
Database changed
MariaDB [mysql]> select host, user from user;
+-----------+------+
| host      | user |
+-----------+------+
| %         | root |
| 127.0.0.1 | root |
| ::1       | root |
| localhost |      |
| localhost | root |
| softcamp  |      |
| softcamp  | root |
+-----------+------+
7 rows in set (0.00 sec)



> 권한설정   
- 아래는 모든 db에 all privileges(모든 권한)을 부여하는 쿼리.  
- 특정 IP 접근 허용 

MariaDB [mysql]> grant all privileges on *.* to ‘root’@‘192.168.1.2’ identified by ‘패스워드’;


- 특정 IP 대역 접근 허용 

MariaDB [mysql]> grant all privileges on *.* to ‘root’@‘192.168.1.%’ identified by ‘패스워드’;


- 모든 IP 접근 허용 

MariaDB [mysql]> grant all privileges on *.* to ‘root’@‘%’ identified by ‘패스워드’;



> 권한변경   
- 권한을 부여한 IP 정보를 수정합니다. 

MariaDB [mysql]> update user set host = '192.168.1.2' where user ='root' and host='192.168.1.%'; 
MariaDB [mysql]> flush privileges;



> 설정적용
- 접속을 허용하려는 IP에 대한 권한 설정을 적용합니다.

MariaDB [mysql]> flush privileges;



> 권한제거   
- 특정 IP 접근 허용 제거

MariaDB [mysql]> delete from mysql.user where host=’192.168.1.2′ AND User=’root’;


- 특정 IP 대역 접근 허용 제거 

MariaDB [mysql]> delete from mysql.user where host=’192.168.1.%′ AND User=’root’;


- 모든 IP 접근 허용 제거 

MariaDB [mysql]> delete from mysql.user where host=’%’ AND User=’root’;


> 설정 적용   - 접속을 허용하려는 IP에 대한 권한을 확인 후 설정을 적용합니다.

MariaDB [mysql]> select host, user from user; mysql> flush privileges;



> mysql 재시작 

# /etc/init.d/mysqld restart
반응형