How to copy table between two models in Mysql work

2019-02-08 00:49发布

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?

7条回答
beautiful°
2楼-- · 2019-02-08 01:11

create table .m_property_nature like .m_property_nature;

INSERT INTO .m_property_nature SELECT * from .m_property_nature;

查看更多
聊天终结者
3楼-- · 2019-02-08 01:13

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.
查看更多
仙女界的扛把子
4楼-- · 2019-02-08 01:17
  1. Select tab with source database
  2. In menu: Server->Data Export
  3. Select Schema and the Table as Schema Object
  4. Select option Export to Self-Contained File and check Create Dump in a Single Transaction (self-contained only)
  5. Copy full file path to clipboard
  6. Start Export
  7. Select tab with target database
  8. In menu: Server->Data Import. Make sure your target database name is at the top left corner of the Data Import view
  9. Select Import from self contained file and paste full file path from clipboard
  10. Select Default Target Schema
  11. Select Dump Content (Dump Structure and Data etc…)
  12. Start Import
查看更多
走好不送
5楼-- · 2019-02-08 01:20

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.
查看更多
三岁会撩人
6楼-- · 2019-02-08 01:22

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.

查看更多
一夜七次
7楼-- · 2019-02-08 01:24

If you just want to do a single table through the MySQL Workbench.

In MySQL Workbench:

  1. Connect to a MySQL Server
  2. Expand a Database
  3. Right Click on a table
  4. Select Copy To Clipboard
  5. Select Create Statement

A create statement for the table will be copied to your clipboard similar to the below:

   CREATE TABLE `cache` (
  `cid` varchar(255) NOT NULL DEFAULT '',
  `data` longblob,
  `expire` int(11) NOT NULL DEFAULT '0',
  `created` int(11) NOT NULL DEFAULT '0',
  `headers` text,
  `serialized` smallint(6) NOT NULL DEFAULT '0',
  PRIMARY KEY (`cid`),
  KEY `expire` (`expire`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Create the table in the new database

  1. Open a new SQL tab for executing queries (File->New Query Tab)
  2. Alter the create table code to include the database to create the table on.

     CREATE TABLE `databaseName`.`cache` (
      `cid` varchar(255) NOT NULL DEFAULT '',
      `data` longblob,
      `expire` int(11) NOT NULL DEFAULT '0',
      `created` int(11) NOT NULL DEFAULT '0',
      `headers` text,
      `serialized` smallint(6) NOT NULL DEFAULT '0',
      PRIMARY KEY (`cid`),
      KEY `expire` (`expire`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

  3. Then click the Execute button (looks like a lightening Bolt)

That will copy the table schema from one db to another using the MySQL workbench. Just refresh the tables in the database and you should see your newly added table

查看更多
登录 后发表回答