반응형

사용자 환경 : macOS Sierra 10.12.65.7.20 MySQL Community Server (GPL)






안드로이드로 MySQL에 관한 개발을 하던 도중 다음과 같은 에러가 발생했다.



mysqli_connect(): (HY000/2002): No such file or directory in (중략)



열심히 구글링을 했었고, 여러 해결 방법이 나와 있었다. 기본적으로 서버가 안켜져있는 경우에 발생한다고 한다.



하지만, 서버는 너무나 잘 켜져있었다. 맥북을 한 번 밀고 다시 개발환경 세팅한 거라 환경 설정이 다 안되었다고 판단하고 예전 기억을 떠올렸다.



분명 소켓에 관한 설정을 했던 것 같아 다시 구글링을 해서 해결 했다. 해결 방법은 다음과 같다.





우선 터미널을 열고 폴더 하나를 만든다.

$> sudo mkdir /var/mysql




다음, 소켓에 대한 심볼릭 링크를 지정한다.

$> sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock




다시 앱을 실행한 결과, 에러가 사라졌다.





또 하나 임시 해결 방안이 있다.



php 파일에서 다음 localhost를 127.0.0.1로 변경하면 소켓 설정 없이 해결할 수 있었다.


$conn=mysqli_connect('localhost', 'root', 'PASSWORD', 'DATABASE');





반응형
반응형


사용자 환경 : macOS Sierra 10.12.65.7.20 MySQL Community Server (GPL)





MySQL에 접속을 시도하다 보면 다음과 같은 에러문을 쉽게 볼 수 있을 것이다.

$> /usr/local/mysql/bin/mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
$> /usr/local/mysql/bin/mysql -uroot -p잘못된비밀번호
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
위에 두 에러의 차이점을 보자면, 마지막 단어인 using password: 부분이 각각 YES, NO로 되어있다.



그럼 두 에러를 하나씩 살펴보자.



$> /usr/local/mysql/bin/mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
위 에러는 비밀번호를 입력하지 않았을 경우 나타는 에러이다.
-p 옵션을 사용하여 옳바른 비밀번호를 입력하면 된다.



$> /usr/local/mysql/bin/mysql -uroot -p잘못된비밀번호
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

위 에러는 -p 옵션을 사용하여 비밀번호를 입력했지만, 옳바르지 않은 비밀번호를 입력했을 경우 나타는 에러이다.

옳바른 비밀번호를 입력 시 다음과 같은 화면이 출력된다.

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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>


반응형

+ Recent posts