[翻訳] MySQL - 削除されたパフォーマンス スキーマ データベースの復元

原文地址:https://blog.sqlauthority.com/2021/12/23/mysql-recover-dropped-performance-schema-database/
原文作者:Pinal Dave
登录后复制

今日の初めに、ユーザーが削除されたパフォーマンス スキーマ データベースを回復する方法を探していることをオンライン フォーラムで知りました。
画像.png
正直に言うと、削除したパフォーマンススキーマデータベースを復元するのは非常に簡単で、操作コマンドは次のとおりです:
OS のコマンドラインを開き、次のコマンドを実行します。

mysql_upgrade --user=root --password=password --force
登录后复制

操作が成功したら、MySQL サービスを再起動する必要があります。再起動が完了すると、新しいパフォーマンス スキーマ データベースが作成されます。心配しないでください。データはこの新しいデータベース (翻訳者注: これはパフォーマンス スキーマ データベースを指します) には存在しません。MySQL サービスはパフォーマンス関連のデータを保存するためにのみデータベースを使用します。

翻訳者のメモ

非常に簡単なので、実際の操作を以下に示します。

  1. 削除する前に、performance_schemaが正常かどうかを確認してください
[root@3306][(none)]>>show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bp_metadata        |
| db_gbk             |
| dbaas              |
| ggmgr              |
| mysql              |
| performance_schema |
| pythonDB           |
| sqm                |
| sys                |
| sysbench           |
| ticle              |
| xhy                |
| zoramon            |
+--------------------+
14 rows in set (0.13 sec)
[root@3306][(none)]>>use performance_schema
Database changed
[root@3306][performance_schema]>>show tables;
+------------------------------------------------------+
| Tables_in_performance_schema                         |
+------------------------------------------------------+
| accounts                                             |
| cond_instances                                       |
| events_stages_current                                |
| events_stages_history                                |
| events_stages_history_long                           |
| events_stages_summary_by_account_by_event_name       |
| events_stages_summary_by_host_by_event_name          |
| events_stages_summary_by_thread_by_event_name        |
| events_stages_summary_by_user_by_event_name          |
。。。
[root@3306][performance_schema]>>select count(*) from accounts;
+----------+
| count(*) |
+----------+
|        3 |
+----------+
1 row in set (0.10 sec)

[root@3306][performance_schema]>>select count(*) from threads;
+----------+
| count(*) |
+----------+
|       51 |
+----------+
1 row in set (0.03 sec)

[root@3306][performance_schema]>>show variables like 'datadir';
+---------------+----------------------------+
| Variable_name | Value                      |
+---------------+----------------------------+
| datadir       | /u01/mysql/mysql3306/data/ |
+---------------+----------------------------+
1 row in set (0.18 sec)

登录后复制
  1. 削除をシミュレートします (performance_schema を /tmp に移動します)
[root@ora11g1 ~]# cd  /u01/mysql/mysql3306/data
[root@ora11g1 data]# mv performance_schema /tmp/
[root@ora11g1 data]# ls performance_schema
ls: cannot access performance_schema: No such file or directory
登录后复制
  1. データベース情報を再度確認すると、performance_schema データベースがなくなっています。
[root@3306][(none)]>>show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bp_metadata        |
| db_gbk             |
| dbaas              |
| ggmgr              |
| mysql              |
| pythonDB           |
| sqm                |
| sys                |
| sysbench           |
| ticle              |
| xhy                |
| zoramon            |
+--------------------+
13 rows in set (0.03 sec)

[root@3306][(none)]>>use [performance_schema;
ERROR 1049 (42000): Unknown database '[performance_schema'
登录后复制
  1. リカバリ操作を実行します:
    4.1) アップグレードを実行します: mysql_upgrade --user=root --password=123456 --force
[root@ora11g1 data]#  mysql_upgrade --user=root --password=123456 --force
mysql_upgrade: [Warning] Using a password on the command line interface can be insecure.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv                                 OK
mysql.db                                           OK
mysql.engine_cost                                  OK
mysql.event                                        OK
mysql.func                                         OK
...
zoramon.tbl_tmp_sql_text                           OK
Upgrade process completed successfully.
Checking if update is needed.

登录后复制

4.2) データベースを再起動すると復元が完了します

可以看到即使不重启数据库performance_schema也已经存在了,但查询具体表时提示 1682错误,表结构发生了改变。
[root@3306][(none)]>>show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
...
| mysql              |
| performance_schema |
| pythonDB           |
| sqm                |
| sys                |
| sysbench           |
| ticle              |
| xhy                |
| zoramon            |
+--------------------+
14 rows in set (0.04 sec)

[root@3306][(none)]>>use performance_schema
Database changed
[root@3306][performance_schema]>>show tables;
+------------------------------------------------------+
| Tables_in_performance_schema                         |
+------------------------------------------------------+
| accounts                                             |
| cond_instances                                       |
...
| users                                                |
| variables_by_thread                                  |
+------------------------------------------------------+
87 rows in set (0.00 sec)

[root@3306][performance_schema]>>select count(*) from threads;
ERROR 1682 (HY000): Native table 'performance_schema'.'threads' has the wrong structure

进行重启操作:可以看到已经可以正常查询performance_schema下的表了
[root@3306][performance_schema]>>exit
Bye
(base) [root@ora11g1 ~]# service mysqld restart
Shutting down MySQL....                                    [  OK  ]
Starting MySQL...                                          [  OK  ]
(base) [root@ora11g1 ~]# mysql -uroot -p123456 
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.26-log MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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.

[root@3306][(none)]>>use performance_schema
Database changed
[root@3306][performance_schema]>>select count(*) from threads;
+----------+
| count(*) |
+----------+
|       51 |
+----------+
1 row in set (0.00 sec)

[root@3306][performance_schema]>>

https://www.modb.pro/db/376338 に移動します。

Supongo que te gusta

Origin blog.csdn.net/asd54090/article/details/132841274
Recomendado
Clasificación