有什么办法可以查看ALTER TABLE执行后的情况吗? -MySQL

发布于 2024-08-22 14:31:08 字数 81 浏览 10 评论 0原文

同样的方式SHOW CREATE TABLE tblname;返回之前执行的内容,是否有办法查看 ALTER TABLE 查询的 SQL? 请帮忙?

In the same way SHOW CREATE TABLE tblname; brings back what was previously executed, is there anyway to view the SQL of an ALTER TABLE query?
Please help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不可一世的女人 2024-08-29 14:31:08

需要澄清一点:show create table 实际上并不“恢复之前执行的内容”。它只是向您显示将从头开始创建表的 DDL。该表可能已创建并更改了多次,但 show create table 反映了表的当前状态。

至于查找最近在表上运行的任何 alter table 语句,最好的选择是二进制日志。

首先检查是否启用了二进制日志:

show variable like 'log_bin';

如果是,则找到相关时间段的二进制日志,使用mysqlbinlog将其转换为SQL,然后grep相关表名找到alter table 您正在寻找的声明。

One small clarification: show create table does not actually "bring back what was previously executed". It just shows you the DDL that would create the table from scratch. The table may have been created and then altered many times, but show create table reflects the current state of the table.

As for finding any alter table statements that ran on the table recently, the best bet is the binary log.

First check to see if binary logging is enabled:

show variable like 'log_bin';

If it is, find the binary log for the relevant time period, use mysqlbinlog to convert it to SQL, then grep for the relevant table name to find the alter table statement you are looking for.

陪你到最终 2024-08-29 14:31:08

工具:

  • Maatkit。
  • Red-Gate 的 MySQL 架构和Data Compare
  • Toad
  • SQLYog
  • MySQL Diff

手动:

首先检查是否启用了二进制日志记录:

show variable like 'log_bin';

然后,

mysqlbinlog /var/log/mysql/mysql-bin.000001 | grep 'alter table *tablename*' > test.file

转到 test.file 查看 alter 语句。

Tools:

  • Maatkit.
  • Red-Gate's MySQL Schema & Data Compare
  • Toad
  • SQLYog
  • MySQL Diff

Manual:

First check to see if binary logging is enabled:

show variable like 'log_bin';

Then,

mysqlbinlog /var/log/mysql/mysql-bin.000001 | grep 'alter table *tablename*' > test.file

Go to test.file to see the alter statements.

‖放下 2024-08-29 14:31:08

如果您的 MySQL 实例开启了日志记录,您可以查看日志。这将是最好的选择。

如果您的系统打开了历史记录,您可以从同一系统启动客户端备份并尝试向上箭头。您也许可以在那里看到该命令。

如果您认识运行该命令的用户,并且他们碰巧直接从命令行运行该命令,则相同的历史记录技巧可能会起作用。

If your MySQL instance has logging turned on, you can view the logs. This would be the best option.

If your system has history turned on, you can start a client back up from the same system and try the up arrow. You might be able to see the command there.

If you know the user that ran the command and they happened to run it directly from a command line, the same history trick might work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文