简体   繁体   English

alter table mysql离线与否?

[英]alter table mysql offline or not?

I need to add a column to my current table. 我需要在当前表中添加一列。

This table is used a lot during the day and night. 这张桌子在白天和晚上都经常使用。 i found out i need to alter using the alter command found here 我发现我需要使用此处找到的alter命令进行更改

http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

I tested it on a development server. 我在开发服务器上测试了它。

i took about 2 hours to complete. 我花了大约2个小时才完成。 Now I want to execute this on the production server? 现在我想在生产服务器上执行此操作?

will this stop my website? 这会阻止我的网站吗?

Why not display a message on the site saying you will perform maintenance from midnight UTC time January 7 2012. 为什么不在网站上显示一条消息,说明您将在2012年1月7日午夜时间执行维护。

This way, you won't break any data, you will not get any mysql errors. 这样,你不会破坏任何数据,你不会得到任何mysql错误。 you execute your ALTER and you start the site again once its completed (don't forget your code to make sure you have the right field etc..). 您执行ALTER并在完成后再次启动该站点(不要忘记您的代码以确保您拥有正确的字段等)。 Easy solution. 轻松解决方案

Stackoverflow does it, why not yours? Stackoverflow会这样做,为什么不是你的?

Yes, during an ALTER TABLE all reads and writes are blocked. 是的,在ALTER TABLE期间,所有读取和写入都被阻止。 If your website needs to use that table, requests will hang. 如果您的网站需要使用该表,请求将挂起。

Try pt-online-schema-change . 尝试pt-online-schema-change It allows reads and writes to continue, while it captures changes to be replayed against the altered table once the restructure is done. 它允许读取和写入继续,同时它捕获一旦重组完成后要对更改的表重放的更改。

Test carefully on your development server so you know how it works and what to expect. 在您的开发服务器上仔细测试,以便了解它的工作原理和预期结果。

It won't stop your website, but it will likely make it throw errors. 它不会阻止您的网站,但它可能会导致错误。

Of course there is no way to answer this without looking at all the code of your application. 当然,如果不查看应用程序的所有代码,就无法回答这个问题。

The bottom line is, when in doubt schedule a maintenance window. 当有疑问安排维护窗口时,底线是。

  1. Make the production server to point to dev db (or) mirror of prodcution db for some time. 使生产服务器指向生成数据库的dev db(或)镜像一段时间。
  2. Alter the table in production 改变生产中的表格
  3. Deploy the code which talks to production db (with the new attributes) 部署与生产数据库对话的代码(使用新属性)

PS: I feel this is safer and a fool proof way (based on my experience). PS:我觉得这是更安全和一种万无一失的方式(根据我的经验)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM