Forums

MySQL ALTER TABLE and OPTIMIZE commands taking forever to execute

I am trying add a table to MySQL database's existing table. I have disabled website in PythonAnywhere's Web panel. At the moment, I am only logged into the MySQL database using shell of PythonAnywhere browser window. I have tried to execute the following commands

use database1;
SET foreign_key_checks=0;
SET unique_checks=0;
set autocommit=0;

these commands ran just fine.

But the following command is taking forever.

ALTER TABLE `pa_username$database1`.table_name ADD new_col varchar(50) NULL;

So, I tried to optimize table using following command but that also took forever and we had to terminate it.

OPTIMIZE TABLE table_name;

What could be the issue and any idea on how this could be fixed?

How many rows are in the table? It might be simply that it's so large that adding on a column is a slow process.