gpt4 book ai didi

mysql - 如何通过安全的 bash 命令使用 InnoDB 表删除未映射的 MYSQL 数据库?

转载 作者:行者123 更新时间:2023-11-30 00:06:45 25 4
gpt4 key购买 nike

$ user=jocular; cat ~/list|while read db; do echo rm -vi /var/lib/mysql/$user_$db; done

这就是我的想法,但我的导师给了我这样的反馈:

Removing MySQL databases in this manner can cause catastrophic problems for the MySQL server that can lead to loss of the MySQL server. Remove a database using InnoDB tables in this fashion and attempt to restore it from a backup to learn more.

删除未映射的数据库最安全的命令是什么?

最佳答案

你的老师是对的,InnoDB 使得使用 shell 工具操作表和数据库变得更加困难。原因是 InnoDB 在 ibdata1 文件内管理一个“数据字典”,该文件对数据库和表以及它们所属的表空间文件进行编目。如果您在 shell 中移动、重命名或删除文件,InnoDB 的数据字典现在会引用 out-of -日期信息,随后尝试使用这些表名称或数据库名称会遇到冲突。

Sort of like when you get a new phone, and you keep getting calls from friends of the former owner of that phone number.

如果您使用 SQL 或其他 MySQL 命令删除数据库,InnoDB 会确保更新其数据字典并使其与现实保持同步。

user=jocular; cat ~/list | while read db; do mysqladmin drop "${user}_${db}" ; done

Mysqladmin 在删除数据库之前会提示您,因为无法撤消该更改。但您也可以使用 -f 选项强制删除而不提示。请小心,不要删除错误的数据库!

关于mysql - 如何通过安全的 bash 命令使用 InnoDB 表删除未映射的 MYSQL 数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24478732/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com