Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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 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?

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 -

like image 670
OneNerd Avatar asked Feb 12 '10 23:02

OneNerd


1 Answers

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.

like image 63
Yada Avatar answered Nov 13 '22 14:11

Yada