原文地址:https://blog.sqlauthority.com/2021/12/23/mysql-recover-dropped-performance-schema-database/ 原文作者:Pinal Dave
复制
今天早些时候我在一个在线论坛上看到有用户在找如何恢复被删除的Performance Schema 数据库的方法。
老实说,恢复删掉的performance schema数据库非常容易,下面就是操作命令:
打开操作系统命令行,执行如下命令:
mysql_upgrade --user=root --password=password --force
复制
一旦你的操作成功了,就需要重启MySQL 服务。重启完成,你就有新的Performance Schema 数据库了。不用担心,你的数据是不会存在这个新的数据库的(译者注:这里指Performance Schema 数据库),MySQL服务只是用它来存放性能相关数据。
译者注
既然这么简单,那就给大家实操一把,如下操作:
- 删除前检查下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)
复制
- 模拟删除(将移动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
复制
- 再次查看数据库信息,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'
复制
- 进行恢复操作:
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]>>
复制
最后修改时间:2022-03-16 09:19:42
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
走不出自己的执念,到哪都是囚徒,人生本过客,何必千千结。
1年前

评论
您好,您已成功参与“墨力翻译计划”,有机会入选“月度最佳译文”🏆
💪加油,辛勤译者、月度翻译官等你角逐!
3年前

评论
相关阅读
【MySQL 30周年庆】MySQL 8.0 OCP考试限时免费!教你免费领考券
墨天轮小教习
2926次阅读
2025-04-25 18:53:11
MySQL 30 周年庆!MySQL 8.4 认证免费考!这次是认真的。。。
严少安
845次阅读
2025-04-25 15:30:58
【活动】分享你的压箱底干货文档,三篇解锁进阶奖励!
墨天轮编辑部
491次阅读
2025-04-17 17:02:24
MySQL 9.3 正式 GA,我却大失所望,新特性亮点与隐忧并存?
JiekeXu
429次阅读
2025-04-15 23:49:58
3月“墨力原创作者计划”获奖名单公布
墨天轮编辑部
372次阅读
2025-04-15 14:48:05
MySQL 8.0 OCP 1Z0-908 考试解析指南(二)
JiekeXu
284次阅读
2025-04-30 17:37:37
记录MySQL数据库的一些奇怪的迁移需求!
陈举超
276次阅读
2025-04-15 15:27:53
SQL优化 - explain查看SQL执行计划(下)
金同学
264次阅读
2025-05-06 14:40:00
MySQL 8.0 OCP 1Z0-908 考试题解析指南
青年数据库学习互助会
246次阅读
2025-04-30 12:17:54
MySQL 8.4 新特性深度解析:功能增强、废弃项与移除项全指南
JiekeXu
228次阅读
2025-04-18 20:21:32