Jump to content

Move data from 1 database to another


daveoffy

Recommended Posts

Using PhpMyAdmin you can

 

Go to the members table

Go to Export

Export for CSV MS Excel

In the options put the field names in first row

tick save as file and save to your computer

 

Do the same for the profile table

The just copy and paste the columns from the members spreadsheet to the profile spreadsheet.

 

When you have the file as you need, then delete the column names from the first row

 

 

Import the data back in by going to the profile table and clicking import tab

 

You can import using CSV LOAD Data, and in fields terminated by, replace ; with a comma (,).

 

 

I have DB1 table members, DB2 with table profile. Both have username columns. I want to move all the members usernames to the table profile in DB2 usernames. How will that be done? I am writting a PHP script for this, I don't have PHPMYADMIN for this job.

you would select the records. and run through in a loop saving the info you need from DB1 to columns in DB2

 

 

<?php

$query = "SELECT * FROM DB1";

 

$result = mysql_query($query) or die(mysql_error());

 

while($row = mysql_fetch_array($result)){

 

 

mysql_query("INSERT INTO DB2

(username) VALUES($row['username']) ")

or die(mysql_error()); 

 

}

?>

 

An easy way of doing that is by simply backing up your database first, which means, you have to back up the whole database or all the tables in that database... Then, you create the new database and restore the data which you backed up.

 

If you dealing with mySQL, then, you can use 'phpmyadmin' which does it easily, you simply open the database there and click on 'Export', then click on 'Restore' to save the data in the new database

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.