How to copy a table from one mysql database to another mysql database

前端 未结 12 1512
一个人的身影
一个人的身影 2020-12-07 21:03

I need to copy a table from one database to another. This will be a cronjob. Which one is the best way to do it? PHP script or Shell Script. The problem with PHP, both datab

12条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 21:51

    If you need to copy the table on the same server you can use this code:

    USE db2;
    
    CREATE TABLE table2 LIKE db1.table1;
    
    INSERT INTO table2  
        SELECT * FROM db1.table1;
    

    It's copy+pasted from here: codingforums.com

    It's not my solution, but I find it useful.

提交回复
热议问题