>  기사  >  데이터 베이스  >  mysql 루트 비밀번호 재설정

mysql 루트 비밀번호 재설정

王林
王林앞으로
2020-01-22 19:26:032519검색

mysql 루트 비밀번호 재설정

데이터베이스의 경우 루트 사용자의 비밀번호를 잊어버리면 매우 치명적이지만 --ship-grant-tables 매개변수를 추가하면 권한 테이블을 건너뛸 수 있습니다.

구체적인 방법은 다음과 같습니다.

루트 비밀번호를 잊어버렸고 데이터베이스에 들어갈 수 없습니다.

mysql 루트 비밀번호 재설정

이때 데이터베이스를 강제 종료해야 합니다. 먼저 MySQL 프로세스 번호를 확인하세요

mysql 루트 비밀번호 재설정

MySQL 프로세스를 종료합니다.

Kill 프로세스가 남아 있는지 확인할 수 있습니다.

[root@tse2 tmp]# kill -9 9840 1
[root@tse2 tmp]# ps -ef |grep mysql

mysql 루트 비밀번호 재설정

데이터베이스 중지 작업이 비즈니스에 영향을 미치지 않는 것이 좋습니다. 작업이 중지되면 비밀번호를 기록해 두는 것이 가장 좋습니다. Keepass를 사용하여 비밀번호 소프트웨어를 저장할 수 있습니다!

무료 학습 비디오 튜토리얼 공유: mysql 비디오 튜토리얼

그런 다음 건너뛰기 권한 테이블 매개변수를 추가하고 데이터베이스를 다시 시작합니다. 이렇게 하면 비밀번호를 입력하지 않고도 데이터베이스에 들어갈 수 있습니다.

[root@tse2 bin]# mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables &
[1] 4854

mysql 루트 비밀번호 재설정

비밀번호 없이 mysql을 직접 입력할 수 있습니다

mysql 루트 비밀번호 재설정

루트 사용자에 대한 새 비밀번호를 설정하고 권한을 새로 고칩니다. MySQL5.7 이후에는 라이브러리 아래의 비밀번호 필드가 인증_문자열 필드로 대체됩니다.

(product)root@localhost:mysql.sock [(none)]> use mysql;
Database changed
(product)root@localhost:mysql.sock [mysql]> update user set authentication_string=password('123456') where user='root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 1

(product)root@localhost:mysql.sock [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

설정이 완료된 후 데이터베이스를 다시 시작하세요. 재시작 시 --skip-grant-tables 파라미터를 추가할 필요가 없으므로 정상적으로 서비스를 시작하고 새 비밀번호를 입력하면 데이터베이스가 정상적으로 입력됩니다. 여기서 다시 시작한 후 비밀번호 없이는 mysql에 들어갈 수 없는지 테스트해보겠습니다.

[root@tse2 bin]# mysqld_safe --deaults-file=/etc/my.cnf &
[2] 6720
[root@tse2 bin]# 2020-01-16T02:55:45.223195Z mysqld_safe Logging to '/mysql/mysql3306/logs/error.log'.
2020-01-16T02:55:45.262302Z mysqld_safe A mysqld process already exists

[2]+  Exit 1                  mysqld_safe --deaults-file=/etc/my.cnf
[root@tse2 bin]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

여기에 비밀번호를 입력하면 정상적으로 입력이 가능합니다. 수정된 비밀번호는 123456

mysql 루트 비밀번호 재설정

[root@tse2 bin]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.23-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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.

(product)root@localhost:mysql.sock [(none)]> use mysql
Database changed
(product)root@localhost:mysql.sock [mysql]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
rows in set (0.01 sec)

추천 관련 글과 튜토리얼: mysql tutorial

위 내용은 mysql 루트 비밀번호 재설정의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 cnblogs.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제