mysql5 root 계정 재설정

x·2024년 1월 23일
0

DB

목록 보기
5/7

local에 DB 스키마를 덤프하고 테스트를 하는 중에 root 권한이 이상해져서 특정 테이블에 insert가 안되는 현상이 발생함

root는 grant할 권한이 없다고 뜸

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;

brew로 설치했다면 brew services list로 실행 중인 mysql 확인 후 종료

brew services stop mysql
brew services stop mysql@5.7

cd /opt/homebrew/etc
vi my.cnf

[mysqld] 아래에 skip-grant-tables 작성하고 저장
brew services restart mysql@5.7로 재시작

mysql -u root -p;
flush privileges;

비번 수정
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';

root에 모든 권한 부여
GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' WITH GRANT OPTION;

flush를 안하고 alter user를 하면 ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement 에러가 뜸

/opt/homebrew/etc/my.conf에서 아까 작성한 skip-grant-tables 제거 후 저장
brew services restart mysql@5.7로 재시작

mysql -u root -p;로 로그인 가능

안보이던 DB들이 다시 보임
show databases;

https://stackoverflow.com/questions/41645309/mysql-error-access-denied-for-user-rootlocalhost

0개의 댓글