mysql 데이터베이스상에서 root의 패스워드를 변경하는 방법을 소개합니다. 이 포스팅은 root로 로그인 한 상태에서 비밀번호 변경입니다. root의 패스워드를 분실한 경우에 대한 해결책은 되지 못합니다.
MySQL 8.x 이상 버전
구문형식
1
| alter user '사용자계정명'@'localhost' identified with mysql_native_password by '비밀번호';
|
사용 예시
1
| alter user 'root'@'localhost' identified with mysql_native_password by '123qwe!@#';
|
MySQL 5.7 버전 혹은 MariaDB
구문형식
1
| set PASSWORD for '계정명'@'localhost'=PASSWORD('비밀번호');
|
사용 예시
1
| set PASSWORD for 'root'@'localhost'=PASSWORD('123qwe!@#');
|
MySQL 5.6 이하 버전
mysql.user 테이블에 password
컬럼이 있는 경우
구문형식
1
| update mysql.user set password=password('비밀번호') where user='계정명';
|
사용예시
1
| update mysql.user set password=password('123qwe!@#') where user='root';
|
mysql.user 테이블에 password
컬럼이 없는 경우
구문형식
1
| update mysql.user set authentication_string=password('비밀번호') where user='계정명';
|
사용예시
1
| update mysql.user set authentication_string=password('123qwe!@#') where user='root';
|
변경사항 저장