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 6846249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:35:55+00:00 2026-05-27T00:35:55+00:00

I am using MySQL v5.1. I am developing a Rails app. and writing a

  • 0

I am using MySQL v5.1.

I am developing a Rails app. and writing a ruby script to copy database. So far, I have got an array of table names, the number of tables is 2090. I need to create all the tables in a new database, my code looks like:

#"table_names" is fetched by execute 'show tables' SQL commands

 table_names.each { |tbl_name|
     ActiveRecord::Base.connection.execute("CREATE TABLE #{new_db_name}.#{tbl_name} LIKE #{old_db_name}.#{tbl_name}")

  }

This code works, but it took a long time to complete, because the code has to execute the CREATE TABLE command one by one and there are 2090 tables to create.

I am wondering is there any way to have bulk creating of tables (like bulk inserting of data) in SQL to save the time? If not, how can I improve the speed of creating the tables? That’s copy all 2090 tables from one database to another.

P.S. I don’t want to hard code all 2090 table names in SQL file.

  • 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-27T00:35:55+00:00Added an answer on May 27, 2026 at 12:35 am

    Simplest method in mysql is to do a mysqldump of the database in question, then restore it to the new database, e.g:

    mysql_dump -pPASSWORD -uUSERNAME name_of_db > name_of_db.sql
    mysql -pPASSWORD -uUSERNAME name_of_db < name_of_db.sql
    

    the dump file will contain all the necessary DDL/DML queries to recreate the database, plus disabling foreign keys and whatnot so that the dump can be loaded without causing any foreign key problems while the restored DB is in a halfway state.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing Rails v2.3 app. and using MySQL v5.1 . I need to
I am developing Rails v2.3 app. and using MySQL v5.1 on Ubuntu machine. I
I have Rails 2.3.8, Ruby 1.8.7, Mongrel Web Server and MySQL database. I am
I'm developing a PHP web app using a MySQL database. I'm wondering what is
I'm currently developing a website which stores bookmarks in a MySQL database using PHP
I'm developing a class to manage the operations on a Mysql database. I have
I'm developing a website using PHP, MySQL and HTML. In the database, one of
I am developing a Diary Management Script using PHP and MySQL. I am stuck
I'm developing a J2EE 6 Web Application, using a MySql 5.02 DataBase. I'm trying
I am currently developing a PUBLIC and OPEN SOURCE software using PHP/MySQL. I have

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.