Mysql 비밀번호 분실

yuseon Lim·2021년 8월 17일
0

작업 환경

  • 라즈비안OS
  • MariaDB(Mysql)
    • mysql Ver 15.1 Distrib 10.3.29-MariaDB, for debian-linux-gnueabihf (armv7l) using readline 5.2

MariaDB(Mysql과 별 다름없음) 사용하던 중 비밀번호를 까먹었다.

비밀번호 입력 안했을 경우

mysql -u root

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

비밀번호가 틀렸을 경우

mysql -uroot -p

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

따라서 비밀번호를 재 설정 해야 한다.

  1. mysqld 중지
systemctl stop mysqld
systemctl status mysqld


이때 password는 현재 접속한 user(나는pi)의 비밀번호이다.

(dead) 했다고 뜬다.

  1. Mysql 환경변수 설정
    비밀번호 없이 접속 가능하도록 환경변수를 설정한다.
sudo systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

  1. Mysql 재가동
systemctl start mysqld
mysql -u root -p


  1. 비밀번호를 다시 설정해준다.
mysql> UPDATE mysql.user SET authentication_string = PASSWORD("dufTlagltkfwk2)2)!!") WHERE User = 'root' AND Host = 'localhost';
mysql> FLUSH PRIVILEGES;

  1. mysql을 빠져 나온 후 아까 설정했던 환경변수를 다시 삭제한다.
systemctl stop mysqld
systemctl unset-environment MYSQLD_OPTS
systemctl start mysqld

  1. 잘 설정 되었는지 확인한다.
profile
🔥https://devyuseon.github.io/ 로 이사중 입니다!!!!!🔥

0개의 댓글