MySQL – Extract Table Using mysql/databasename Folder

MySQL

I am not an SQL expert, not even a novice so please excuse me if this question is naive. I have a copy of an old Linode drive where my Joomla website was hosted. I think that the Joomla database is located in "/var/lib/mysql/sitename".

I need to extract a specific table from this database but the database is not online anymore and I can not boot up from that drive anymore. What is the procedure to extract the info that I need from that database? (I know the table name from the Joomla documentation).

Best Answer

If you see [tablename].MYD and [tablename].MYI files it's MYISAM. If you see [tablename].ibd or only the .frm file then it's InnoDB. Based on that the process:

MyISAM

You can simply copy the .MYI, .MYD and .frm files to any existing MySQL instance's database directory.

For example:

You have your database in /var/lib/mysql/sitename then you find the table which will be /var/lib/mysql/sitename/[dbname]/[tablename].* (.MYD, .MYI and .frm). You can copy only these three files to an arbitrary database on a newly installed MySQL like /var/lib/mysql/sitename/[restored_db]/.

InnoDB

It's possible to import tablespace since 5.6 but if you can it's much simpler to copy the whole directoy. It's a common procedure to clone new replication slaves.

In your case you copy the whole /var/lib/mysql/sitename directory onto the new server and start MySQL over it. Make sure the innodb_log_file_size and innodb_log_files_in_group matches the size and number of what you have now. These are the files called ib_logfile0 and ib_logfile1.


When you have the server running you can use mysqldump or any other method you prefer.