Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Altering the data type of a column in a HUGE table. Performance issues

Tags:

mysql

alter

I want to run this on my table:

ALTER TABLE table_name MODIFY col_name VARCHAR(255)

But my table is huge, it has more than 65M (65 million) rows. Now when I execute, it takes nearly 50mins to execute this command. Any better way to alter table?

like image 614
Kiran Avatar asked Jun 12 '12 11:06

Kiran


2 Answers

Well, you need

 ALTER TABLE table_name CHANGE col_name new_name VARCHAR(255)

But, you are right, it takes a while to make the change. There really isn't any faster way to change the table in MySQL.

Is your concern downtime during the change? If so, here's a possible approach: Copy the table to a new one, then change the column name on the copy, then rename the copy.

You probably have figured out that routinely changing column names in tables in a production system is not a good idea.

like image 143
O. Jones Avatar answered Oct 14 '22 01:10

O. Jones


another variant to use percona toolkit https://www.percona.com/doc/percona-toolkit/2.2/pt-online-schema-change.html

like image 29
gayavat Avatar answered Oct 14 '22 01:10

gayavat