简体   繁体   English

关于生产数据库的MySql ALTER TABLE - 有任何问题吗?

[英]MySql ALTER TABLE on Production Databases - Any Issues?

I have about 100 databases (all the same structure, just on different servers) with approx a dozen tables each. 我有大约100个数据库(所有相同的结构,只在不同的服务器上),每个数据库大约有十几个表。 Most tables are small (lets say 100MB or less). 大多数表都很小(比方说100MB或更少)。 There are occasional edge-cases where a table may be large (lets say 4GB+). 偶尔会出现边缘情况,表格可能很大(比方说4GB +)。

I need to run a series of ALTER TABLE commands on just about every table in each database. 我需要在每个数据库的几乎每个表上运行一系列ALTER TABLE命令。 Mainly adding some rows to the structure, but a few changes like change a row from a varchar to tinytext (or vice versa). 主要是在结构中添加一些行,但是有一些更改,例如将一行从varchar更改为tinytext(反之亦然)。 Also adding a few new indexes (but indexing new rows, not existing ones, so assuming that isn't a big deal). 还添加了一些新索引(但索引新行,而不是现有索引,所以假设这不是什么大问题)。

I am wondering how safe this is to do, and if there are any best practices to this process. 我想知道这是多么安全,如果这个过程有任何最佳实践。

First, is there any chance I may corrupt or delete data in the tables. 首先,我是否有可能破坏或删除表中的数据。 I suspect no, but need to be certain. 我怀疑没有,但需要确定。

Second, I presume for the larger tables (4GB+), this may be a several-minutes to several-hours process? 其次,我假设更大的表(4GB +),这可能是几分钟到几个小时的过程?

Anything and everything I should know about performing ALTER TABLE commands on a production database I am interested in learning. 关于在我有兴趣学习的生产数据库上执行ALTER TABLE命令我应该知道的任何事情和一切。

If its of any value knowing, I am planning on issuing commands via PHPMYADMIN for the most part. 如果知道任何值,我计划通过PHPMYADMIN发布命令。

Thanks - 谢谢 -

First off before applying any changers, make backups. 在应用任何更换器之前先进行备份。 Two ways you can do it: mysqldump everything or you can copy your mysql data folder. 有两种方法可以做到: mysqldump一切或者你可以复制你的mysql数据文件夹。

Secondly, you may want to use mysql from the command line. 其次,您可能希望从命令行使用mysql PHPMyAdmin will probably time out. PHPMyAdmin可能会超时。 Most PHP server has timeout less than 10 minutes. 大多数PHP服务器的超时时间不到10分钟。 Or you accidently close the browser. 或者您意外关闭浏览器。

Here is my suggestion. 这是我的建议。

  1. You can do fail-over the apps.(make sure no connections on all dbs) . 您可以对应用程序进行故障转移。(确保所有dbs上没有连接)。

  2. You can create indexes by using "create index statements" .don't use alter table add index statements. 您可以使用“create index statements”创建索引。不要使用alter table add index statements。

  3. Do these all using script like(keep all these statements in a file and run from source). 这些全部使用脚本(将所有这些语句保存在文件中并从源代码运行)。

  4. Looks like table sizes are very small so it wont create any headache. 看起来桌子尺寸非常小,所以它不会造成任何头痛。

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

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