PHPMYADMIN main 2 SQL Database KESE Merge hogi (SMF HELP)

Started by iTHero, November 23, 2009, 06:15:47 PM

Previous topic - Next topic

iTHero

Salam
SMF Urdu Community main iTHero Hazir HAi
Tamam Expert Bhiyon Se aik problem ka solution chaye tha....main ne apna forum appserver per upload kar rakha hai or main apni OLD SQL database ko NEW SQL database ke sath merge karna chata hon.... Mujhay malom hai ye kam phpmyadmin main hoga lekin kon........main chata hon ke old db main se sirf khuch topics new main merge ho jain or badi mahnat se main bach jaon..... mujhay sirf ye guideline de den ke konse table main or kis tarikay se database ko merge karna hai yani ke New database main sirf old database ke khuch topic ad karne hen. baki setting new ki hi rakhni hai...........
is ka sahi solution mil jaye to bohut maherbani hogi.......koi thirdparty tool use hoga ya sab kam manualy karna pare ga...........
main sab expert ke replay ka muntizir raho ga.......
Zeeshan

iTHero

Mujhay Lagta HAi Urdu Community Per abhi Kam Kam howa hai is liye is question ka solution yahan Mojod nahi hai ..................aik Forum ke ADmin hone ke natay main samjhta hon Database MAnaging Ka masla tamam Users KE sath Hoga.......................

Mraza

well zeeshan me nai apke pm k reply me bhi bataya tha k apko ager sql ka knowledge hai to ap ker skte , aur ager nahi to phir mushkil hoga, dekhe shyed kisi k pass itna time ho yaha to apki database merge me shayed koi help kr ske.
Signature:
Old Software Engineers Never Dies, They Just Log Out...
! ! ! ! ! 5 Best Movies Thread ! ! ! ! !

iTHero

Salam Mraza Bhai main ne apni searching se ye find kia hai aap is step by step process main convert kar saken to Kafi MEmbers Ka faida Ho jaye Ga...........
How to merge two MySQL databases
I thought that we ought to post this in the forum for the benefit of other users, since I have just recently received a request for help with merging two MySQL databases into one...

A request recently landed on my desk from a client who had a fairly large links database. They had deleted the database, after first making and downloading a backup, and started afresh with a new and empty database, but after a week or so, they decided that they would like to restore the old database. Now that's a simple enough operation, but they had since had some new entries in their newer database which they wanted to keep, so they wanted help with merging the two MySQL databases into one while retaining the existing structure and data. This is the advice that I gave...

How to merge two MySQL databases

First you will need to download a backup of your existing database (the newer one), I am assuming here that you already have a backup of the other database which you want to merge with the existing one. If not, you need to download a backup of both (best to always be on the safe side and keep regular backups of your MySQL databases on your local hard drive). So, you will need to log into your cPanel (web hosting control panel), use the Backup link to go to the Backup page. Then select the database that you need to download by using the links under the section entitled Download a MySQL Database Backup (in fact, if you have not already done so, download each and every database that is shown there right now). You should be faced with a prompt to download the database(s), and you should allow the download and select an appropriate place on your hard drive to save each one.

Now we need to go to the folder on your hard drive which contains the database backup(s) that you've just downloaded. And rename the newest one to something slightly different (I'd just add the letter a to the existing file name, but do NOT change the file extensions). For example, let's say that your newest database backup is called linksdb1.gz, this should be renamed to linksdb1a.gz

Now that you've renamed one of the database backups, you will need to upload that renamed backup to your web space, so go now click the Browse button under the section entitled Restore a MySQL Database on the Backup page from which we downloaded the backups. In the window that comes up, browse to the folder and select the renamed backup and click Open. Then you will see the path and file name in the box to the left of the Browse button, now click the Upload button right below that and your database will be restored (let the page finish loading to ensure that the upload has completed before doing anything else).

Now you must repeat this step for the old database, which will replace the existing database on the server with the old one. We will then get to work on merging the newer data into the older database so we have not lost any of the newer entries.

Now that you've restored the renamed database, go back to the cPanel home page (use your browser's Back button and then use the link top right of the cPanel page called Home).

Now use the MySQL Databases link to go to the MySQL interface, and scroll down to the bottom of the page and click on the phpMyAdmin link which will open the phpMyAdmin page in a new browser window.

Now we need to select the renamed database that you restored as above (in the example I gave above it was named linksdb1a.gz - to select this database on the phpMyAdmin page, look to the left pane and select the database from the drop down list (where it says (Databases) ... ). You should see all of your existing databases in that drop down list, and you select the database we want by simply clicking on the one which we renamed. The phpMyAdmin page will now reload and show the database structure in the main pane (the right part of the window) together with a list of tables in the database in the left pane. Don't worry about the left pane because we will now be working in the main window (the right part of the window).

The next step is to find the table which holds the data which you want to merge. Lets say in this instance, the links are contained in the table called dbs_links. We'll keep this to hand because we will need this when entering the SQL code to merge the information into the existing database.

Now we need to click on the tab called SQL, its at the top of the main window. You'll now see a different page in the main window, and we will now be entering a SQL instruction in the large input box called Run SQL query/queries on database username_linksdb1 (note that the username part will be replaced with your control panel username, this is always used as a prefix on every MySQL database name :: and the linksdb1 part will be replaced with the actual name of your database). Now enter the following code (replacing the username part with your cPanel username) ...


Code:
INSERT IGNORE INTO `username_linksdb1a.gz`.`dbs_links`
SELECT *
FROM `username_linksdb1.gz`.`dbs_links`
Highlight and press CTRL+C to copy this code, then paste it using CTRL+V

NOTE: don't forget to change username to your own control panel username. Remember that we determined the data that we wished to merge from the appropriate table, in this example we used dbs_links as we can see in the code, so you need to replace that with the appropriate table name in your databases.

Note the use of the IGNORE element in the code above, it ensures that duplicate entries are skipped. If this was left out, you may get an error message during the merge which will prevent all records from being merged.

Now click the Go button at the bottom right of the input box (where you've just entered this code). The page will then refresh and show a results box above the input box that we just used. It should tell you how many rows have been inserted into the database.

Advertisement: