mysql root 패스워드 분실시 초기화


서버를 운영하거나 다른 회사에서 의뢰가 들어오는 경우 root 비밀번호를 모를 경우가 많다. 
그래서 root 비밀번호를 초기화 해야하는데 우선 원격 root를 알고 있거나 sudoers 에 계정이 등록된 경우에 한에서 해결 가능하다.


우선 mysql daemon 종료

# /sbin/service mysqld stop 
or
$ sudo /sbin/service mysqld stop


mysql_safe 실행

# /usr/bin/mysqld_safe --skip-grant &
or
$ sudo /usr/bin/mysqld_safe --skip-grant &


mysql 접속

# /usr/bin/mysql -u root mysql
or
$ sudo /usr/bin/mysql -u root mysql


sql문으로 root 비밀번호 변경

mysql> update user set password=password('NEW-PASSWORD') where user='root';


권한이 변경하고 mysql에 즉시 적용

mysql> flush privileges;


mysql을 종료

mysql> quit


mysql daemon 실행

# /sbin/service mysqld start
or
$ sudo /sbin/service mysqld start


MySQL 자동실행 설정

먼저 /usr/local/mysql/share/mysql/mysql.server 파일을 /etc/init.d 디렉토리에 복사한다.

# cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld

다음과 같이 chkconfig 명령어를 이용하여 mysqld 의 자동 실행을 등록한다.

# chkconfig --add mysqld
Apache 자동실행 설정

MySQL 과 같이 /usr/local/apache/bin/apachectl 자동실행 스크립트를 /etc/init.d 디렉토리에 복사한다.

# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

Apache 의 자동 실행 스크립트 파일은 chkconfig 명령어를 이용하여 등록할 수 없다. chkconfig 명령어를 사용하기 위해서 다음과 같은 내용을 스크립트 파일의 주석부분에 추가한다.

# Comments to support chkconfig on RedHat Linux # chkconfig: 2345 90 90 # description: A very fast and reliable WebServer engine.

MySQL 과 같이 chkconfig 명령어를 이용하여 httpd 의 자동 실행을 등록한다.

# chkconfig --add httpd
자동 실행 설정 확인

다음과 같이 chkconfig 명령어를 사용하여 설정사항을 확인할 수 있다.

# chkconfig --list



'개발자 인생 > Linux' 카테고리의 다른 글

Centos 5.X 버젼 Yum 설치 오류 해결  (0) 2018.11.05
보안 인증서 설치 후 HTTPS URL 변경  (0) 2018.08.13