Using Mariadb Databases From Old Server

Home » CentOS » Using Mariadb Databases From Old Server
CentOS 6 Comments

I’m running CentOS-7, but I left some MySQL databases on my old CentOS-6.5 partition which I’d like to retrieve. I assume they are contained in the file /var/lib/mysql/ibdata1 ?

Could I just copy this file to /var/lib/mysql in CentOS-7?
Or is there some way Mariadb or phpMyAdmin can import mysql databases from a server that is no longer running?

6 thoughts on - Using Mariadb Databases From Old Server

  • The C6 partition is part of the new server, so you are able to mount it and copy files from it, is this correct? Have you done something with the MariaDB or it’s still clean installation?

  • Todor Petkov wrote:

    I did add something to Mariadb on the new CentOS-7 system, but I don’t mind deleting it and starting again. I can mount the partition with the old mysql files on it. Could I just copy the contents of /mnt/var/lib/mysql to the new system?
    There are files with the same name, eg ibdata1, on both systems. Could I have an ibdata2 ?

    Any suggestions gratefully received.

  • If you don’t care about the new data, you can:

    1) shut down MariaDB
    2) rename /var/lib/mysql to /var/lib/mysql.orig
    3) copy the old directory /var/lib/mysql – /mnt/var/lib/mysql in your case – do not forget the permissions! – to /var/lib/mysql
    4) systemctl start mysql (or mysqld, can’t remember)
    5) run mysql_upgrade – this is a script, which changes the mysql.user etc tables with the new columns
    6) There are some issues with PHP for example, when you have an user in mysql system tables, that has an old hash password, so you need to reenter the password to update the hash

    I did it many times this way and everything went smoothly.

    Good luck and don’t forget to make some backups just in case;)

  • This is what I ran into trying to clone a web server on C7 (doing this from memory):
    There is something in the database file /var/lib/mysql that has to match something elsewhere on the machine. Apparently the match is created during the mariadb-server.rpm installation. I found two ways to transfer a /var/lib/mysql file successfully.
    1. Transfer the file before installing mariadb-server.rpm or
    2. After copying the file over the existing one, yum reinstall mariadb-server

    Hope this helps, Ted Miller, Indiana, USA

  • Richard wrote:

    Thanks very much for your advice.

    Actually I had already taken a rather longer path:
    I installed a MySQL server on my Fedora laptop, and transferred the directory /var/lib/mysql from the dead computer. This ran perfectly, so I could export the table in question, and install it on my server.

LEAVE A COMMENT