mysqli_connect(): no such file or directory 에러 해결
위와 같은 오류가 떴음.
방법1: 재설치... (실패)
brew services stop mysql
brew uninstall mysql
which mysql
=> /opt/homebrew/bin/mysql
rm -rf /opt/homebrew/var/mysql
rm -rf /opt/homebrew/etc/my.cnf
이래도 안 됐다ㅜ
방법2: localhost -> 127.0.0.1 로 변경 (성공)
Warning: mysqli_connect(): (HY000/2002): No such file or directory
I'm trying to install vanilla forums on my Mac, and for this I just created a database and a user from the MySQL command line: mysql> CREATE DATABASE vanilla; Query OK, 1 row affected (0.00 sec)
stackoverflow.com
위 답변을 참고해서 한번 localhost 부분을 바꿔보기로 했다.
$conn = mysqli_connect( 'localhost, 'root', '1234', 'opentutorials');
이 부분을
$conn = mysqli_connect( '127.0.0.1', 'root', '1234', 'opentutorials');
이렇게 바꿔주었다.
그랬더니
mysqli_connect: authentication method unknown to the client [caching_sha2_password]
이런 오류가 떴고...
mysql -u root -p;
alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'root 비밀번호';
flush privileges;
이렇게 비밀번호 설정을 변경해주니 잘 해결됐다.
그런데 이 방법은 조금 찜찜했다. 127.0.0.1로는 되는데 localhost로는 안 된다..?? 는 문제가 여전히 남아있기 때문이다.
일단 이 케이스는 해결이 됐지만, 앞으로도 localhost로 뭔가를 하려고 하면 계속 안 될 것 같았다.
내 로컬에서 127.0.0.1과 localhost를 연결시켜주는 설정이 빠져있는 느낌이 들었다.
방법을 찾아보니 역시나 이 방법은 임시방편 같은 것이었고 socket 설정을 해주는 방법이 따로 있었다.
방법3: 소켓 설정 (성공)
https://bestcoding.tistory.com/17
[Solution] Warning: mysql_connect(): [2002] No such file or directory 해결하기
사용자 환경 : macOS Sierra 10.12.6, 5.7.20 MySQL Community Server (GPL) 안드로이드로 MySQL에 관한 개발을 하던 도중 다음과 같은 에러가 발생했다. mysqli_connect(): (HY000/2002): No such file or dire..
bestcoding.tistory.com
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock