sudo를 실행하지 않으면 MySQL에 액세스할 수 없습니다.

sudo를 실행하지 않으면 MySQL에 액세스할 수 없습니다.

최근에 ARM 시스템(RBPI3)에 MySQL을 설치했고 다음을 실행하면:

pi@raspberrypi:~ $ mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

하지만 sudo를 사용하여 연결할 수 있습니다.

pi@raspberrypi:~ $ sudo mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.1.23-MariaDB-9+deb9u1 Raspbian 9.0

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

내가 su가 아니면 왜 서비스에 접근할 수 없는지 이해가 되지 않습니다. 이는 예를 들어 WWW-DATA 사용자로 실행되는 Nginx로 실행되는 WordPress가 내 데이터베이스에 연결할 수 없음을 의미합니다. 내가 여기서 무엇을 놓치고 있는 걸까요?

답변1

Debian/Ubuntu의 MariaDB는 기본적으로 Unix 소켓을 통해 인증하고 호출 사용자의 유효한 unix 사용자 ID를 확인합니다 mysql. mysql루트로 실행 하지 않거나 sudo를 사용하지 않으면 실패합니다.

https://mariadb.com/kb/en/library/authentication-plugin-unix-socket/

sudo다시 기존 방식으로 변경하려면 ( )를 사용하여 데이터베이스에 로그인한 후 sudo mysql -u root다음과 같이 사용자를 변경하세요.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'test';
FLUSH PRIVILEGES;

관련 정보