Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5931627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:43:17+00:00 2026-05-22T14:43:17+00:00

I have a LIVE version of a MySQL database with 5 tables and a

  • 0

I have a LIVE version of a MySQL database with 5 tables and a TEST version.

I am continually using phpMyAdmin to make a copy of each table in the LIVE version to the TEST version.

Does anyone have the mysql query statement to make a complete copy of a database? The query string would need to account for structure, data, auto increment values, and any other things associated with the tables that need to be copied.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:43:17+00:00Added an answer on May 22, 2026 at 2:43 pm

    Ok, after a lot of research, googling, and reading through everyone’s comments herein, I produced the following script — which I now run from the browser address bar. Tested it and it does exactly what I needed it to do. Thanks for everyone’s help.

    <?php
    function duplicateTables($sourceDB=NULL, $targetDB=NULL) {
        $link = mysql_connect('{server}', '{username}', '{password}') or die(mysql_error()); // connect to database
        $result = mysql_query('SHOW TABLES FROM ' . $sourceDB) or die(mysql_error());
        while($row = mysql_fetch_row($result)) {
            mysql_query('DROP TABLE IF EXISTS `' . $targetDB . '`.`' . $row[0] . '`') or die(mysql_error());
            mysql_query('CREATE TABLE `' . $targetDB . '`.`' . $row[0] . '` LIKE `' . $sourceDB . '`.`' . $row[0] . '`') or die(mysql_error());
            mysql_query('INSERT INTO `' . $targetDB . '`.`' . $row[0] . '` SELECT * FROM `' . $sourceDB . '`.`' . $row[0] . '`') or die(mysql_error());
            mysql_query('OPTIMIZE TABLE `' . $targetDB . '`.`' . $row[0] . '`') or die(mysql_error());
        }
        mysql_free_result($result);
        mysql_close($link);
    } // end duplicateTables()
    duplicateTables('liveDB', 'testDB');
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a live MySQL database that is 99% INSERTs, around 100 per second.
I have a live search on my help page that searches our help database
I have a live database that had some data deleted from it and I
I have around 400 GB Live mysql Databases on one server and I like
My goal is to stop having to have a local copy and a live
I have an ASP.NET AJAX page that for some reason on the LIVE version
I have 2 copies of my website synced with Subversion. One live version and
I have simple console application project for live video streaming using cross-platform libs on
I have a fairly small MySQL database (a Textpattern install) on a server that
I have MySQL with below settings Server version: 5.0.77 MySQL client version: 5.0.41 Protocol

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.