title: copy tables between databases
body: <p>I am using MySQL v5.1.</p>
  
  <p>I am developing a <strong>Rails</strong> app. and writing a <strong>ruby</strong> 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:</p>
  
  <pre><code>#"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}")
  
    }
  </code></pre>
  
  <p>This code works, but it took a long time to complete, because the code has to execute the <code>CREATE TABLE</code> command one by one and there are 2090 tables to create.</p>
  
  <p>I am wondering is there any way to have <strong>bulk creating</strong> of tables (like <strong>bulk inserting</strong> 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>
  
  <p><strong>P.S.</strong> I don't want to hard code all 2090 table names in SQL file.</p>