Implementation code for PHP MySQL database replication

Source: Internet
Author: User
    1. --
    2. --Database: ' Db_copy_old '
    3. --
    4. --
    5. --The structure of the table ' article '
    6. --
    7. CREATE TABLE IF not EXISTS ' article ' (
    8. ' ID ' int (a) is not NULL auto_increment,
    9. ' title ' text character set UTF8 not NULL,
    10. ' Content ' text character set UTF8 not NULL,
    11. PRIMARY KEY (' id ')
    12. ) Engine=innodb DEFAULT CHARSET=GBK auto_increment=4;
    13. --
    14. --Dump the data in the table ' article '
    15. --
    16. INSERT into ' article ' (' id ', ' title ', ' content ') VALUES
    17. (1, ' Test 001 ', ' Content 001 '),
    18. (2, ' Test 002 ', ' content 002 '),
    19. (3, ' Test 003 ', ' content 003 ');
Copy Code

2, import the data from table article in database db_copy_old into the table article_new in the database db_copy_new to achieve replication between database tables:

    1. CREATE TABLE article_new like db_copy_old.article;
    2. INSERT article_new SELECT * from Db_copy_old.article;
Copy Code
  • 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.