1.管理者ユーザーのパスワードを忘れましたか?PS:一般的に忘れません(>﹏< )
[root@centos7-db01 ~]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
データベースダウン2.シャット
[root@centos7-db01 ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@centos7-db01 ~]# systemctl stop mysqld
[root@centos7-db01 ~]# systemctl is-active mysqld
inactive
PS:使用SYS-Vモードは、データベースサービスを管理することができます。
データベースのメンテナンスモードを有効にする3。
[root@centos7-db01 ~]# mysqld_safe --skip-grant-tables --skip-networking &
[1] 2268
[root@centos7-db01 ~]# ps -ef|grep [m]ysqld_safe
root 2268 1429 0 17:39 pts/0 00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --skip-grant-tables --skip-networking
PS:パラメータビューのmysqld --verbose --help | egrepの「スキップ・助成金・テーブル|スキップ・ネットワーキング」。
説明:
--skip-グラント-テーブル:スキップ権限テーブル
--skip-ネットワーキング:スキップのtelnet
4.ログインし、パスワードを変更
モード1:
[root@centos7-db01 ~]# mysql
mysql> alter user root@'localhost' identified by '123';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> flush privileges;
mysql> alter user root@'localhost' identified by '123';
Query OK, 0 rows affected (0.00 sec)
PS:フラッシュ権限;ロード承認フォーム許可管理者は、ユーザーのパスワードを変更する権限を持っています。
オプション2:
[root@centos7-db01 ~]# mysql
mysql> update mysql.user set authentication_string=password('123') where user='root' and host='localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
PS:MySQL5.7バージョンauthentication_stringストアユーザーのパスワードフィールド。
5.閉じるデータベース、通常の起動認証
[root@centos7-db01 ~]# pkill mysql
[root@centos7-db01 data]# systemctl start mysqld
#忽略授权表登录失败
[root@centos7-db01 data]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
#输入原密码登录失败
[root@centos7-db01 data]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
#正常登录
[root@centos7-db01 ~]# mysql -uroot -p123 -e 'show processlist;'
mysql: [Warning] Using a password on the command line interface can be insecure.
+----+------+-----------+------+---------+------+----------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+----------+------------------+
| 5 | root | localhost | NULL | Query | 0 | starting | show processlist |
+----+------+-----------+------+---------+------+----------+------------------+