ホームページ  >  記事  >  データベース  >  mysqlはrootパスワードをリセットします

mysqlはrootパスワードをリセットします

王林
王林転載
2020-01-22 19:26:032519ブラウズ

mysqlはrootパスワードをリセットします

データベースの場合、root ユーザーのパスワードを忘れると非常に致命的ですが、--ship-grant-tables を追加できます。パラメータを使用して権限テーブルをスキップします。

具体的な方法は次のとおりです:

root パスワードを忘れてデータベースにアクセスできません:

mysqlはrootパスワードをリセットします

現時点では、次のものが必要です。データベースを強制的に停止するには、まず MySQL を確認してください。 プロセス番号

mysqlはrootパスワードをリセットします

MySQL プロセスを強制終了します。コマンドは次のとおりです。

強制終了後、次のことを確認できます。まだプロセスが存在するかどうか

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

mysqlはrootパスワードをリセットします

データベースを停止する操作が業務に影響を及ぼさない場合は、パスワードを記録し、keepassを使用して保存することをお勧めします。パスワードソフト!

無料の学習ビデオ チュートリアルの共有: mysql ビデオ チュートリアル

次に、スキップ許可テーブル パラメーターを追加し、データベースを再起動します。これにより、パスワードを入力しなくてもデータベースにアクセスできるようになります。

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

mysqlはrootパスワードをリセットします

パスワードを入力せずに mysql を直接入力して入力してください。

mysqlはrootパスワードをリセットします

root ユーザーに新しいパスワードを設定し、権限 、MySQL5.7 以降、ライブラリの下のパスワード フィールドは、authentication_string フィールドに置き換えられます。

(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パスワードをリセットします

[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チュートリアル

以上がmysqlはrootパスワードをリセットしますの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はcnblogs.comで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。