How to access my MySQL files on a hard drive using Windows - mysql

I was given some research data on a hard drive. All the files are in one folder and consists of .frm files, .MYD files, .MYI files, .TRG files and .TRG files.
I downloaded and installed MAMP so that I can run an MySQL Server. I launched PHPMYAdmin in a browser and chose the import option. I then navigated to the data folder and realized that it was looking for a .zip file with the structure .sql.zip. I then proceeded to zip all of the content to comply and according to the WinZip dialog box, it was going to take 3 hours! This cannot be the correct action.
I found this solution from 8 years ago (derobert):
Recover Database Files From MYD MYI FRM Files
which has a linux solution (copy the files into the /var/lib/mysql/dbname directory)
There was also a solution for Windows in which a single .frm file and a ibdata1 file is copied to the data folder (alnel). Since my intention was not to copy the data to my notebook but, instead, read it directly from the drive, I tried another solution mentioned and it turned into a nightmare....
I created a symbolic link in the data folder: c:\MAMP\bin\mysql\data called mydata
c:\mklink /D mydata e:\MyResearchData
This created a link as expected. I then reloaded PHPMyAdmin expecting to see it listed. I did not. Recognizing that the /D switch is for a soft link, I tried a hard link using /H. However, that didn't over-write the previous link. I then proceeded to delete the link and it deleted all of my data! Recovery was not as simple as if I had deleted the data from the C:\ as it was not in the Recycle Bin. I was able to use file recovery software but now I am gun-shy about trying anything unproven.
I did eventually copy all the files into the MySQL data folder (suggested by Vishal)(c:\MAMP\bin\mysql\data\MyResearchData) and refreshed PHPMyAdmin ... no luck.
I'm hoping someone can lead me in the correct direction.
Thank you in advance!

You've figured out one possible way. The other way is to find My.ini (mysql config file) in which you will find datadir and basedir like
# Path to installation directory. All paths are usually resolved relative to this.
basedir="C:/Program Files/MySQL/MySQL Server 5.7/"
# Path to the database root
datadir=C:/ProgramData/MySQL/MySQL Server 5.7/Data
change the datadir to whatever location you have your MySQL data and restart your server. Since your current data dir is "c:\mamp\db\mysql" look for that line in the config file.
if you are going to use it often, i'd suggest installing MySQL server, workbench and mysql notifier using mysql installer for windows. It's much more easier to manage. With workbench you can do many things.

Related

Restore DB data after XAMPP uninstallation

I uninstalled XAMPP from my pc, during the uninstallation the system asked me if wanted to delete htdocs folder (I selected "yes" because I made a backup of this folder before the uninstallation), after that the system asked me if I wanted to delete Mysql data and I selected "NO".
After the uninstallation I had still some folder in C:/xampp (also mysql folder).
Now I reinstalled XAMPP but is there a method to restore DB file with the folders that I have?
I tried to replace the mysql folder but it wasn't a good idea.
This is a screenshot of the folders that are remained after the uninstallation:
The databases are stored on xampp\mysql\data location on this location you find the folder for each database in this folder you have file db.opt and also two file for each table that is (yourtableName.frm and yourtableName.ibd)
something like....
if you put that all dbfolder (in mycase i.e. "empdb") in to above location you will get your database back to used
Hope it make sense

XAMPP NOT WORKING! - OS X Yosemite

I was working with XAMPP 1.8.3-3 on OS X Mavericks. After upgrading to Yosemite Mysql server stopped working. And an upgrade to XAMPP 1.8.3-5 fixed the problem and mysql server starts working.
Now the entire database list is showing on phpmyadmin, but no access to the tables. Its showing “#1146 - Table ‘DB_NAME.TABLE_NAME’ doesn’t exist”.
Unfortunately I don't have any DB backup!
I have the entire XAMPP folder backup. So how I can able to retrieve the mysql tables?
just type /Applications/XAMPP/xamppfiles/bin/mysql.server start
in terminal then start xampp
you can restore if you have all the mysql folders from XAMPP folder. (check /XAMPP/xamppfiles/var/mysql in backup)
if you have var/mysql folder, open and look for database names you had earlier.
there is a separate folder for each database you had earlier. open the folder and it will contain lots of files with table names.
if your old table engine is InnoDB you will see 2 files. with .frm and .ibd extensions.
or if you had MyISM it will contain three file per table which has .frm, .MYD and .MYI extensions.
after you verify you have all the required files in backup, you can start restoring them.
stop mysql
copy required database folder completely and paste it to currently installed folder. (/Applications/XAMPP/xamppfiles/var/mysql/)
start mysql
to restore web files, open htdocs folder in backup and copy required site folder to currentely xampp installed htdocs folder.
This solution worked for me. Good Luck !
Do a clean install. See my answer for my own question. xampp mysql server not starting. The bad part is that I'm not sure if it will save your database the way I explained. What you might try is going to xampp > xamppfiles > var > mysql > 'your database name' and making a copy of the database folder on your desktop and moving it back once you reinstall it. I tried and I think it might have worked had I changed the file permissions. You can also try experimenting to see if it preserves the database if you do this. I would do some serious testing if you really want to save your database before doing this.

How do I move a MySQL database from one hard drive to another?

I am using MySQL 5.5 and MySQLWorkbench on Windows7. I have successfully created a database on my C: drive but I want to move it to my E: drive. I stopped the mysqld daemon and edited the my.ini file to change datadir="C:/ProgramData/MySQL/MySQL Server 5.5/Data/" to datadir="E:/MySQL/data/". I copied the data from the C: location to the E: location.
I can start the mysqld process, but the database I created does not appear. Would anyone have any explanation as to what I am doing wrong?
Basicly you would like to copy all the contents in the old directory to the new directory. Make sure that while doing this you don't also copy binlogs (if any, they look like mysql-bin.001 etc. and also don't copy mysql-bin.index because that contains real path reference to the old binary logs). Once you do that, you should be able to restart the mysql daemon and login to see the databases.
PS: not tested, but should work.
When I was trying to move my database I ran into the issue where windows didn't have the same permissions on the new data folder as the original. You may check that the correct user(s) have access to the new folder by going to the properties of the folder then selecting the security tab.
As I wanted my innodb database to sit on another partition, I stopped MySQL from the MySQL Workbench. I copied my innodb database ibdata1 as well as 2 log files which MySQL automatically created in my C:\ProgramData\MySQL\ folder to a new folder on my E: partition. I added the following to my.ini:
innodb_data_home_dir = "E:/MySQL Data"
Now, when I start my database, all changes are made to the ibdata1 in the E: drive.
Dump your database to disk using this tool http://sourceforge.net/projects/mysqlbutool/ Then restore it to the new server using this tool http://www.webyog.com/

Restore the mysql database from .frm files

I have dumped all my tables everyweek to got the backup. But later I understand that it is only storing the .frm file of the table. It is not showing .MYD and .MYI files of a table. So I have only my .frm file of the database with me and also mydatabase is innodb. So can I get my database with data in the database?
Yes this is possible. It is not enough you just copy the .frm files to the to the databse folder but you also need to copy the ib_logfiles and ibdata file into your data folder. I have just copy the .frm files and copy those files and just restart the server and my database is restored.
After copying the above files execute the following command -
sudo chown -R mysql:mysql /var/lib/mysql
The above command will change the file owner under mysql and it's folder to MySql user. Which is important for mysql to read the .frm and ibdata files.
Just might be useful for someone:
I could only recover frm files after a disaster, at least I could get the table structure from FRM files by doing the following:
1- create some dummy tables with at least one column and SAME NAME with frm files in a new mysql database.
2-stop mysql service
3- copy and paste the old frm files to newly created table's frm files, it should ask you if you want to overwrite or not for each. replace all.
4-start mysql service, and you have your table structure...
regards.
anybudy
I answered this question here, as well: https://dba.stackexchange.com/a/42932/24122
I recently experienced this same issue. I'm on a Mac and so I used MAMP in order to restore the Database to a point where I could export it in a MySQL dump.
You can read the full blog post about it here: http://www.quora.com/Jordan-Ryan/Web-Dev/How-to-Recover-innoDB-MySQL-files-using-MAMP-on-a-Mac
You must have:
-ibdata1
-ib_logfile0
-ib_logfile1
-.FRM files from your mysql_database folder
-Fresh installation of MAMP / MAMP Pro that you are willing to destroy (if need be)
SSH into your web server (dev, production, no difference) and browse to your mysql folder (mine was at /var/lib/mysql for a Plesk installation on Linux)
Compress the mysql folder
Download an archive of mysql folder which should contain all mySQL databases, whether MyISAM or innoDB (you can scp this file, or move this to a downloadable directory, if need be)
Install MAMP (Mac, Apache, MySQL, PHP)
Browse to /Applications/MAMP/db/mysql/
Backup /Applications/MAMP/db/mysql to a zip archive (just in case)
Copy in all folders and files included in the archive of the mysql folder from the production server (mt Plesk environment in my case) EXCEPT DO NOT OVERWRITE:
-/Applications/MAMP/db/mysql/mysql/
-/Applications/MAMP/db/mysql/mysql_upgrade_info
-/Applications/MAMP/db/mysql/performance_schema
And voila, you now should be able to access the databases from phpMyAdmin, what a relief!
But we're not done, you now need to perform a mysqldump in order to restore these files to your production environment, and the phpmyadmin interface times out for large databases.
Follow the steps here:
http://nickhardeman.com/308/export-import-large-database-using-mamp-with-terminal/
Copied below for reference. Note that on a default MAMP installation, the password is "root".
How to run mysqldump for MAMP using Terminal
EXPORT DATABASE FROM MAMP[1]
Step One:
Open a new terminal window
Step Two:
Navigate to the MAMP install by entering the following line in terminal
cd /applications/MAMP/library/bin
Hit the enter key
Step Three:
Write the dump command
./mysqldump -u [USERNAME] -p [DATA_BASENAME] > [PATH_TO_FILE]
Hit the enter key
Example:
./mysqldump -u root -p wp_database > /Applications/MAMP/htdocs/symposium10_wp/wp_db_onezero.sql
Quick tip: to navigate to a folder quickly you can drag the folder into the terminal window and it will write the location of the folder. It was a great day when someone showed me this.
Step Four:
This line of text should appear after you hit enter
Enter password:
So guess what, type your password, keep in mind that the letters will not appear, but they are there
Hit the enter key
Step Five:
Check the location of where you stored your file, if it is there, SUCCESS
Now you can import the database, which will be outlined next.
Now that you have an export of your mysql database you can import it on the production environment.
I made use of mysqlfrm which is a great tool which generates table creation sql code from .frm files. I was getting this nasty table not found error although tables were being listed. Thus I used this tool to regenerate the tables. In ubuntu you need to install this as:
sudo apt install mysql-utilities
then,
mysqlfrm --diagnostic mysql/db_name/ > db_name.sql
Create a new database and then you can use,
mysql -u username -p < db_name.sql
However, this will give you the tables but not the data. In my case this was enough.
Yes! It is possible
Long approach but you can get all the data's using just .frm files. Of course, you need other files in the mysql/data directory.
My Problem
One day my hard disk crashed and got the booting blue screen error. I try connecting with multiple machines and it didn't work. Since it is a booting error I was concerned about the files. and I tried with the secondary hard disk and try to recover the folders and files. I also backed up the full xampp folder c:/xampp just in case, Because I had no back of the recent databases I got really worried about how to retrieve the database. we have a lot of clients' project management and personal doc in the database.
None of the methods listed on the StackOverflow comment works, at least for me. It took me 2 full days googling for the answer to getting the data from the .frm files. Came across multiple approaches from many people but everything was frustrating and getting some error or another when implementing. If most of them get it working (based on their comment) then what am I missing.
Because I was so desperate I even reinstall windows which result in losing all my software and tried again. But still the same error
THANKS to Dustin Davis
I found the solution in his blog and I managed to get it working exactly the same way he did. Let me give the credit to this guy, Dustin Davis (https://dustindavis.me/restoring-mysql-innodb-files-on-windows/). You could jump from here to his blog and try his method, pretty clear and easy to follow.
But there is something I discovered when trying his approach that he hasn't explained in his blog and I will try my best to explain how I did and what you need to look for.
Follow this exactly
IMPORTANT: Make sure you install the same version of XAMPP. You cannot copy-paste from older XAMPP to a new version. This will result in __config or __tracking errors.
How to check your XAMPP version
Go to your xampp folder (you're backed up xampp).
Open the readme_en.txt file. which is in the root directory of the xampp.
You should see the version on top. ###### ApacheFriends XAMPP Version X.X.XX ######
Files require to restore
xampp(old folder)/mysql/data/
ibdata1
ib_logfile0
ib_logfile1
<databasename>/*.frm
<databasename>/*.ibd
Step 1
After installing the same version of xampp.
Do not start the apache or myql
Step 2
Go to the mysql/data folder and replace the ibdata1, ib_logfile0, and ib_logfile1
Now copy paste your database folder from your old xampp backup to the newly installed xampp folder c:/xampp/mysql/data/ that contain .frm and .ibd files, If you are not sure try with one database.
Step 3
Go to c:/xampp/mysql/bin and look for my.cn.
Open the my.cn file and look for #skip-innodb and under that look for the line that says innodb_log_file_size=5M change it to 170M. innodb_log_file_size=170M. This is your log file size and if you are not sure just set it to 170
Step 4
Now open the file mysql_start.bat (Windows Batch file) that is in the c:/xampp/ directory.
Add –innodb_force_recovery=6 after the ... --console
....
mysql\bin\mysqld --defaults-file=mysql\bin\my.ini --standalone --console -–innodb_force_recovery=6
if errorlevel 1 goto error
goto finish
Step 5
Now Start your Apache and Mysql.
Go to your PHPMyAdmin and check for your database and its tables. if you do not get any errors you are on the right track.
Stop the Apache and Mysql and copy-paste the rest of the databases.
I just copy pasted the database folders to data folder in MySQL, i.e. If you have a database called alto then find the folder alto in your MySQL -> Data folder in your backup and copy the entire alto folder and past it to newly installed MySQL -> data folder, restart the MySQL and this works perfect.
Copy all file and replace to /var/lib/mysql ,
after that you must change owner of files to mysql
this is so important if mariadb.service restart has been faild
chown -R mysql:mysql /var/lib/mysql/*
and
chmod -R 700 /var/lib/mysql/*
After much trial and error I was able to get this working based on user359187 answer and this blog post.
To get my old .frm and .ibd transferred to a new MySQL database after copying the files over and assigning MySQL ownership, the key for me was to then log into MySQL and connect to the new database then let MySQL do the work by importing the tablespace.
mysql> connect test;
mysql> ALTER TABLE t1 IMPORT TABLESPACE;
This will import the data using the copied .frm and .ibd files.
I had to run the Alter command for each table separately but this worked and I was able to recover the tables and data.
Before starting you should stop the WAMP services, or at least restart the services when prompted to start them.
On the old server instance navigate to the MySQL data folder by default this should look something similar to C:\wamp\bin\mysql\mysql5.1.53\data\ where mysql5.1.53 will be the version number of the previously installed MySQL database.
Inside this folder you should see a few files and folders. The folders are the actual MySQL databases, and contain a bunch of .frm files which we will require. You should recognise the folder names as the database names. These folder and all their contents can be copied directly to your MySQL data folder, you can neglect the default databases mysql, performance_schema, test.
If you started the server now you will see the databases are picked up, however the databases will contain none of the tables which were copied across. In order for the contents of the database to be picked up, back in the data folder you should see a file ibdata1, this is the data file for tables, copy this directly into the data folder, you should already have a file in your new data folder called “ibdata1″ so you may wish to rename this to ibdata1.bak before copying across the ibdata1 from the old MySQL data folder.
Once this has been done Restart all the WAMP services. You can use PhpMyAdmin to check if your databases have been successfully restored.
create a new database with same name
copy the .frm .ibd files into xampp/mysql/data/[databasename]/
you will need ibdata file as well
which is found inside
xampp/mysql/data/
copy the previous ibdata1 file
paste in the paste the file and replace it with the existing ibdata file
[caution: you may loose the contents of the database which are newly created in the new ibdata file]

What is the exact location of MySQL database tables in XAMPP folder?

I have a MySQL database and I want to know the exact location where this data actually stored in the XAMPP folder, I went to this file location to try to get the information:
xampp -> mysql -> data ->
Here I found a separate folder for each of my databases and within these folders I saw files stored with the .frm format (FRM FILE).
When I copied my desired database with all tables in .frm format and try to use them on another PC, I was given an empty database of the same name.
Where are the data files for the database kept on the local server?
For Mac, your database files are located at:
/Applications/XAMPP/xamppfiles/var/mysql
You might need admin permissions to access or delete your files.
Your database is in this directory:
C:\xampp\mysql\data
Rather late I know, but you can use SELECT ##datadir to get the information.
Happy file huntin' SO community :)
This is how it looks when ran in phpmyadmin:
I think the matter is your tables engine. I guess you are using InnoDB for your table. So you can not copy files easily to make a copy.
Take a look at these links:
http://dev.mysql.com/doc/refman/5.0/en/innodb-backup.html
http://dev.mysql.com/doc/refman/5.0/en/innodb-migration.html
Also I recommend you to use something like phpMyAdmin for creating your backup file and then restore the backup file on the next machine using the same IDE.
Copy and paste the entire data folder, not just the content.
I use xampp, and the path to the data is xampp/mysql/data.
The exact location is stored in "my.ini" which exists under main mysql installation directory. In my.ini file, look for 'datadir'. This parameter points the data folder.
Data are store in this path. You can search data location, just put the below address in your search location (url address):
C:\xampp\mysql\data
Just in case you forgot or avoided to copy through PHPMYADMIN export feature..
Procedure: You can manually copy: Procedure For MAC OS, for latest versions of XAMPP
Location : Find the database folders here /Users/XXXXUSER/XAMPP/xamppfiles/var/mysql..
Solution: Copy the entire folder with database names into your new xampp in similar folder.
If you are like me, and manually installed your webserver without using Xampp or some other installer,
Your data is probably stored at C:\ProgramData\MySQL\MySQL Server 5.6\data
In Ubuntu the file path is ./opt/lampp/var/mysql