mysql 비밀번호 입력하지 않고 root 계정으로 접속 하기
CentOS에서 mysql root 비밀번호를 잃어버릴때가 있습니다. 그럴 경우 일반적으로 mysqld_safe 명령어를 이용하여 root 비밀번호를 변경합니다. 그러나 상위버전의 mysql의 경우 mysqld_safe 파일이 없습니다. 그러므로 mysqld_safe 명령이 존재하지 않을 때 root 비밀번호를 변경하는 방법에 대해서 알아보겠습니다.
- SSH를 이용하여 root 게정으로 서버에 로그인을 합니다.
2. mysqld 서버를 중지합니다.
[root@localhost /] systemctl stop mysqld
3. mysql 서버에 –skip-grant-tables 옵션을 설정해 줍니다.
[root@localhost /] systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
4. mysqld 서버를 시작합니다.
[root@localhost /] systemctl start mysqld
5. root 사용자로 mysql 서버에 접속을 합니다.
[root@localhost /] mysql
6. root 비밀번호를 변경합니다. flush 적용
mysql> update user set authentication_string=PASSWORD('비밀번호') where user='root';
mysql> flush privileges;
7. mysql 접속을 빠져나온 후 mysqld 서버를 중지합니다.
[root@localhost /] systemctl stop mysqld
8. mysql 서버에 unset-environment MYSQLD_OPTS 옵션을 설정해 줍니다.
[root@localhost /] systemctl unset-environment MYSQLD_OPTS
9. mysqld 서버를 시작합니다.
[root@localhost /] systemctl start mysqld