If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > help with migrating data from one database to another

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-21-10, 13:59
ozzii ozzii is offline
Registered User
 
Join Date: Mar 2007
Posts: 194
help with migrating data from one database to another

Hi,

I have MySQL database which I have redesigned from scratch. The tables in the new database has some mandatory fields which the old database did not have

I need to migrate the data from the old database into the new one. The old database has several thousand records stored in different tables.

What is the best or most practical way to migrate this data so that the mandatory fields in the new database wont be a hinderance?

One of my problems is that in the old database user passwords were stored in an unencrypted format. The new database stores them using phps md5 hash in an encrypted format - that is whne a new user signs up the php script will encrypt the password and then store it in the new database.

If i was to migrate this information from the old database to the new they will end up being stored again in an unencrypted format.

Any help and guidance would be appreciated.

Regards
Reply With Quote
  #2 (permalink)  
Old 05-21-10, 15:38
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
You need some kind of ETL (Extract-Transform-Load) process. In this case an ETL process can be as simple as a MySQL script. In other cases, it can be an application/scripts/etc and there are many vendors and open source systems that facilitate ETL projects.

There are many approaches, and only you can decide which is best for you. My suggestion would be to create a "staging table" with the same structure (columns and data types) as your destination table, but without the constraints. Transfer the data to the staging table, massage it as needed, make a backup of anything currently in your destination table, then repeat the try/fix/try again cycle as often as needed to get the data clean and into your destination.

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #3 (permalink)  
Old 05-27-10, 13:42
mtomcanyi mtomcanyi is offline
Registered User
 
Join Date: May 2010
Posts: 1
ozzii,

I think Pat explained the approach nicely, so just a few recommendations from my side.

Before doing the try/fix/try cycle, do a little analysis in the source data for other data-related problems to save a few iterations . Look for duplicates, weird default values or broken data integrity. During systems lifecycle admins tend to drop constraints to facilitate data that were not counted on in the original model.

During try/fix cycle, enable constraints in target one by one, then re-load data to incrementally identify problem groups (they will be rejected by database).

Finally, I suggest doing audit counts to discover any rejected data. Also is possible check the app sitting on top of your database to see if it is affected.

In terms of the missing data, you have several options:
1. You can try to populate the missing data from other sources (e.g other system, other tables, have users type it in). Correct the data in stage, then load to target.

2. You are not able to correct the data. Then you have to fall back to default values (-1, 01/01/1970, etc.). If you use this approach DOCUMENT it, because the application/users must be ready for that!

Another possibility is not to migrate the records with missing data and place them to a reject file/table. Once again, backup and document that, as someone might come looking for the missing data.

I very much support Pat's suggestion to use ETL, but with my background I am a bit biased . While SQL scripting will definitely work if you just migrate within one database, consider using ETL tools if there is some complex data manipulation expected (e.g. one table is mapped to many, data must be validated/recalculated). Today's tools lets you visualize that process, so it is much easier to inspect, debug and understand the migration rules.

Regarding the MD5, either use the built-in md5() function in MySQL, or calculate it on the fly in your ETL job.

HTH,
Michal
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On