Skip to content

Instantly share code, notes, and snippets.

@tothi
Last active November 12, 2022 18:00
Show Gist options
  • Save tothi/5d1d60548bc85bd0d4c052451194f063 to your computer and use it in GitHub Desktop.
Save tothi/5d1d60548bc85bd0d4c052451194f063 to your computer and use it in GitHub Desktop.
recover innodb from corrupted tablespace
### DANGEROUS OPERATIONS: do not run automatically
### (notes)
# https://web.archive.org/web/20170105064212/https://twindb.com/recover-corrupt-mysql-database/
DB=dbname; TBL=tablename
# from prod mysql instance
mysqlfrm --user=root --server=root:xxx@localhost --port=3307 /var/lib/mysql/${DB}/${TBL}.frm | sed -e 's/^CREATE TABLE `[^`]*`\./CREATE TABLE /g' -e '1d' -e '$a;' | grep -v '^#' > schemas/${DB}_${TBL}_author.sql
./stream_parser -f /var/lib/mysql/${DB}/${TBL}.ibd
# from local backup
mysqlfrm --user=root --server=root:xxx@localhost --port=3307 ../mysql/${DB}/${TBL}.frm | sed -e 's/^CREATE TABLE `[^`]*`\./CREATE TABLE /g' -e '1d' -e '$a;' | grep -v '^#' > schemas/${DB}_${TBL}_author.sql
./stream_parser -f ../mysql/${DB}/${TBL}.ibd
# -6f OR -5f? (wordpress: -5f)
./c_parser -5f ./pages-${TBL}.ibd/FIL_PAGE_INDEX/0000000000001319.page -t ./schemas/${DB}_${TBL}_author.sql
./c_parser -5f ./pages-${TBL}.ibd/FIL_PAGE_INDEX/0000000000001319.page -t ./schemas/${DB}_${TBL}_author.sql > dumps/default/${DB}_${TBL} 2> dumps/default/${DB}_${TBL}_load.sql
echo "DROP TABLE ${TBL}" | mysql ${DB} && cat schemas/${DB}_${TBL}_author.sql | mysql ${DB} && ln -sf ${DB}_${TBL} dumps/default/${TBL} && cat dumps/default/${DB}_${TBL}_load.sql | mysql ${DB} && mysqlcheck ${DB} ${TBL}
cd ..
./recover.sh ${DB}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment