Starting second MYSQL process

Thursday, November 7, 2019

R1soft has a nice database restore function which I would say is hit or miss process. When it keeps failing you can do the below steps to recovery manually.

IMPORTANT! DONT COPY AND PASTE

First you need to restore /var/lib/mysql from a backup to somewhere like /var/lib/mysql_restore/mysql. Once you have done that you cant start up a second mysql process to do a dump.

edit: /var/lib/mysql_restore/my.cnf

[server]
datadir=/var/lib/mysql_restore/mysql/ 
port=3307
socket=/var/lib/mysql_restore/mysql2.sock
pid-file=/var/lib/mysql_restore/mysql.pid
general_log_file=/var/lib/mysql_restore/mysql.log
log-error=/var/lib/mysql_restore/mysql-err.log
tmpdir=/var/lib/mysql_restore/tmp

start mysql

su -c 'mysqld --defaults-file=/var/lib/mysql_restore/my.cnf' mysql

dump databases

mysql -h 127.0.0.1 -P 3307 -e 'show databases' > dbs.txt
cat dbs.txt | while read line ; do mysqldump  -h 127.0.0.1 -P 3307 $line > $line.sql; gzip $line.sql; done

import database from backup

cat DATABASE_DUMP.sql.gz | mysql 

Now kill the second mysql process and clean up after yourself.

mysqlmysqllinuxrecovery
as free as beer

OpenSSH legacy options