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

  • Home
  • SEARCH
  • 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 502177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:15:55+00:00 2026-05-13T06:15:55+00:00

I have two mysql databases that have almost the same structure and representing the

  • 0

I have two mysql databases that have almost the same structure and representing the data of the same web app but one of them represents the current version and second one was made long time ago.

How can I create the database with both dumps inside but with old_ prefix for tables from the first and new_ prefix for tables from the second database?

Is there any mysqldump options to setup the prefix or other solution?

  • 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-13T06:15:55+00:00Added an answer on May 13, 2026 at 6:15 am
    1. Restore both the databases as it is.
    2. Use the following stored procedure to move all the tables from one DB to another DB after adding the prefix.
    3. After moving delete the source database.

    This stored procedure gets the table list from MySQL’s inmemory tables in information_schema and automatically moves to another DB using the RENAME command.

    DELIMITER $$
    
    USE `db`$$
    
    DROP PROCEDURE IF EXISTS `renameDbTables`$$
    
    CREATE DEFINER=`db`@`%` PROCEDURE `renameDbTables`(
        IN from_db VARCHAR(20),
        IN to_db VARCHAR(30),
        IN to_name_prefix VARCHAR(20)
    )
    BEGIN
    /*
    call db.renameDbTables('db1','db2','db_'); 
    db1.xxx will be renamed to db2.db_xxx
    */
        DECLARE from_state_table VARCHAR(20) DEFAULT '';
        DECLARE done INT DEFAULT 0;
        DECLARE b VARCHAR(255) DEFAULT '';
        DECLARE cur1 CURSOR FOR SELECT TABLE_NAME FROM information_schema.TABLES 
            WHERE TABLE_SCHEMA=from_db;
        DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
    
        OPEN cur1;
    
        REPEAT
            FETCH cur1 INTO from_state_table;
            IF NOT done THEN
    --          select from_state_table;
                SET @QUERY = '';
                SET @QUERY = CONCAT(@QUERY,'RENAME TABLE ',from_db,'.', from_state_table,' TO ',to_db,'.', to_name_prefix, from_state_table,';');
    --          SELECT @query;
                PREPARE s FROM @QUERY;
                EXECUTE s;
                DEALLOCATE PREPARE s;
            END IF;
        UNTIL done END REPEAT;
        CLOSE cur1;
        END$$
    
    DELIMITER ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 294k
  • Answers 294k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer in iis7 it does not create "MSFTPSVC" folder in the… May 13, 2026 at 6:39 pm
  • Editorial Team
    Editorial Team added an answer Most people will never write any code that needs to… May 13, 2026 at 6:39 pm
  • Editorial Team
    Editorial Team added an answer I don't think you can use the is operator for… May 13, 2026 at 6:39 pm

Related Questions

We have an InnoDB database that is about 70 GB and we expect it
I'm beginning PHP development, and I'm looking at picking brains for ideas and best
I know this is not a straight up question, so if you need me
My experience with databases is with fairly small web applications, but now I'm working
Greetings All! I am having some troubles on how to execute thousands upon thousands

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.