[译] MySQL-恢复被删除的Performance Schema 数据库

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

今天早些时候我在一个在线论坛上看到有用户在找如何恢复被删除的Performance Schema 数据库的方法。

老实说,恢复删掉的performance schema数据库非常容易,下面就是操作命令:

打开操作系统命令行,执行如下命令:

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

一旦你的操作成功了,就需要重启MySQL 服务。重启完成,你就有新的Performance Schema 数据库了。不用担心,你的数据是不会存在这个新的数据库的(译者注:这里指Performance Schema 数据库),MySQL服务只是用它来存放性能相关数据。

译者注

既然这么简单,那就给大家实操一把,如下操作:

  1. 删除前检查下performance_schema 是否正常
auto 复制代码
[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下)
auto 复制代码
[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数据库已经不见了
auto 复制代码
[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
auto 复制代码
[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) 重启数据库,恢复完成

auto 复制代码
可以看到即使不重启数据库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

相关推荐
零炻大礼包35 分钟前
【SQL server】数据库远程连接配置
数据库
zmgst44 分钟前
canal1.1.7使用canal-adapter进行mysql同步数据
java·数据库·mysql
令狐少侠201144 分钟前
explain执行计划分析 ref_
mysql
随心............1 小时前
python操作MySQL以及SQL综合案例
数据库·mysql
€☞扫地僧☜€1 小时前
docker 拉取MySQL8.0镜像以及安装
运维·数据库·docker·容器
CopyDragon1 小时前
设置域名跨越访问
数据库·sqlite
xjjeffery1 小时前
MySQL 基础
数据库·mysql
写bug的小屁孩1 小时前
前后端交互接口(三)
运维·服务器·数据库·windows·用户界面·qt6.3
恒辉信达1 小时前
hhdb数据库介绍(8-4)
服务器·数据库·mysql
齐 飞2 小时前
MongoDB笔记01-概念与安装
前端·数据库·笔记·后端·mongodb