Skip to content

Instantly share code, notes, and snippets.

@nexusstar
Last active June 22, 2018 08:31
Show Gist options
  • Save nexusstar/233d08d43c1f068cae06e9d8e6996030 to your computer and use it in GitHub Desktop.
Save nexusstar/233d08d43c1f068cae06e9d8e6996030 to your computer and use it in GitHub Desktop.

Ok folks, I ran into this problem this weekend when my OpenStack environment crashed. Another post about that coming soon on how to recover.

I found a solution that worked for me with a SQL Server instance running under the Ver 15.1 Distrib 10.1.21-MariaDB with Fedora 25 Server as the host. Do not listen to all the other posts that say your database is corrupted if you completely copied your old mariadb-server's /var/lib/mysql directory and the database you are copying is not already corrupted. This process is based on a system where the OS became corrupted but its files were still accessible.

Here are the steps I followed.

Make sure that you have completely uninstalled any current versions of SQL only on the NEW server. Also, make sure ALL mysql-server or mariadb-server processes on the NEW AND OLD servers have been halted by running:

        service mysqld stop or service mariadb stop.

On the NEW SQL server go into the /var/lib/mysql directory and ensure that there are no files at all in this directory. If there are files in this directory then your process for removing the database server from the new machine did not work and is possibly corrupted. Make sure it completely uninstalled from the new machine.

On the OLD SQL server:

      mkdir /OLDMYSQL-DIR cd /OLDMYSQL-DIR tar cvf mysql-olddirectory.tar /var/lib/mysql gzip mysql-olddirectory.tar

Make sure you have sshd running on both the OLD and NEW servers. Make sure there is network connectivity between the two servers.

On the NEW SQL server:

      mkdir /NEWMYSQL-DIR

On the OLD SQL server:

      cd /OLDMYSQL-DIR scp mysql-olddirectory.tar.gz @:/NEWMYSQL-DIR

On the NEW SQL server:

        cd /NEWMYSQL-DIR gunzip mysql-olddirectory.tar.gz OR tar zxvf mysql-olddirectory.tar.gz (if tar zxvf doesn't work) tar xvf mysql-olddirectory.tar.gz

You should now have a "mysql" directory file sitting in the NEWMYSQL-DIR. Resist the urge to run a "cp" command alone with no switches. It will not work. Run the following "cp" command and ensure you use the same switches I did.

        cd mysql/ cp -rfp * /var/lib/mysql/
```

Now you should have a copy of all of your old SQL server files on the NEW server with permissions in tact. On the NEW SQL server:

```
        cd /var/lib/mysql/
```
VERY IMPORTANT STEP. DO NOT SKIP
```
> rm -rfp ib_logfile*
```
Now install mariadb-server or mysql-server on the NEW SQL server. If you already have it installed and/or running then you have not followed the directions and these steps will fail.
FOR MARIADB-SERVER and DNF:
```
> dnf install mariadb-server
> service mariadb restart
```
FOR MYSQL-SERVER and YUM:
```
> yum install mysql-server
> service mysqld restart
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment