3

[译] mysql-m6米乐安卓版下载

原创 晨辉 2022-03-15
3073
原文地址:https://blog.sqlauthority.com/2021/12/23/mysql-recover-dropped-performance-schema-database/
原文作者:pinal dave

今天早些时候我在一个在线论坛上看到有用户在找如何恢复被删除的performance schema 数据库的方法。
image.png
老实说,恢复删掉的performance schema数据库非常容易,下面就是操作命令:
打开操作系统命令行,执行如下命令:

mysql_upgrade --user=root --password=password --force

一旦你的操作成功了,就需要重启mysql 服务。重启完成,你就有新的performance schema 数据库了。不用担心,你的数据是不会存在这个新的数据库的(译者注:这里指performance schema 数据库),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)
米乐app官网下载 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
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
1人已赞赏
【米乐app官网下载的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

网站地图