Is it possible to migrate related data but with different column names from one database to another database? and im talking about very large amount of data here. someone has an idea? I have tried exporting it to CSV and importing to the otherdatabase but i get errors saying:
invalid column count in CSV input in line 1
So if anyone has an efficient and effective way of doing this please share. Or if anyone can guide mo through this CSV mapping in excell on how to properly do it, i would really appreciate
With the MySQL Workbench Migration Wizard, users can convert an existing database to MySQL in minutes rather than hours or days that the same migration would require using traditional, manual methods. The Migration Wizard allows you to easily and quickly migrate databases from various RDBMS products to MySQL.
Importing TablesA table that resides in a file-per-table tablespace can be imported from another MySQL server instance or from a backup using the Transportable Tablespace feature.
There are two cases in this:
You just need to insert the data in the destination table:
insert into dbDestination.tblDestination (field1, field2, ...)
select ...
from dbSource.tblSource
Notes
select
statement must include the fields you need to copy to the destination table.select
statement must be in the same order as the fields specified in the field list in the insert
portionI would export the data to a plain text file, and then import it. I personally prefer .csv files, but it's up to you.
You have two possibilities: To use select... into outfile
or to use the system terminal (command window).
a. Using select... into outfile
and load data
In the server where dbSource
is:
select ...
from dbSource.tblSource
into outfile [your destination file]
...
Copy the file to the destination server.
In the server where dbDestination
is:
load data local infile [your file] ...
Notes
select
statement must be in the same order as the fields specified in the field list in the insert
portionselect... into outfile
and load data...
b. Using the terminal
In Linux (or other Unix systems), open a terminal window and enter the following command:
$ mysql -h [sourceServer] -u [yourUser] -p[yourPassword] dbSource -e"select ..." | sed 's/\t/,/g' > yourDestinationFile.csv
Copy the file to the destination server
Start MySQL console, and use `load data ...``
Notes
select
statement must be in the same order as the fields specified in the field list in the insert
portion| sed 's/\t/,/g'
part converts the output of the mysql query to a .csv file. You can use another separator instead of ,
. For further reference about sed
check http://lowfatlinux.com/linux-sed.html
ignore 1 lines
at the end of the load data...
sentence.To copy data from one database to another is a very simple task. Hope this points you in the right direction.
A word of advice: Download the reference manual for your MySQL version and keep it at hand. You can find most of your solutions there.
A simple way to do this is with the following syntax:
INSERT INTO Database.Table(field 1, field 2,...)
SELECT * FROM Database2.Table2;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With