1 개요[ | ]
- ERROR 1045 (28000): Access denied for user
- #1045 MySQL 서버에 로그인할 수 없습니다
- MySQL 접근 거부 오류
- 아이디 또는 패스워드가 맞지 않거나, 그 계정에 지정된 접속가능한 대역(Host)이 아닌 경우
2 문제상황[ | ]
2.1 로컬 예시[ | ]
리눅스 셸에서 mysql을 실행하니 Access denied(접근 거부)가 나온다.
Console
Copy
[root@localhost ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
-p
옵션을 붙여 패스워드를 입력하자.
Console
Copy
[root@localhost ~]# mysql -pP@ssw0rd
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 600388
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
2.2 원격접속 예시[ | ]
- 패스워드 안맞음
Console
Copy
[root@zetawiki ~]# mysql -h135.79.246.80 -utestuser -phello
ERROR 1045 (28000): Access denied for user 'testuser'@'135.79.246.80' (using password: YES)
- 패스워드 맞음
Console
Copy
[root@zetawiki ~]# mysql -h135.79.246.80 -utestuser -pP@ssw0rd
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 272691
Server version: 5.0.77-log Source distribution
Copyright (c) 2000, 2011, 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>
3 원인[ | ]
- MySQL 패스워드가 맞지 않는 것
- 그런데... MySQL 패스워드가 맞지 않다는 것은 일반적인 경우[1]와 달리 조금 복잡한 점이 있다.
- 계정과 패스워드가 1:1 관계가 아니기 때문이다.
- MySQL은 같은 이름의 계정이라도, 아래와 같이 접속지에 따라 다른 패스워드를 줄 수 있다.[2]
Console
Copy
mysql> SELECT host, user, password FROM mysql.user WHERE user='root';
+-----------+------+-------------------------------------------+
| Host | User | Password |
+-----------+------+-------------------------------------------+
| localhost | root | *64B2393C4607E57C549B41537134BC7C3314164E |
| myserver1 | root | *64B2393C4607E57C549B41537134BC7C3314164E |
| % | root | *F3A2A51A9B0F2BE2468926B4132313728C250DBF |
+-----------+------+-------------------------------------------+
1 rows in set (0.00 sec)
- → localhost 또는 myserver1에서 접속할 때와, 그 외의 컴퓨터에서 접속할 때 패스워드가 다르게 되어 있다.
4 조치 방법[ | ]
- 로컬호스트에서는 접속이 되는데, 외부에서 접속이 안된다면 MySQL 원격 접속 문서 참고
- 로컬호스트에서도 접속이 안된다면 MySQL root 패스워드 분실 문서 참고