move table from one schema to another schema ?

MysqlDatabase

Mysql Problem Overview


I want to move table from one schema to another schema in mysql , can anybody tell me how can I do this .

Mysql Solutions


Solution 1 - Mysql

If both schema is on same server then Alter table can be used to move tables from one db to another.

alter table old_db.fooTable rename new_db.fooTable

Solution 2 - Mysql

Moving tables with space characters in between should be enclosed.

Example:

ALTER TABLE `schema1`.`tbl somename` 
RENAME TO  `schema2`.`tbl somename` ;

Solution 3 - Mysql

Moving fooTable from old_db_schema to new_db_schema will be a 2 step process:

Step 1:

CREATE SCHEMA new_db_schema --Assuming you do not have new schema
GO

Step 2:

ALTER SCHEMA new_db_schema
TRANSFER old_db_schema.fooTable 
GO

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionp27View Question on Stackoverflow
Solution 1 - MysqlHarry JoyView Answer on Stackoverflow
Solution 2 - MysqlKruti MehtaView Answer on Stackoverflow
Solution 3 - MysqljaiveeruView Answer on Stackoverflow