1. 발생 계기
백엔드의 서버 데이터를 mysql 로 하기 위해 작업중이었고 node.js 환경에서 작업하다보니 sequelize 를 통한 작업이 이뤄지고 있었다. 대략적인 데이터 표는 완성이 되어, sequelize 와 mysql 을 동기화 할 필요가 있기에 npx sequelize db:create 명령어를 입력했는데 에러가 발생하였고, 우선 mysql 의 서버를 키고, 이후 workbench 에서 Test connection 을 해보는 도중 오류가 발생하였다.
2. 탐구해본 원인
예전에 mysql 을 사용해본적이 있는데, 아마 그때 설정했던 비밀번호와 백엔드 서버 내 비밀번호가 달라서 발생한 문제가 아닌가 싶어서 기존 mysql 비밀번호를 찾아야 겠다는 생각이 들었다.
3. 해결 과정
문제는 여기서부터 시작하는데... 우선 mysql 을 실행하려고 하는데 맙소사... 비밀번호를 까먹었다. 우선 기존 mysql 의 비밀번호를 초기화 하고 새로운 비밀번호를 설정해 주어야 겠다고 생각했다.
mysql.server start --skip-grant-tables
우선 서버를 껐다 키는데, 킬 때 root 인증없이 MySql 에 접근할 수 있도록 조치를 해두자.
mysql -u root
update mysql.user set authentication_string=null where user='root';
주의할 점이 있는데, 쉼표 잊지말자... 이것때문에 더 빨리끝날것도 계속 시간끌려서 해맸음..(mysql 은 거진 사용해본적이 없어서)
여하튼 위처럼 기존의 비밀번호를 null 로 변경한 뒤
flush privilegs;
위 설정을 해준다.
이후 재 시작을 한 뒤 비밀번호를 변경하면 된다.
EXIT;
mysql.server restart;
참고로 mysql 에 들어왔으니 당연히 다시 나간 뒤에, 서버를 종료시켜주자
mysql - u root;
alter user 'root'@'localhost' identified with caching_sha2_password by '변경 비밀번호';
위 비밀번호는 우리가 입력한 비밀번호를 암호화 하여 저장한다. 여하튼 이렇게 비밀번호까지 저장하였고,
EXIT;
mysql.server restart;
mysql -u root -p;
이렇게 입력할 시 비밀번호 입력창이 뜨고, 바뀐 비밀번호로 들어가면 잘 들어가진다!!
이제 바뀐 비밀번호를 통해 workbench 를 다시 비밀번호 치고 들어가면 잘 들어가진다.
다시 서버 코드로 돌아와 시퀄라이즈와 mysql 을 연결시켜주어야 했고, 그 작업을 하던 도중 또 다시 같은 문제가 발생을 하였다?..
패스워드에 문제라면, mysql workbench 는 잘 들어가지고 있으니 mysql 의 문제는 아닌것 같고, 그럼 코드 상에서 비밀번호... 라고 생각을 하다가 문득, config.json 파일이 떠올라서 확인해보니 다른 비밀번호로 되어있었다. 이를 수정해주자.
이후 다시 npx sequelize db:create (시퀄라이즈와 mysql 동기화 과정) 을 입력해주니
다행이 잘 작동하였다!
참조
https://velog.io/@kimtaeeeny/mysql-%EB%AA%85%EB%A0%B9%EC%96%B4-%EB%AA%A8%EC%9D%8C
'Programing > Error' 카테고리의 다른 글
[ERROR]MySql root 비밀번호 설정 시 에러 (0) | 2023.01.05 |
---|---|
Error : MySQL Sequelize 사용 중 Models 관련 오류 (0) | 2022.11.23 |
Error : because it would overwrite input file (0) | 2022.11.12 |
Error: Invalid Hook Call Warning (1) | 2022.10.29 |
Error: ERESOLVE unable to resolve dependency tree (1) | 2022.10.29 |