Search code examples
mysqlheidisql

MySQL table "crashed" after column type update


My MySQL table "crashed" after updating column types. I changed VARCHAR to INT and added some new columns too.

After that, when I'd like to view the table entries, every software just keeps loading and crashing... I can't even make any queries to the table. All I can do is look at the list of columns of the table. (I've tried with PhpMyAdmin, HeidiSQL and MySQL Workbench). Changes are made with HeidiSQL.

What should I do? This is the first time this happens and I've been using HeidiSQL for a long time.


Solution

  • You have changed VARCHAR to INT in the table schema. At first sight we are correct, just change alter the column and mysql server do as without showing any error But when you alter the table, mysql server have to do lot of work. first store the records temporary and recreate the schema and insert the record. If your table have many records then it is tough to alter. So either truncate table and alter the schema and reinsert or create other table and rename it latter.

    In my opinion the solution is create table as you want schema.

    Insert the record in new table from table. eg- insert into new_table (col1, col2) select col1, col2 from old_table;

    drop the old table drop table old_table

    rename the new table with old table rename new_table to old_table