Mysql test Connection 오류해결 방법 및 권한부여방법

2021. 9. 14. 11:22데이터베이스

반응형

Host '****' is not allowed to connect to this MySQL server

디비버에서 test 커넥션을 했는데 해당 오류를 발생시켰다.

The MySql service of this machine only allows the machine to visit, and has not opened the access authority to other computers.

 

Enter the cmd window of MySql, and by querying the user table, you can see the current host mode:

mysql> use mysql
Database changed

mysql> select user,host from user;
+-----------+-----------+

| user      | host      |
+-----------+-----------+

| root      | localhost |
| mysql.sys | localhost |
+-----------+-----------+

2 rows in set (0.00 sec)

It can be found that the root user's host=localhost, which means that only the local machine is allowed to visit.

 

Modify through update:

mysql> update user set host='%'where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select user,host from user;
+-----------+-----------+

| user      | host      |
+-----------+-----------+

| root      | %         |
| mysql.sys | localhost |
+-----------+-----------+

2 rows in set (0.00 sec)

Change localhost to %.

Restart the Mysql service

problem solved.

 

출처: <https://www.programmersought.com/article/99975466085/>

 

Mysql 기본 user들에대한 정보가 localhost 지정되어있는걸 % 변경해줬음.(외부접근 가능하도록 변경시킴)

 

# 로컬에서 접속 가능한 사용자 추가하기

create user '사용자'@'localhost' identified by '비밀번호';

 

#로컬 접속 DB 모든 권한 부여하기  (localhost)

# 모든 DB에 권한 부여 

$ grant all privileges on *.* to '사용자'@'localhost';

# 특정 DB에 권한 부여 

$ grant all privileges on DB이름.* to '사용자'@'localhost';

 

#원격지 접속 DB 모든 권한 부여하기  '%', '특정 아이피 ' (remote host)

$ grant all privileges on *.* to '사용자'@'%';

$ grant all privileges on DB이름.* to '사용자'@'%';

 

# 특정 사용자에게 타겟팅된 특정 권한만 부여 하기 

$ grant select, insert, update on test.* to user@'localhost'

 

# 사용자 계정 삭제

$ drop user '사용자'@'localhost';

 

# 변경 내용 저장 

flush privileges; 

 

출처: https://mycup.tistory.com/239 [IT.FARMER]

##변경내용 저장을 반드시 해야한다!!!!

반응형