简体   繁体   中英

MySQL restore table from XAMPP issue

I used to rely on XAMPP in my Kubuntu 18.04 which located in /opt/lampp . I uninstalled the XAMPP and had a whole folder backup in this directory before that, and eager to install all the LAMP stack individually, which i installed apache2, mysql-server, and phpmyadmin after that.

The thing is, i want to import my databases from my backed up XAMPP folder located in /opt/lampp/var/mysql which consist of all my databases with tables in .frm and .ibd format, which is obviously exist, to my current installed mysql package database location in /var/lib/mysql .

After i moved those databases, i opened phpmyadmin to make sure the dbs imported correctly, but i only saw the database without the table inside the database. How come? What needs to be done to restore the tables inside?

You can't just copy database files from the datadir ( /var/lib/mysql in your case). A proper MySQL/MariaDB backup is to generate.sql files which you can then import independently. It's not possible to selectively restore certain databases, due to the way certain files are managed (such as ibdata1 and perhaps others such as logfiles).

What I would try, and may or may not work, is this (the usual disclaimers about backups apply, I'm not responsible if your system becomes inoperative or catches fire, etc):

  1. Make a back up of your existing databases (to SQL, I use the mysqldump command-line utility that ships with MySQL/MariaDB).
  2. Stop the MySQL daemon and make sure it isn't running.
  3. Temporarily move your current datadir out of the way (perhaps with a command like mv /var/lib/mysql /var/lib/mysql-current ).
  4. Copy your complete backup, the entire MySQL datadir (from XAMPP's old /opt/lampp/var/mysql ), to /var/lib/mysql .
  5. Start the MySQL daemon.
  6. Connect and export any data you wish to save to SQL files.
  7. Stop the daemon.
  8. Move the current /var/lib/mysql out of the way (or if you're brave, delete it entirely).
  9. Restore your original files from /var/lib/mysql-current to the original location in /varlib/mysql
  10. Start the daemon again
  11. Import the SQL files you've generated from step 6.

That's it — you should now be all set with your original data in your new database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM