Pages

Saturday, March 30, 2013

Recover Lost WAMP Databases

Sometimes we are messed up tinkering with WAMP vanilla package.And all we end up is fatal errors that either restrict us to use PHP MyAdmin or let us forget the fact of importance of an Database Backup.

We take the backup of WWW/our Important Projects but are hopeless when we find no database for the same.

Here is a way to resolve the problem.First and Important step Backup of whatever you are left with

If you have the the following folder intact with you

"D:\wamp\bin\mysql\mysql5.5.24\data".(You may find a change in version of your Mysql Folder.)

You can bring back the Data out from ashes.

This folder remains even if you uninstall wamp.Its ur Mysql Data Dump.Unless and untill you have tempered with this area you can get your databases back.

Now That's the ingredients we need

1. The folder in bold above
2. A Wamp setup(we will be going for a fresh installation)

 If you have them in hand let's startoff with recovery process then

1. Rename this folder to something other than "wamp".Let's say "wamp_bak"
2. Reinstall wamp to your favorite location.
3. Under your wamp installation you will find a file with path and name as follows

"D:\wamp\bin\mysql\mysql5.5.24\my.ini"

You may see only "my" as file name in case your extension types are hidden.Again your mysql version may differ.

Open this file in your favorite text editor.I prefer using "notepad","notepad++" in order to preserve their encodings.

Search for a line like as follows

"datadir=d:/wamp/bin/mysql/mysql5.5.24/data"

It was 39th line I am using notepad++. 

copy this line and place a hash before the same.

"#datadir=d:/wamp/bin/mysql/mysql5.5.24/data"

We have commented this line here....

paste the uncommented  exactly same line just below this commented line.

"datadir=d:/wamp/bin/mysql/mysql5.5.24/data"

We will be playing with Path's now

In windows explorer navigate to your old wamp backup till the data folder and copy its path. Considering you are following the same directory and naming conventions as me you would get a path like this one

"D:\wamp_bak\bin\mysql\mysql5.5.24\data"

(I suppose you have copied it from window's explorer's address bar like any smart freak does )


paste the path in my.ini and replace it with the path in our copied uncommented text.We will get sth like this


"#datadir=d:/wamp/bin/mysql/mysql5.5.24/data" (commented line)
"datadir=D:\wamp_bak\bin\mysql\mysql5.5.24\data" (uncommented line)

In the uncommented line change the copied path as follows

"d:/wamp_bak/bin/mysql/mysql5.5.24/data"

Restart Wamp if you get a green signal everything went well if not check path again.

Open phpmyadmin in browser

http://localhost/phpmyadmin

You will find a list of databases from your previous installations.

Next Step: Exporting Databases

Select Export

Under "Export Method" select "Custom"

Select All Databases Except/Excluding

1. mysql
2. performace_schema
3. information_schema
4. test

Scroll Down Select Go soon you will be told to save an sql file containg sql dump of all your previous databases.

Save it....That's your Magic Wand in Hand to bring up Databases from Ashes.

Change the Path in "my.ini" back to

"datadir=d:/wamp/bin/mysql/mysql5.5.24/data"

(remove the copied line and uncomment the orignal one to get a line sth as above)

Restart Wamp and open 

http://localhost/phpmyadmin in browser 

You should be back with your original setup by now

Now all you need to do is Import SQL File

You may need to modify the sql file again open the same in your favorite editor

remove following lines from top

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
 


remove following lines from bottom

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


Also you might need to modify some Referential Integrity Constraints if you are facing importing error's.

If it imports successfully you are back with original databases.If not let me know the error's.I would with glad to assist you in recovery.

PS:In case you fail even after this do follow our important comments too