开发者

MySql ALTER TABLE on Production Databases - Any Issues?

开发者 https://www.devze.com 2022-12-20 14:10 出处:网络
I have about 100 databases (all the same structure, just on different servers) with approx a dozen tables each. Most tables are small (lets say 100MB or less). There are occasional edge-cases where a

I have about 100 databases (all the same structure, just on different servers) with approx a dozen tables each. Most tables are small (lets say 100MB or less). There are occasional edge-cases where a table may be large (lets say 4GB+).

I need to run a series of ALTER TABLE commands on just about every table in each database. Mainly adding some rows to the structure, but a few changes like change a row from a varchar to tinytext (or vice versa). 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 practice开发者_开发问答s 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?

Anything and everything I should know about performing ALTER TABLE commands on a production database I am interested in learning.

If its of any value knowing, I am planning on issuing commands via PHPMYADMIN for the most part.

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.

Secondly, you may want to use mysql from the command line. PHPMyAdmin will probably time out. Most PHP server has timeout less than 10 minutes. 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) .

  2. You can create indexes by using "create index statements" .don't use 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消