반응형

(OS : CentOS 7.x 기준입니다.)

 

MySQL 패스워드 분실시, 우리는 여러가지 방식으로 해결이 가능합니다.

우선, 정석적인(?) 방법으로 먼저 해결해봅시다.


 

DB(MySQL)를 종료합니다. 그 후,  /usr/bin/mysqld_safe 명령어에 --skip-grant-tables & 옵션을 부여해서

DB를 강제로 실행해 봅시다. 그 후, 사용자의 계정 패스워드를 변경해봅시다.

 

####### MySQL 강제 실행 ########

[root@localhost ~]# systemctl stop mysql
[root@localhost ~]# /usr/bin/mysqld_safe --skip-grant-tables &
[root@localhost ~]# /usr/bin/mysql -u root mysql

####### MySQL 버전에 따라 명령어 문법이 다름 #######
MariaDB [(mysql)]> UPDATE USER SET password=password('${passwd}') WHERE USER='root';
MariaDB [(mysql)]> FLUSH privileges;


###### MySQL 재실행 #######

[root@localhost ~]# systemctl start mysql

 


두번째 방법은 OS에 root 권한으로 접속이 가능하며, mysql_history 파일이 생성되고 있을 경우에 가능하다.

아래와 같이 확인이 가능하며, 보안을 위해 생성을 없애고 싶다면 아래와 같이 진행하면 됩니다.

 

########### mysql_history ##########
[root@localhost ~]# view /root/.mysql_history
.....
flush privileges;
alter user 'root'@'localhost' identified by 'daasdfasdgwetg';
show variables like '%datadir%';
show datadir;
show variables like '%datadir%';
set global datadir="/home/";
......


########### mysql_history 삭제 ###########
[root@localhost ~]# rm -rf .mysql_history
[root@localhost ~]# echo "MYSQL_HISTFILE=/dev/null" > /etc/profile
[root@localhost ~]# source /etc/profile
반응형

+ Recent posts