title: mysql - how to copy table and keep same keys and encoding?
body: <p>Just wrote a short script of copying all my tables into another local database. was quite easy but after checking it I found that the keys are gone and also the encoding for text fields are set to some default encoding.</p>
  
  <p>How can I use my script and have the same keys and same encoding duplicated after copying, but not manually define for each table. I have to get this done automatically.</p>
  
  <p>my code is pretty straight forward:</p>
  
  <pre><code>$first_db = 'first_db';
  $second_db = 'second_db';
  
  
  $result = mysql_query("SHOW TABLES FROM $first_db");
  
  while ($row = mysql_fetch_array($result)){
      $current_table = $row["Tables_in_$first_db"];
      $result2 = mysql_query("DROP TABLE IF EXISTS $second_db.$table_name");
      $result2 = mysql_query("CREATE TABLE $second_db.$table_name SELECT * FROM $first_db.$current_table");
  } 
  </code></pre>
  
  <p>I think I should use ALTER TABLE, but can it find and define the keys and encoding automatically ?</p>
  
  <p>Thanks</p>