How to import table data MySQL? - mysql

I had a problem with MySQL on one of my DigitalOcean Ubuntu servers, so I compressed the files and have transferred them over to a new one.
I have moved the /var/lib/mysql folder over, which has the databases in, they are now visible in phpMyAdmin, but when I click them it says the table doesn't exist, do I need to run a command to import it all, or should I start again and import it differently?

This depends on the storage engine you use on your source System. If you use MyISAM you can just copy the three file associated with your table (.frm, .MYD, .MYI) to your target machine, restart the MySQL Service and your tables are there. With all other storage engines you should use mysqldump from a comandline (see here).

Related

MySQL restore table from XAMPP issue

I used to rely on XAMPP in my Kubuntu 18.04 which located in /opt/lampp. I uninstalled the XAMPP and had a whole folder backup in this directory before that, and eager to install all the LAMP stack individually, which i installed apache2, mysql-server, and phpmyadmin after that.
The thing is, i want to import my databases from my backed up XAMPP folder located in /opt/lampp/var/mysql which consist of all my databases with tables in .frm and .ibd format, which is obviously exist, to my current installed mysql package database location in /var/lib/mysql.
After i moved those databases, i opened phpmyadmin to make sure the dbs imported correctly, but i only saw the database without the table inside the database. How come? What needs to be done to restore the tables inside?
You can't just copy database files from the datadir (/var/lib/mysql in your case). A proper MySQL/MariaDB backup is to generate .sql files which you can then import independently. It's not possible to selectively restore certain databases, due to the way certain files are managed (such as ibdata1 and perhaps others such as logfiles).
What I would try, and may or may not work, is this (the usual disclaimers about backups apply, I'm not responsible if your system becomes inoperative or catches fire, etc):
Make a back up of your existing databases (to SQL, I use the mysqldump command-line utility that ships with MySQL/MariaDB).
Stop the MySQL daemon and make sure it isn't running.
Temporarily move your current datadir out of the way (perhaps with a command like mv /var/lib/mysql /var/lib/mysql-current).
Copy your complete backup, the entire MySQL datadir (from XAMPP's old /opt/lampp/var/mysql), to /var/lib/mysql.
Start the MySQL daemon.
Connect and export any data you wish to save to SQL files.
Stop the daemon.
Move the current /var/lib/mysql out of the way (or if you're brave, delete it entirely).
Restore your original files from /var/lib/mysql-current to the original location in /varlib/mysql
Start the daemon again
Import the SQL files you've generated from step 6.
That's it — you should now be all set with your original data in your new database.

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.

percona backup and restore

I'm trying to use percona xtrabackup to backup a mysql database. in the restoring the database according to the documentation:
rsync -avrP /data/backup/ /var/lib/mysql/
this will copy the ibdata1 as well.
what if I have want to restore the backup into an existing mysql instance with some some existing databases? would this corrupt my other databases? clearly this will overwrite existing ibdata1.
I suppose you have a local http/php server, so in case you don't need to batch import or export information, I suggest you use a database manager app that can import or export as sql, csv or tsv files.
I use a web-based admin tool called Adminer and it works great (plus, it's just a single php file). It has options to export or import a whole database or just certain tables and even specific registers. Its usage is pretty straightforward.

MYSql 5.5 Upgrade Issue: All tables gone

I had MySql 5.1.13 Database on Windows 2008, then on one fine day I took backup of my server [300+ databases]. Uninstall Old version and install 5.5 Version of MYSql. Now I copy the Data Folder back in Mysql 5.5 data location and I got all my Databases, but later I realise that around 250 Databases though did present at location but they do not show Tables in PHPmyadmin. I try to run "Show Tables" on couple of those database and Tables name does shows [and so as tablename.frm files exits] .
not to mention all tables that are Innodb are only one missing. How can get them back with ease. I have backup of each database but running 250 SQL files is not easy :).
Your innodb engines can have their own seperate folder where they store their data files. According the MySQL manual InnoDB creates tablespace files in the MySQL data directory by default see: http://dev.mysql.com/doc/refman/5.0/en/innodb-configuration.html.
Normally you would split you tables onto different drives to increase performance thus you might have a scenario where the InnoDB tables where configured to be placed on a another drive or folder. If you have it please check the previous MySQL configuration file and check for the following line: innodb_data_home_dir = /ibdata
This will indicate where the files are located. I have not tried this but you should be able to point the current config to the old innodb location if this is the case. If that does not work I think restoring will be you best bet.
Good luck!

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.