MySQL root 비밀번호 변경

■ Windows OS에 설치된 mysql서버의 root 계정의 비밀번호 분실시 이를 변경하는 방법을 알아본다. 여기서는 3개의 도스창(명령 프롬프트)가 필요하다. 비인증모드로 mysql서버를 실행시키기 위한 도스창, mysql root 비밀번호를 변경하고 권한 적용하기 위한 도스창, 비인증모드로 실행한 mysql서버를 중지시키기 위한 도스창이 필요하다.

■ 먼저 서비스에서 실행중인 mysql 서버가 있다면 서버를 중지한다.

window mysql root 비밀번호 변경 00

 

서비스에 등록된  mysql 실행파일 경로를 참조하여 비인증모드(–skip-grant)로 mysql 서버를 실행한다. (DOS창은 관리자 모드로 실행해서 열어야 함)

C:\Windows\system32>mysqld --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.6\my.ini" --skip-grant

window mysql root 비밀번호 변경 01 window mysql root 비밀번호 변경 02

 

mysql 명령어를 이용하여 -p옵션없이 mysql 서버에 접속한다(mysql 데이터베이스에 접속). 비인증모드(–skip-grant)로 mysql 서버를 실행하였기 때문에 패스워드를 입력하는 -p 옵션이 없다. mysql 데이터베이스에 접속 후 update 쿼리를 이용해서 root사용자의 비밀번호를 변경한다. 그리고 변경된 root 사용자정보를 권한 적용한다.(flush privileges)

C:\Users\nextman-note>mysql -u root mysql --port 3306 --host localhost
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.21-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> update user set password=password('변경할 비밀번호') where user='root';
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye

C:\Users\nextman-note>

window mysql root 비밀번호 변경 03

 

■ 비밀번호를 변경하기 위해 임시로 시작한 mysql서버를 종료해야 하는데 비밀번호를 변경 후 서버를 종료시에는 아래와 같이 비밀번호를 입력하여야 종료 된다.

C:\Users\nextman-note>mysqladmin -u root shutdown -p
Enter password: *****

C:\Users\nextman-note>

window mysql root 비밀번호 변경 04

 

■ 윈도우 서비스에서 중지한 mysql 서버를 시작하면 mysql root 비밀번호 변경이 완료된다.

window mysql root 비밀번호 변경 05

 

 

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다