Skip to content

Instantly share code, notes, and snippets.

@slashdotdash
Created September 21, 2009 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slashdotdash/190361 to your computer and use it in GitHub Desktop.
Save slashdotdash/190361 to your computer and use it in GitHub Desktop.
MySQL, Alter Table, and How to Observe Progress
#!/bin/bash
(while(true); do \
(mysql -e 'show innodb status \G' | grep undo\ log\ entries ; sleep 1 ; \
mysql -e 'show innodb status \G' | grep undo\ log\ entries ) | \
egrep '[0-9][0-9][0-9][0-9]' |awk '{print $10;}' ; done ) | \
perl -e '$t = ROWS_IN_TABLE; while(1) { \
$n ++; $nn; $a = <>; $b = <>; $nn += ($b-$a); \
printf "Rate: %d, avg: %d, %0.3f%% complete, done in %d sec\n", \
$b-$a, $nn/$n, ($b/$t)*100, ($t-$b)/($nn/$n); }';
# http://gabrielcain.com/blog/2009/08/05/mysql-alter-table-and-how-to-observe-progress/
@konstantinast
Copy link

(Yeah I know, that this thing is 9 years old, but Google still shows this quite high in the search results :D )

The above mentioned shell script is outdated and does not return result, because with newer mysql versions:

show innodb status \G

was changed to:

show engine innodb status \G

and even with this thing sorted out, when I try to run the above mentioned script I get:

Illegal division by zero at -e line 3, <> line 2.

error (sorry, but my shell-fu is too weak to fix that :( )

BUT I've managed to achieve a very similar result using instructions in the article, that I link to here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment