Edmonds Commerce Logo
  • home
    • blog
  • ecommerce
    • product catalogue
    • order processing
    • customer services
    • stock control
    • human resources
    • management information
  • development
    • oscommerce
    • php
    • mysql
    • open source
    • performance tuning
  • design
  • marketing
  • contact us
    • pricing

Edmonds Commerce Blog

Freelance PHP Ecommerce and SEO Developer in the UK

Latest Posts

Securing a LAMP Server with mod_security
osCommerce Easypopulate File Creator Class
CRELoaded Remove Google Ads -
ICECat Integration with osCommerce, Magento etc

Most Popular Posts

PHP Email Attachment Function Freelance osCommerce UK Ultimate osCommerce Checkout - Fast and Friendly PHP : Dead Easy Excel Export

MySQL Copy Table from One Database to Another

March 3rd, 2008
Read More mysql, programming, web development

Sometime in MySQL you want to copy an entire table from one database to a separate database. One example of when you would want to do this is if you are making a backup of a table before you apply some kind of processing to that table. There is nothing worse than ruining a database table and losing valuable information. To make an instant backup is so easy that there really is no excuse not to make backups at important or risky stages.

Here is how to do it:

PLAIN TEXT
MySQL:
  1. DROP TABLE IF EXISTS `backup_db.backup_table`;
  2. CREATE TABLE `backup_db.backup_table` SELECT * FROM `live_db.live_table`;

This will delete your existing backup table completely, then will remake it copying all structural information and content from the live_table in the live_db.

Related Blogs
http://www.phpclasses.org/browse/package/4017.html
http://www.sematopia.com/?p=61
http://www.yinfor.com/blog/archives/2008/02/mysql_backup_and_recovery_meth.html

Bookmark this Post
Add 'MySQL Copy Table from One Database to Another' to Del.icio.usAdd 'MySQL Copy Table from One Database to Another' to diggAdd 'MySQL Copy Table from One Database to Another' to FURLAdd 'MySQL Copy Table from One Database to Another' to blinklistAdd 'MySQL Copy Table from One Database to Another' to redditAdd 'MySQL Copy Table from One Database to Another' to Feed Me LinksAdd 'MySQL Copy Table from One Database to Another' to TechnoratiAdd 'MySQL Copy Table from One Database to Another' to Yahoo My WebAdd 'MySQL Copy Table from One Database to Another' to NewsvineAdd 'MySQL Copy Table from One Database to Another' to SocializerAdd 'MySQL Copy Table from One Database to Another' to Ma.gnoliaAdd 'MySQL Copy Table from One Database to Another' to Stumble UponAdd 'MySQL Copy Table from One Database to Another' to Google BookmarksAdd 'MySQL Copy Table from One Database to Another' to RawSugarAdd 'MySQL Copy Table from One Database to Another' to SquidooAdd 'MySQL Copy Table from One Database to Another' to SpurlAdd 'MySQL Copy Table from One Database to Another' to BlinkBitsAdd 'MySQL Copy Table from One Database to Another' to NetvouzAdd 'MySQL Copy Table from One Database to Another' to RojoAdd 'MySQL Copy Table from One Database to Another' to BlogmarksAdd 'MySQL Copy Table from One Database to Another' to ShadowsAdd 'MySQL Copy Table from One Database to Another' to Co.mments
Add 'MySQL Copy Table from One Database to Another' to ScuttleAdd 'MySQL Copy Table from One Database to Another' to BloglinesAdd 'MySQL Copy Table from One Database to Another' to TailrankAdd 'MySQL Copy Table from One Database to Another' to SegnaloAdd 'MySQL Copy Table from One Database to Another' to OKnotizieAdd 'MySQL Copy Table from One Database to Another' to NetscapeAdd 'MySQL Copy Table from One Database to Another' to Bookmark.itAdd 'MySQL Copy Table from One Database to Another' to AskAdd 'MySQL Copy Table from One Database to Another' to SmarkingAdd 'MySQL Copy Table from One Database to Another' to LinkagogoAdd 'MySQL Copy Table from One Database to Another' to DeliriousAdd 'MySQL Copy Table from One Database to Another' to SocialdustAdd 'MySQL Copy Table from One Database to Another' to Live-MSNAdd 'MySQL Copy Table from One Database to Another' to SlashDotAdd 'MySQL Copy Table from One Database to Another' to SphinnAdd 'MySQL Copy Table from One Database to Another' to DiggitaAdd 'MySQL Copy Table from One Database to Another' to SeotribuAdd 'MySQL Copy Table from One Database to Another' to FaceBookAdd 'MySQL Copy Table from One Database to Another' to UpnewsAdd 'MySQL Copy Table from One Database to Another' to WikioAdd 'MySQL Copy Table from One Database to Another' to Social Bookmarking Reloaded

Feed | Respond | Trackback

5 Responses to “MySQL Copy Table from One Database to Another”

  1. Julz Says:
    June 12th, 2008 at 11:42 pm

    Just remember that this won't create the table using the same engine as the existing table and it won't recreate the primary keys or indexes.

    To do this you have to use:

    CREATE TABLE new_table_name LIKE old_table_name;

    then you populate it with the data from the old table with:

    INSERT INTO new_table_name SELECT * FROM old_table_name;

    If the copied old table has many keys then it may help to speed the INSERT if you turn off the keys using the following before the INSERT:

    ALTER TABLE new_table_name DISABLE KEYS;

    And then after the INSERT:

    ALTER TABLE new_table_name ENABLE KEYS;

    These two statements are not supported by all MySQL Engine types though. InnoDB being one of them in MySQL ver 5.x

    Cheers
    Julz

  2. admin Says:
    June 13th, 2008 at 8:47 am

    Nice one Julz

    Yes if you want to do more than simply backup the table data and want to actually make a proper fully functional copy of the table then the above is definitely the best way to do so.

  3. tony Says:
    October 2nd, 2008 at 2:31 pm

    hi, i want to update my table2 with only the new data that i have entered from table1. hopefully on a daily basis

    how wud i go about this? pls help

    tony

  4. tony Says:
    October 3rd, 2008 at 7:57 am

    any one? please

  5. rigo Says:
    October 12th, 2008 at 7:56 pm

    Very useful tip, thanks to Julz and Admin

Leave a Reply

  • RSS Feed
  • Categories

    • apache
    • barcode
    • creloaded
    • curl
    • customer services
    • debugging
    • ecommerce
    • email
    • excel
    • firefox
    • flash
    • gd
    • graphs
    • hosting
    • icecat
    • internet news
    • javascript
    • link building
    • linux
    • magento
    • management
    • mod_rewrite
    • mysql
    • oscommerce
    • php
    • plesk
    • product catalogue
    • product feed
    • programming
    • regular expressions
    • scraping
    • search engine optimisation
    • security
    • spidering
    • ubuntu
    • web design
    • web development
    • Windows
    • xampp
    • zip
  • Archives

    • September 2008
    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
  • Tags

    addons advanced adverts blackhat blocking css curl development directories find firefox google hosts file html javascript keywords links msn mysql myths operators oscommerce paid links paid placement performance php ppc reciprocal linking replace screen scraping security seo serp speed spider spidering tuning user friendly vista web web design web developer
  • Random Posts

    • PHP Generated SQL
    • 10 SEO Myths
    • Faster File Browsing with Tabs for Ubuntu
    • Essential Search Engine Optimisation Research Tool
    • PHP Random Sleep Function with Flush
    • PHP: Recursive Create Path (if not exists)
    • Advanced Google Search Queries
    • EAN13 Barcode Check Digit with PHP
    • Securing a LAMP Server with mod_security
    • Ecommerce Back Office Optimisations

Edmonds Commerce related questions? Send us a message or call us on 0844 357 0201.

Freelance PHP Web Design UK Commercial Web Design