최신판 |
당신의 편집 |
1번째 줄: |
1번째 줄: |
| {{테스트|리눅스, MySQL 5.0.77}}
| |
| ;MySQL 초기 패스워드 지정
| |
| ;MySQL root 패스워드 분실
| |
| ;MySQL root 패스워드 초기화
| |
| ;MySQL root 패스워드 재설정
| |
|
| |
|
| ==mysqld 중지== | | ==mysqld 중지== |
| <source lang='bash'> | | <source lang='dos'> |
| systemctl stop mysqld # CentOS
| | [root@localhost ~]# service mysqld stop |
| systemctl stop mysql # Ubuntu
| | Stopping MySQL: [ OK ] |
| </source>
| |
| <source lang='console'>
| |
| [root@localhost ~]# systemctl stop mysqld | |
| [root@localhost ~]# | |
| </source> | | </source> |
|
| |
|
| ==mysqld_safe 실행== | | ==mysqld_safe 실행== |
| * 인증 생략 옵션 + 안전모드로 데몬 실행
| | ;위치 확인 |
| <source lang='bash'> | | <source lang='dos'> |
| /usr/bin/mysqld_safe --skip-grant &
| | [root@localhost ~]# which mysqld_safe |
| /usr/bin/mysqld_safe --skip-grant-tables & | | /usr/bin/mysqld_safe |
| </source> | | </source> |
| <source lang='console'> | | ;실행 |
| [root@localhost ~]# /usr/bin/mysqld_safe --skip-grant-tables & | | <source lang='dos'> |
| | [root@localhost ~]# /usr/bin/mysqld_safe --skip-grant & |
| [1] 32055 | | [1] 32055 |
| Starting mysqld daemon with databases from /var/lib/mysql | | Starting mysqld daemon with databases from /var/lib/mysql |
| </source> | | </source> |
| → 이제 패스워드 없이 mysql에 접속할 수 있게 되었다.<ref>로컬에서는 인증 없이 mysql의 root 권한을 사용가능하게 됨</ref> | | → 이제 패스워드 없이 mysql에 접속할 수 있게 되었다. |
|
| |
|
| ==새 패스워드 지정== | | ==새 패스워드 지정== |
| mysql 콘솔로 들어가자.<ref>ERROR 1049 (42000): Unknown database 'mysql' 라고 나오면서 안들어 가지는 경우가 있을 수 있는데, mysql 설치 이후 한번도 root 패스워드를 지정하지 않은 상태이다. 이 때는 본 문서를 따르지 말고 <code>service mysqld restart</code>한다. 그러면 mysqladmin을 통한 패스워드 설정 방법이 나올 것이다.</ref> | | mysql 콘솔로 들어가자. |
| <source lang='bash'> | | <source lang='bash'> |
| /usr/bin/mysql -u root mysql | | /usr/bin/mysql -u root mysql |
| </source> | | </source> |
| 다음 SQL 명령어를 입력하여 원하는 패스워드로 변경한다. | | 다음 SQL 명령어를 입력하여 원하는 패스워드로 변경한다. |
| {{소스헤더|MySQL 5.7.6 이상}}
| | <source lang='sql'> |
| <source lang='mysql'>
| | update user set password=password('패스워드') where user='root'; |
| ALTER USER 'root'@'localhost' IDENTIFIED BY '패스워드';
| | flush privileges; |
| </source>
| | quit |
| {{소스헤더|MySQL 5.7.5 이하}}
| |
| <source lang='mysql'>
| |
| -- MySQL 5.6에서 성공 ★
| |
| SET PASSWORD FOR 'root'@'localhost' = PASSWORD('패스워드');
| |
| </source>
| |
| <source lang='mysql'> | |
| -- MySQL 5.7 이상
| |
| UPDATE mysql.user SET authentication_string=PASSWORD('패스워드') WHERE user='root' AND Host='localhost';
| |
| FLUSH PRIVILEGES;
| |
| </source>
| |
| <source lang='mysql'>
| |
| -- MySQL 5.7 미만
| |
| UPDATE mysql.user SET password=PASSWORD('패스워드') WHERE user='root' AND Host='localhost';
| |
| FLUSH PRIVILEGES;
| |
| </source> | | </source> |
|
| |
|
| |
|
| ;실행 예시 | | ;실행 예시 |
| <source lang='console'> | | <source lang='dos'> |
| [root@localhost ~]# /usr/bin/mysql -uroot mysql | | [root@localhost ~]# /usr/bin/mysql -u root mysql |
| Reading table information for completion of table and column names | | Reading table information for completion of table and column names |
| You can turn off this feature to get a quicker startup with -A | | You can turn off this feature to get a quicker startup with -A |
78번째 줄: |
55번째 줄: |
| </source> | | </source> |
|
| |
|
| ==mysqld 재시작==
| | ==참고 자료== |
| 이제 패스워드를 입력해야만 mysql을 사용할 수 있도록 하기 위해, mysqld를 재시작한다.
| |
| <source lang='bash'>
| |
| systemctl restart mysqld # CentOS
| |
| systemctl restart mysql # Ubuntu
| |
| </source>
| |
| <source lang='console'>
| |
| [root@localhost ~]# systemctl restart mysqld
| |
| [root@localhost ~]#
| |
| [1]+ Done /usr/bin/mysqld_safe --skip-grant
| |
| </source>
| |
| :→ 백그라운드로 실행 중이던 무인증 안전모드 mysqld 프로세스가 중지되고 정상모드 mysqld로 재시작되었다.
| |
| | |
| ==같이 보기==
| |
| *[[MySQL 패스워드 변경]]
| |
| *[[셸에서 MySQL 접근 거부]]
| |
| *[[MySQL 패스워드 초기설정 실패]]
| |
| | |
| ==참고== | |
| * https://www.cyberciti.biz/faq/mysql-change-user-password/
| |
| *http://oparrow.tistory.com/entry/MySQL-root-password-%EC%9E%8A%EC%96%B4%EB%B2%84%EB%A0%B8%EC%9D%84%EB%95%8C | | *http://oparrow.tistory.com/entry/MySQL-root-password-%EC%9E%8A%EC%96%B4%EB%B2%84%EB%A0%B8%EC%9D%84%EB%95%8C |
|
| |
|
| <!--
| |
| [[/usr/bin/mysqld_safe 없이 systemctl로 MySQL 패스워드 재설정]]라는
| |
| 문서로 따로 만들면 어떨까요?
| |
|
| |
| === centos 7 & mysql 5.7 환경에서 /usr/bin/mysqld_safe 을 찾을 수 없는 경우 ===
| |
| systemctl 을 활용하여 리셋 하는 방법이 있음.
| |
| <source>
| |
| 1. Stop mysql:
| |
| systemctl stop mysqld
| |
|
| |
| 2. Set the mySQL environment option
| |
| systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
| |
|
| |
| 3. Start mysql usig the options you just set
| |
| systemctl start mysqld
| |
|
| |
| 4. Login as root
| |
| mysql -u root
| |
|
| |
| 5. Update the root user password with these mysql commands
| |
| mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
| |
| mysql> FLUSH PRIVILEGES;
| |
| mysql> quit
| |
|
| |
| 6. Stop mysql
| |
| systemctl stop mysqld
| |
| 7. Unset the mySQL envitroment option so it starts normally next time
| |
| systemctl unset-environment MYSQLD_OPTS
| |
| 8. Start mysql normally:
| |
| systemctl start mysqld
| |
| Try to login using your new password:
| |
| 7. mysql -u root -p
| |
|
| |
| </source>
| |
| 출처: <https://stackoverflow.com/questions/33510184/change-mysql-root-password-on-centos7>
| |
| -->
| |
| [[분류: 패스워드]] | | [[분류: 패스워드]] |
| [[분류: MySQL]] | | [[분류: MySQL]] |