How can I import a backup made from MAMP PRO/db? - mysql

The article
https://appsolute.zendesk.com/hc/en-us/articles/215198206-How-do-I-do-a-complete-uninstall-and-re-install-of-MAMP-PRO-
says "Copy back your database and host files to their original locations if needed. You will need to remake your hosts." but when I do that, the database appears empty in phpMyAdmin (even though the .frm and .ibd files are in the folder for the db.
Is there an extra step I am missing?

Related

Recovering a XAMPP database with ibdata1, .frm and .ibd files

Thanks for looking!
I've tried pretty much every solution I found online, yet nothing recovered a full database.
My client had a crash of MySQL on her XAMPP, and sent over the mysql/data folder along with WP root directory(it's a WordPress website).
-she erased the mysql/backup folder
-I've tried copying ibdata1, .frm and .ibd files into fresh XAMPP, but then I get the "Table doesn't exist in engine" error in PHPMyAdmin
Also tried SysInfo MySQL Database Recovery tool, which extracts the database when pointed to database folder, and without loading ibdata1. If I load ibdata1, tables are empty. If I point the software to the database directory, I get a full database, but with a few weird issues. Some are in wp_posts table(,, instead of ,'',) which brakes the element count, but I hopefully patched it. However, some other things are not showing well, all IDs are like "-9223372036854775555", and slugs have weird characters, like "a-lepsi-jutri��u癮u�".
Post statuses look messed up as well(like "itclosedclosedsta").
On WP side, this manifests as a 404 homepage error. You can access wp-login.php, but after entering the details and trying to login you get redirected to the homepage 404.
When I replace the entire mysql folder in fresh XAMPP with a backup from my client, MySQL won't start.
Have also tried starting it with repair level 1-6, but MySQL still won't start.
Have tried creating a fresh database, adding tables and fields with .frm files, discarding TABLESPACE then copying over only .ibd files and importing TABLESPACE. This works only for empty tables.
Also some other things, but nothing worked so far.
Any WP or DB thoughts - please let me know :)

I Want to use a mysql database from a backup of a non-working server on a new computer

My database is from a backup of the non-working server.
My database is the teachercenter folder that was on the server, and contains files for each table name with the extension *.frm.
I copied the database from:
C:\Users\xxx\Downloads\wamp-saved\wamp\bin\mysql\mysql5.1.36\data\
And pasted that folder on my computer here:
C:\wamp\bin\mysql\mysql5.6.17\data
I realize the the two mysql's were different versions, but I'm just trying to use the database files.
When I start up PHPMyAdmin on the new computer, it shows the teachercenter database in the list of databases.
Also, if I click the plus next to the teachercenter database, I can see a list of my database tables!
But if I click on teachercenter database itself, I get error:
No tables found in database.
How do I get mysql to recognize and let me operate (PHPMyAdmin) on the teachercenter database on the new computer?
I tried to start/use wampmanager.exe, but I don't see it running to use it's menus.
THE PROBLEM IS SOLVED:
At: stackoverflow.com/questions/10934745/… a simple answer to my probelem is given, as follows: "Yes this is possible. It is not enough you just copy the .frm files to the to the database folder but you also need to copy the ib_logfiles and ibdata file into your data folder." I copied the ib_logfiles and ibdata file into my data folder, and Voila! PHPMyAdmin was completely happy with the database and its tables and I could do SQL exports of table records.
Summary: To make use of a MySQL database of *.frm files that your MySQL doesn't understand, simply copy the ib_logfiles and ibdata file from whereever you got the .frm files from, and put these two files in the data folder next to the database you want to use. Once you do that, the MySQL database engine will recognize your database, and you can all PHPMyAdmin operations on your fully operational database.
Because you can't be sure that the MyISAM storage format backwards compatible, your safest option is to install MySql 5.1.36, use mysqldump to export your entire database to plain SQL, install MySql 5.6.17 and then import your data using SQL.
Also, this probably gives better results because your indexes are rebuild.

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]

Import .frm and .opt files to MySQL

I am using MySQL 5.5.1.1 downloaded and installed from : http://dev.mysql.com/downloads/
I want to import .frm and .opt database files from my local machine to my mysql database.
I created a new Databbase connection to help me import the files from my machine. But I am unable to import .frm files as I keep getting error message: Format not supported.
Can someone please help me on how I could import files to MySQL client??
Thank you,
J
As far importing any MySQL data, three(3) things need to considered.
MyISAM
Importing a MyISAM table is a simple as moving three files with the extensions .frm, .MYD, and .MYI files for the given table into a MySQL folder. For example, if the table name is mydata, then the three(3) files
mydata.frm
mydata.MYD
mydata.MYI
The following could be the nightmare of nightmares. Importing InnoDB depends entirely on many factors that fall into one of two categories:
InnoDB (innodb_file_per_table disabled [default])
All InnoDB data and index pages are located in /var/lib/mysql/ibdata1. This file must be moved from your source machine (Server-S) to the target machine (Server-T) and placed in the same absolute path. In fact, here is the shocker: Server-S and Server-T must be the same. In other words, you cannot import and export InnoDB .ibd files to other machines. They can only be imported and exported on the same machine the .ibd was created on.
You would also have to move /var/ib/mysql/ib_logfile0 and /var/ib/mysql/ib_logfile1 from Server-S and place them in the same absolute path on Server-T.
You also must make sure that every InnoDB variable set in /etc/my.cnf from Server-S must be set in /etc/my.cnf on Server-T.
InnoDB (innodb_file_per_table enabled)
For every InnoDB table, there will be two files. For example, if the InnoDB table in the mydata database is called mytable, you will have /var/lib/mysql/mydata/mytable.frm and /var/lib/mysql/mydata/mytable.ibd. The .ibd file contains data and index pages for the table. To import the individual table you must
Place the mytable.frm in /var/lib/mysql/mydata folder on Server-T
Place the mytable.ibd in /var/lib/mysql/mydata folder on Server-T
Run ALTER TABLE mydata.mytable IMPORT TABLESPACE;
Make sure you have the /var/lib/mysql/ibdata1 in the same place it was imported from.
Moral of the story
Please do not use IMPORT TABLESPACE techniques across different servers. Just do a mysqldump of everything and import the mysqldump. Logical dumps are always the safest way to go !!!
I did a mysql import using the files on xampp. I have very many databases so I did not want to go through the mysqldump route. The process was:
Install the new xampp, but do not enable the services
Update my.ini to include any custom settings I had on the previous install.
Confirm that mysql is starting successfully
Copy over all the database folders (inside the data folder) from the old install with the exception of mysql, phpmyadmin and webauth.
Confirm that mysql is starting successfully
Copy over ib_logfile0, ib_logfile1 and ibdata1. Rename the files first, do not overwrite just in case something goes wrong.
Confirm that mysql is starting successfully
Copy over the following files from the data/mysql folder: db.frm, db.MYD, db.MYI, user.frm, user.MYD, user.MYI. Do not overwrite the new ones just in case it doesn't work.
Confirm that mysql is starting successfully
At the end of the process I had mysql working perfectly with all my databases and users intact.
Just copy desired 'data' folder to target mysql data folder, after renaming current 'data' folder, after stop mysql service. And export to sql file with phpmyadmin, and restore current data folder, and import desired data sql.
I think the great problem you may be experiencing comes from the fact that you cannot even view these .frm files in the phpmyadmin interface (because they really are incomplete sets). I'd suggest you delete these files from the current location and use phpmyadmin to re-create the these tables as SQL under "query" tab [delete IFF you do have database script of everything. if not, you may still get this from the old dump. if not gaian, do NOT delete). Thanks : chagbert.

How do I re-create a MySQL InnoDB table from an .ibd file?

Assume that the following MySQL files have been restored from a backup tape:
tablename.frm
tablename.ibd
Furthermore, assume that the MySQL installation was running with innodb_file_per_table and that the database was cleanly shutdown with mysqladmin shutdown.
Given a fresh install of the same MySQL version that the restored MySQL files were taken from, how do I import the data from tablename.ibd/tablename.frm into this new install?
Similar thing is answered here.
please have a look
https://stackoverflow.com/a/10943833/3985205
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.
You must bring the table into the tablespace:
https://www.percona.com/doc/percona-xtrabackup/2.2/innobackupex/restoring_individual_tables_ibk.html
ALTER TABLE mydatabase.tablename IMPORT TABLESPACE;
There is also a exp/cfg file you must have.
I posted the correct solution when you lost ib_logfiles and ibdata file and you have only .frm and .idb files.
Please take a look at my comment on this link:
Restore table structure from frm and ibd files
This will work for you, too.
Thank you.
This not may work in all cases.
But yes it is working in some case...
First stop all the services related to wamp or xampp which you use.
Then copy and past the tablename.frm, tablename.ibd
files under mysql/data/DATABASE NAME FOLDER.
then start all the services again. the tablet created under that DB.