更新时间:2023-11-30 22:50:04
您应使用 pt-online-schema-change ,该工具可自动执行MySQL的ALTER TABLE操作,不锁定表格。它是Percona工具包的一部分,它是MySQL开发人员和DBA的免费必备工具免费集合。
You should use pt-online-schema-change, a tool for automating ALTER TABLE operations for MySQL, without locking the table. It's part of the Percona Toolkit, a free collection of indispensable helper tools for MySQL developers and DBA's.
$ pt-onlines-chema-change h=localhost,D=mydatabase,t=mytable \
--alter="add column mod_time timestamp"
在pt-online-schema-change运行时,您可以继续读取和写入原始表。完成后,它会自动交换表格名称,并删除原始名称。
You can continue reading and writing the original table while pt-online-schema-change is working. When it's done, it automatically swaps the tables' names, and drops the original.
您可以通过其设计者查看有关此工具的在线讲座的录像。查看是免费的,但需要注册: http ://www.percona.com/webinars/2012-05-02-zero-downtime-schema-changes-in-mysql
You can view a recording of a webinar about this tool by its designer. Viewing is free, but requires registration: http://www.percona.com/webinars/2012-05-02-zero-downtime-schema-changes-in-mysql