简体   繁体   English

将表和列从 mysql 数据库复制到另一个

[英]Replicating tables and columns from a mysql database to another

My objective is to duplicate the tables and columns with constraints included from one database to another within a mysql server.我的目标是将包含约束的表和列从一个数据库复制到 mysql 服务器中的另一个数据库。

Is there any query possible for this purpose ?是否有任何可能用于此目的的查询?

This has to be done without copying the table data from one database to another.这必须在不将表数据从一个数据库复制到另一个数据库的情况下完成。

You can achieve the same by using the two methods mentioned below:您可以使用下面提到的两种方法来实现相同的效果:

  1. Use CREATE TABLE new_table LIKE other_db_name.other_table;使用CREATE TABLE new_table LIKE other_db_name.other_table;

  2. You can check the create statement by SHOW CREATE TABLE and copy that statement to create a new table without copying the data.您可以通过SHOW CREATE TABLE检查 create 语句并复制该语句以创建新表而不复制数据。

I hope it helps!我希望它有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM