Batch generation of table on dev machine database

Source: Internet
Author: User

My inefficient approach:

Create from a local PHP script:

<?PHP//0-63Header("Content-type:text/html;charset=utf-8");$conn=mysql_connect(' localhost ', ' root ', ') or die(Mysql_error());$db=mysql_select_db(' Test ',$conn) or die(Mysql_error()); for($i= 10;$i<64;$i++){    $sql=<<<SQL CREATE TABLE karate_final_{$i}(
Xxxx
XXXX) ENGINE InnoDB auto_increment73DEFAULTCharset=utf8 comment= ' stored everyones info list '; SQL; mysql_query($sql,$conn) or die(Mysql_error($conn));}Mysql_close($conn);?>

Discovery efficiency is low, and because the dev connection speed is not stable, create to 9 is over.

New method:

Create the karate_final_tmp in the database of the dev machine and generate the SQL statements locally from the script.

CREATE TABLE  like karate_final_tmp;

Paste into Workbench, a total of 64, executed.

Like keyword: Creates a table that completely replicates the structure of the tables behind the like

You can also refer to the differences between the like and select keywords used here

1<?PHP2 //0-633 Header("Content-type:text/html;charset=utf-8");4 $conn=mysql_connect(' localhost ', ' root ', ') or die(Mysql_error());5 $db=mysql_select_db(' Test ',$conn) or die(Mysql_error());6 7  for($i= 0;$i<64;$i++){8     $sql. = <<<SQL9CREATE TABLE karate_final_{$i} like Karate_final_tmp;<br/>Ten SQL; One } A Mysql_close($conn); - Echo $sql; -?>

Batch generation of table on dev machine database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.