"MySQL root 패스워드 분실"의 두 판 사이의 차이

잔글 (211.36.134.168(토론)의 편집을 Jmnote bot의 마지막 판으로 되돌림)
잔글 (봇: 자동으로 텍스트 교체 (-<source lang='cli'> +<source lang='console'>))
6번째 줄: 6번째 줄:


==mysqld 중지==
==mysqld 중지==
<source lang='cli'>
<source lang='console'>
[root@localhost ~]# service mysqld stop
[root@localhost ~]# service mysqld stop
Stopping MySQL:                                            [  OK  ]
Stopping MySQL:                                            [  OK  ]
12번째 줄: 12번째 줄:


==mysqld_safe 실행==
==mysqld_safe 실행==
<source lang='cli'>
<source lang='console'>
[root@localhost ~]# /usr/bin/mysqld_safe --skip-grant &
[root@localhost ~]# /usr/bin/mysqld_safe --skip-grant &
[1] 32055
[1] 32055
32번째 줄: 32번째 줄:


;실행 예시
;실행 예시
<source lang='cli'>
<source lang='console'>
[root@localhost ~]# /usr/bin/mysql -uroot mysql
[root@localhost ~]# /usr/bin/mysql -uroot mysql
Reading table information for completion of table and column names
Reading table information for completion of table and column names
56번째 줄: 56번째 줄:
==mysqld 재시작==
==mysqld 재시작==
이제 패스워드를 입력해야만 mysql을 사용할 수 있도록 하기 위해, mysqld를 재시작한다.
이제 패스워드를 입력해야만 mysql을 사용할 수 있도록 하기 위해, mysqld를 재시작한다.
<source lang='cli'>
<source lang='console'>
[root@localhost ~]# service mysqld restart
[root@localhost ~]# service mysqld restart
STOPPING server from pid file /var/run/mysqld/mysqld.pid
STOPPING server from pid file /var/run/mysqld/mysqld.pid

2016년 3월 29일 (화) 10:40 판

MySQL 초기 패스워드 지정
MySQL root 패스워드 분실
MySQL root 패스워드 초기화
MySQL root 패스워드 재설정

1 mysqld 중지

[root@localhost ~]# service mysqld stop
Stopping MySQL:                                            [  OK  ]

2 mysqld_safe 실행

[root@localhost ~]# /usr/bin/mysqld_safe --skip-grant &
[1] 32055
Starting mysqld daemon with databases from /var/lib/mysql

→ 이제 패스워드 없이 mysql에 접속할 수 있게 되었다.[1]

3 새 패스워드 지정

mysql 콘솔로 들어가자.[2]

/usr/bin/mysql -uroot mysql

다음 SQL 명령어를 입력하여 원하는 패스워드로 변경한다.

update user set password=password('패스워드') where user='root'; 
flush privileges; 
quit
실행 예시
[root@localhost ~]# /usr/bin/mysql -uroot mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> update user set password=password('P@ssw0rd') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

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

mysql> quit
Bye

4 mysqld 재시작

이제 패스워드를 입력해야만 mysql을 사용할 수 있도록 하기 위해, mysqld를 재시작한다.

[root@localhost ~]# service mysqld restart
STOPPING server from pid file /var/run/mysqld/mysqld.pid
120229 13:08:54  mysqld ended

Stopping MySQL:                                            [  OK  ]
Starting MySQL:                                            [  OK  ]
[1]+  Done                    /usr/bin/mysqld_safe --skip-grant
→ 백그라운드로 실행 중이던 무인증 안전모드 mysqld 프로세스가 중지되고 정상모드 mysqld로 재시작되었다.

5 같이 보기

6 주석

  1. 로컬에서는 인증 없이 mysql의 root 권한을 사용가능하게 됨
  2. ERROR 1049 (42000): Unknown database 'mysql' 라고 나오면서 안들어 가지는 경우가 있을 수 있는데, mysql 설치 이후 한번도 root 패스워드를 지정하지 않은 상태이다. 이 때는 본 문서를 따르지 말고 service mysqld restart한다. 그러면 mysqladmin을 통한 패스워드 설정 방법이 나올 것이다.

7 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}