How to copy table between two models in Mysql workbench?

后端 未结 9 1893
小鲜肉
小鲜肉 2020-12-28 14:42

I am doing some databese thing, I need copy one table from one model to another, but i try many ways there no effect. Is there any way for doing this?

相关标签:
9条回答
  • 2020-12-28 15:20

    If you already have your table created and just want to copy the data, I'd recommend using the "Export Data Wizard" and "Import Data Wizard". It is basically choosing stuff in the program for exporting and then importing the data and is easy to use.

    MySQL has an article on the wizards here: Table Data Export and Import Wizard

    To copy data using the wizards, do the following:

    1. Find the table in the list from which you want to copy data from.
    2. Right click and choose "Table Data Export Wizard."
    3. Choose the columns you wish to copy.
    4. Choose a location to save a *.csv or *.json file with the copied data.

    5. Find the table to insert the copied data to.

    6. Right click and choose "Table data import wizard".
    7. Choose the file you just exported.
    8. Map the columns from the table you copied from to the table you insert to.
    9. Press "Finish". The data is inserted as you chose.
    0 讨论(0)
  • 2020-12-28 15:21

    Your best option is probably to create a stripped down version of the model that contains the objects you want to carry over. Then open the target model and run File -> Include Model.... Select the stripped down source model and there you go.

    0 讨论(0)
  • 2020-12-28 15:24

    You can just use a select statement. Here I am creating a duplicate of "original_table" table from the "original_schema" schema/database to the "new_schema" schema :

    CREATE TABLE new_schema.duplicate_table AS
    Select * from original_schema.original_table;
    

    You can just put any select statement you need ,add a condition and select the columns :

    CREATE TABLE new_schema.duplicate_table AS
    SELECT column1, column2       
    FROM original_schema.original_table
    WHERE column2 < 11000000;
    
    0 讨论(0)
  • 2020-12-28 15:25

    I think it is worth mentioning that

    1. a copied table may reference fields in tables of the original schema, that do not exist, in the schema where it's to be copied. It might be a good idea, to inspect the table for these discrepancies, before adding it to the other schema.
    2. it's probably a good idea, to check engine compatibility (e.g. InnoDB vs MyISAM) and character set.
    0 讨论(0)
  • 2020-12-28 15:31

    create table .m_property_nature like .m_property_nature;

    INSERT INTO .m_property_nature SELECT * from .m_property_nature;

    0 讨论(0)
  • 2020-12-28 15:32

    You can get the crate table query from table info and use the same query on different database instance.

    1. show create table TABLENAME.content and copy the query;
    2. Run the generated query on another Db instance connected.
    0 讨论(0)
提交回复
热议问题