MySQL database disappear - mysql

I have done an idiot mistake, i cut the database folder in /var/lib/mysql folder and paste into my external hard drive because my hard disk was almost full.
Now i copy the database folder back into the original mysql folder, i cannot access the database anymore, phpmyadmin says it is an empty database.
Is there any way to recover the old database? If it disappear permanently it will be a big pain for me

What is the engine for your tables? InnoDB or MyISAM? If it is MyISAM then yes they can be recovered if you still have all the files but if type is InnoDB then there might be some trouble
And after pasting the files back to original directory you have to restart mysql server too.

Related

MySQL Tables Could Not Be Read

I'm using Appserv for local MySQL hosting. I had to reset my computer. I forgot to make backup for MySQL database and used Win 10 reset feature. So it removed all the applications but not personal files. After resetting my pc, I set up the Appserv again. I got into phpMyAdmin. On the left side, I can see all of the tables. But when i click on them, I'm having an error message "#1146 - Table 'database.table' doesn't exist". So i only have the MySQL data files which has database's .frm and .ibd files.
My question is, can i recover tables with these .frm and .ibd files?
Note: ib_logfile and ibdata files are overwrited after setup.
A quick search on Google I found an article that may help you but bear that in mind that once you erase something permanently by mistake or otherwise and if you haven't made the appropriate backups then I am sorry to say that whatever you do to try and resurrect it won't work.
Nevertheless, try out the link below and let me know of your progress:
http://www.voxteneo.com/restoring-tables-mysql-database-frm-ibd-files-available/

Xampp Mysql and Apache not Working - How to backup database

I'm having trouble with my Mysql and Apache server here for a week already. Tried to look for every possible solutions in the internet like changing ports and everything. Still no luck. I would like to reinstall Xampp, the problem is, I have important databases which do not have any backups yet. Is there a way to backup these databases without having my apache and mysql started?
It depends a bit on the type of storage engines you're using.
MyIsam
MyISAM tables are stored as files, so it is easy to do a backup by copying files (*.frm, *.MYD, and *.MYI files). In a typical XAMPP installation they can be found under c:/your/path/to/xampp/mysql/data/ .
InnoDB
Have a look at the manual:
Copy all InnoDB data files (ibdata files and .ibd files) into a safe place.
Copy all the .frm files for InnoDB tables to a safe place.
Copy all InnoDB log files (ib_logfile files) to a safe place.
Copy your my.cnf configuration file or files to a safe place.
However, if you have important databases, it is advised to think about a backup strategy before problems occur. MySQL offers a variety of backup strategies from which you can choose the methods that best suit the requirements for your installation.
Yes, you can just copy the data files. for innodb you need the ibdata1 (or similar) file. For MyISAM you will see 3 files (different extensions) for each database and the filename match the database names. If it is MyISAM then you can just copy these files back into the data directory on your new install and it will just work.
The other thing you should do is not use WAMP! It is easy enough to set up from scratch and much easier to figure out when things don't work.... you just need to read a little bit.
Copy all the files in your htdocs to another location first, duplicate the database organizers from information envelope and erase xampp then re-install it. You also need to delete the ib_logfile0, ib_logfile1 files from the data folder inside mysql folder.
Read here for further procedure https://dba.stackexchange.com/questions/3437/lost-tables-in-drupal-site-database

MySQL .frm/.myd/.myi

I have a MySQL database with test data. I have been modifying routines and triggers in this database. I have a new .tar file containing *.frm, *.myd, *.myi, *.trn, and *.trg files for this same database with production data. I want to take only the actual data from the tar file and move it into my existing database. May I simply move the *.myd and *.myi files from the tar file to the current folder for my database without corrupting the schema?
Yes, you should be able to do that just fine. frm, myd and myi are MyISAM tables and you can copy and moves those around without corrupting anything. Although, technically you should have the database shutdown when you do that. If that is not an option, make sure you run "flush tables" before copying anything.
Once you copy those into the mysql data directory, make sure the privileges are correct. Then you should be able to see them in mysql. As I said, you can do this while mysql is running, but I don't recommend it.
You cannot do this with Innodb tables (i.e. .ibd extension).

How to recover/restore the data (records) of my MySQL database on a corrupted hard drive?

A few days ago my hard drive crashed (no booting anymore). On this hard drive was a MySQL installation with a database (called "db_cedar"). Meanwhile, I could connect the corrupted hard drive as a second hard drive to my computer. That means I have full access to the file system of the crashed hard drive, thus on the MySQL files and folders.
I did never a backup of my database. I know, my fault. :-(
Is there a way to recover/restore the data (records) of my database (db_cedar) or even the entire database, for example by copying particular MySQL files or folders (on the crashed hard drive) and puting these on my new hard drive with a freshly installed version of MySQL? Note: The freshly installed MySQL version on my new hard drive is exactly the same version of the MySQL version on the crashed hard drive.
I would be very happy for any help. Thank you!
Provided the data is not corrupt, you should be able to copy the entire database directory + the my.cnf file and get back up and running.
For restoring InnoDB databases, have a look at my answer here.and have a look at taking cold backup f innodb from mysql docs here. For MYSIAM, it is easier. As #mluebke said just copy database directory and the my.cnf (for non-windows) or my.ini for windows

Restore mysql server from myd myi files - windows

I have a recovery disc image which contains the datafiles for mysql server.
The original server is unavailable - all I have is the datafiles (programdata, program files etc).
I am not able to make a mysqldump file.
On the new server, I've installed the exact copy of mysql server, and copied the files/folders (all the myd myi files) from the disc image to the new server.
After restarting the mysql service, I can see the list of my databases in mysql administrator.
However, when I try to view a table, I get an error:
"1146 The table {dbname}.{tablename} does not exist."
I tried running myisamchk but this says there is n problem (at least no error is displayed)
Can anyone help?
Bob
You will need a copy of the corresponding .frm files, which contain the format information MySQL needs to read the raw row data from .myd/.myi or ibdata files. Without the .frm files, MySQL does not know the tables are even supposed to exist (which is why they're not found, and myisamchk doesn't see any broken tables).
If you don't have these files, you may be in trouble. You should be able to reconstruct the .frm by re-CREATEing the tables from scratch, then stopping the server and dropping the .myd/.myis over the empty versions. But you will need to know the exact datatypes and indexes that were originally used in the schema. (“Very difficult repair”)