Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy table between two models in Mysql workbench?

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?

like image 449
DraculaW Avatar asked Jun 15 '13 01:06

DraculaW


People also ask

How do I copy a table from one schema to another schema in MySQL?

Right-click on the database name then select "Tasks" > "Export data..." from the object explorer. 4. Provide authentication and select the source from which you want to copy the data; click "Next".

Can you copy a table from one database to another in MySQL?

Copy a table from one database to another. In MySQL, the easiest way to copy a table with its data between two databases is to use the CREATE TABLE AS statement, but note, that you need to provide the target database name as a table prefix. CREATE TABLE new-database-name. new-table-name AS SELECT * FROM old-database.


1 Answers

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

like image 156
Ricky Hewitt Avatar answered Sep 21 '22 23:09

Ricky Hewitt