以同样的方式 SHOW CREATE TABLE tblname; 带回之前执行的内容,是否可以查看 ALTER TABLE 查询的 SQL?请帮忙?
3 回答
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.
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.
如果您的 MySQL 实例已打开日志记录,您可以查看日志。这将是最好的选择。
如果您的系统已打开历史记录,您可以从同一系统启动客户端备份并尝试向上箭头。您可能可以在那里看到该命令。
如果您知道运行该命令的用户并且他们碰巧直接从命令行运行它,那么相同的历史技巧可能会起作用。