Linux

Docker 환경에서 MySQL 로그인시 Access denied for user... Error 해결하기

mark340 2023. 3. 2. 00:22

Docker 환경에 설치한 MySQL에 계정을 생성할때 도메인을 일반적인 localhost로 지정하면 에러가 발생한다.

그렇기 때문에 에러 메세지에 나오는 Docker 가상 IP로 지정을 해서 계정을 생성해야 한다.

 

1. MySQL 콘솔 접속하기

$ docker exec -it <CONTAINER_ID>  mysql -uroot -p

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 360
Server version: 8.0.21 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

 

 

2. 계정 생성 및 권한 부여

mysql> CREATE USER 'account_name'@'172.17.0.1' IDENTIFIED BY 'password';

mysql> GRANT ALL PRIVILEGES ON *.* TO 'account_name'@'172.17.0.1' WITH GRANT OPTION;

 

 

3. 계정 적용

mysql> flush privileges; 

#MySQL 콘솔화면 종료하기
mysql> exit

 

 

4. MySQL WorkBench 접속하기

서버 접속 정보를 생성하여 접속하시면 로그인 성공 되는걸 볼수 있습니다.

(Server Name은 localhost를 입력하시면 됩니다.)