Database

Mysql root로 사용자 계정 권한부여시 오류 발생 해결방법

nickbegain 2021. 6. 17. 15:15

내용

mysql에서 root로 접속

PS C:\Users\user> mysql -u root -p

Enter password: <비밀번호>

 

사용자 user1에게 test_db에 대한 권한 부여 시도

mysql> grant all privileges on test_db.* to user1@locahost;

ERROR 1410 (42000): You are not allowed to create a user with GRANT

 

해결법

 

외부 접근 권한이 있는 root 유저 생성 후 확인

mysql> create user 'root'@'%' identified by 'asdf';

mysql> use mysql; --> mysql 데이터베이스에 접속

mysql> select host, user from user;

+-----------+------------------+

| host             | user                       |

+-----------+------------------+

| %                 | root                        |

| 127.0.0.1      | root                        |

| localhost     | user1                     |

+-----------+------------------+

 

 

(정상작동하기도 하고 안되기도함) --> 한번 권한이 부여되면 이후에는 잘 작동함

mysql> grant all privileges on test_db.* to jsh@locahost;

 

(정상적으로 사용자계정에게 권한을 부여하는 쿼리문)

mysql> grant all on testdb.* to jsh@localhost;

 

원하는 사용자에게 권한 부여 후 'root'@'%' 삭제

mysql> drop user 'root'@'%';

 

권한 부여 잘 됐는지 확인

mysql> show grants for user1@localhost;

+------------------------------------------------------------+

| Grants for user1@localhost                                                          |

+------------------------------------------------------------+

| GRANT USAGE ON *.* TO `user1`@`localhost`                        |

| GRANT ALL PRIVILEGES ON `test_db`.* TO `user1`@`localhost` |

+------------------------------------------------------------+

 

출처 : https://velog.io/@inhalin/MySQL-ERROR-1410-42000