리눅스
MySQL에서 사용자의 패스워드를 변경하는 방법
변군이글루
2023. 5. 21. 21:02
반응형
MySQL에서 사용자의 패스워드를 변경하는 방법(5.7/8.0)
MySQL 5.7(5.7.41) 패스워드 변경
1. MySQL 버전 확인
/usr/local/mysql/bin/mysqld --version
/usr/local/mysql/bin/mysqld Ver 5.7.41 for linux-glibc2.12 on x86_64 (MySQL Community Server (GPL))
2. skip-grant-tables 옵션 추가
인증을 우회하기 위해 MySQL 설정 파일에 옵션을 추가합니다.
vim /usr/local/mysql/my.cnf
[mysqld]
...
skip-grant-tables
3. MySQL 서버 실행
/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf --user=mysql &
4. MySQL 접속(패스워드 없이)
/usr/local/mysql/bin/mysql -uroot
5. root 계정 패스워드 변경(MySQL 5.7 방식)
UPDATE mysql.user
SET authentication_string=PASSWORD('P@ssw0rd1!')
WHERE user='root' AND Host='localhost';
FLUSH PRIVILEGES;
- 주의 : MySQL 5.7에서는 ALTER USER 대신 mysql.user 테이블을 직접 수정합니다
6. skip-grant-tables 제거 후 MySQL 재시작
MySQL 종료
/usr/local/mysql/bin/mysqladmin -uroot -p'P@ssw0rd1!' shutdown --socket /tmp/mysql.sock
설정 파일 수정
vim /usr/local/mysql/my.cnf
- skip-grant-tables 삭제 MySQL 재실행
/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf --user=mysql &
7. 변경된 패스워드로 로그인 확인
/usr/local/mysql/bin/mysql -uroot -p'P@ssw0rd1!'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.41 MySQL Community Server (GPL)
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
MySQL 버전 확인
select version();
+-----------+
| version() |
+-----------+
| 5.7.41 |
+-----------+
1 row in set (0.00 sec)
mysql>
728x90
MySQL 8.0(8.0.33) 패스워드 변경
1. MySQL 버전 확인
mysqld --version
/usr/sbin/mysqld Ver 8.0.33 for Linux on x86_64 (MySQL Community Server - GPL)
2. skip-grant-tables 옵션 추가
vim /usr/local/mysql/my.cnf
[mysqld]
...
skip-grant-tables
3. MySQL 서버 실행
mysqld_safe --defaults-file=/etc/mysql/my.cnf --user=mysql &
4. MySQL 접속
mysql -uroot
5. root 계정 패스워드 변경(MySQL 8.0 방식)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'P@ssw0rd1!';
FLUSH PRIVILEGES;
- MySQL 8.0부터는 ALTER USER ... IDENTIFIED BY 방식이 권장/표준입니다.
6. skip-grant-tables 제거 후 MySQL 재시작
MySQL 종료
mysqladmin -uroot -p'P@ssw0rd1!' shutdown --socket /tmp/mysql.sock
설정 파일 수정
vim /etc/mysql/my.cnf
- skip-grant-tables 삭제
MySQL 재실행
mysqld_safe --defaults-file=/etc/mysql/my.cnf --user=mysql &
7. 변경된 패스워드로 로그인 확인
mysql -uroot -p'P@ssw0rd1!'
$ mysql -uroot -p'P@ssw0rd1!'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.33 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
select version();
+-----------+
| version() |
+-----------+
| 8.0.33 |
+-----------+
1 row in set (0.00 sec)
mysql>
MySQL에서는 버전(5.7/8.0)에 따라 사용자 패스워드 변경 방법이 다릅니다.
728x90
반응형