I want to copy table contained from one database and insert onto another database table

前端 未结 7 1843
你的背包
你的背包 2020-12-07 08:38

I want to copy a table\'s schema as well as the data within that table to another database table in another database on a live server. How could I do this?

相关标签:
7条回答
  • 2020-12-07 08:44

    CREATE TABLE db2.table_new AS SELECT * FROM db1.table_old

    0 讨论(0)
  • 2020-12-07 08:52

    In BASH you can do:

    mysqldump database_1 table | mysql database_2
    
    0 讨论(0)
  • 2020-12-07 08:53

    simply use -

    CREATE TABLE DB2.newtablename SELECT * FROM DB1.existingtablename;

    0 讨论(0)
  • 2020-12-07 08:59

    In Commandline:

    mysqldump -h localhost -u username -ppassword [SCHEMA] --tables [TABLE] | mysql -h otherhost -u username -ppassword [SCHEMA2]
    

    This will copy table inside SCHEMA on localhost to SCHEMA2 on otherhost.

    localhost and otherhost are just hostname and might be same or different.

    0 讨论(0)
  • 2020-12-07 09:00

    If you want to copy a table from one Database to another database , You can simply do as below.

    CREATE TABLE db2.table LIKE db1.table;
    INSERT INTO db2.table SELECT * FROM db1.table;
    
    0 讨论(0)
  • 2020-12-07 09:07

    or just CREATE TABLE db2.table SELECT * FROM db1.table in MySQL 5

    0 讨论(0)
提交回复
热议问题