Recover SQL innodb Database

How to recover an SQL innodb db with docker. When I moved this wordpress to it new hosting a did not have any good backup of the db. And i only got the mysql files from /var/lib/mysql.

 

So to get the site back without to much work I want to see if I could get the sql files mounted into a mysql docker and recverd to the export a .sql file.

And it worked and here is how

 

Recover the db

Start a mysql docker container and mount your files into it. Then start mysql with this command.

docker run -it -v /home/mahe/projects/backup/fromcolo/export/disk/word-hosting/lifeandshell-com/wp/:/var/lib/mysql mysql /bin/bash

 

In th file

vi /etc/mysql/mysql.conf.d/mysqld.cnf

 

[mysqld]
innodb_force_recovery = 6

 

 

Start mysql with the command

su mysql -s/bin/bash -c "/usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables "

 

Now you should have a running sql with you innodb files and we now can login and dump the database.

 

List all docker running

docker ps

 

Login into the one with the sql

docker exec -it 8b214ff70688 /bin/bash

 

And dump the sql you want

mysqldump wordpress >> /var/lib/mysql/wordpress.sql

 

I dump the sql to the /var/lib/mysql folder and that is mounted into the container and i can now get the .sql file and import it into my new site.