简体   繁体   English

是否可以使用某些查询将记录从一台服务器上的一个数据库表复制到另一台服务器上的另一数据库表? (两个表完全相同)

[英]is it possible to copy records from one db table on one server to another db table on another server using some query? (both tables are exactly same)

I want to get data from our production server to my local development server for testing purposes. 我想将数据从生产服务器发送到本地开发服务器以进行测试。 I was wondering if there is any way by which I can copy records from prod server's db table to my local db table using SQL query. 我想知道是否可以通过任何方式使用SQL查询将记录从生产服务器的db表复制到本地db表。 The tables are exactly same in terms of column names and datatypes. 这些表在列名和数据类型方面完全相同。

I know that I can do it by taking dump to a file and then loading using infile. 我知道我可以通过将转储到文件然后使用infile加载来做到这一点。 Although I am using MySQL, I would like to know if it is possible to do it in other databases as well and if yes, how? 尽管我使用的是MySQL,但我想知道是否也可以在其他数据库中使用它,如果可以,怎么办?

As for MySQL, probably the easiest way to do with would be with mysqladmin ( link ): 对于MySQL,最简单的方法可能是使用mysqladminlink ):

mysqladmin create db_name
mysqldump -h 'other_hostname' --compress db_name | mysql db_name

With DB2, you can do this with 3-part table names ( subsystem.authid.object ), as long as your DBA has defined access to the remote subsystem. 使用DB2,只要您的DBA定义了对远程子系统的访问权限,就可以使用三部分表名( subsystem.authid.object )来完成此操作。

In order for this to work, the DB2 doing the forwarding must be on Z/OS. 为了使其正常工作,进行转发的DB2必须在Z / OS上。 DB2 L(inux)U(nix)W(indows) does not support this feature. DB2 L(inux)U(nix)W(indows)不支持此功能。 See here. 看这里。

The syntax is using INSERT mostly as with a normal insert: 语法通常与普通插入一起使用INSERT

INSERT INTO table (n1, n2, ... nx) 
SELECT n1, n2, ... nx
FROM subsystem.authid.object
WHERE ...

etc. 等等

In case of SQL Server , you can use a simple SELECT INTO statement if you define a linked server : 对于SQL Server ,如果定义了链接服务器 ,则可以使用简单的SELECT INTO语句:

SELECT Column1, Column2, ...
INTO dbo.TableName
FROM LinkedServerName.DatabaseName.dbo.TableName

All the major databases have a replication feature, or third party software that implements it. 所有主要数据库都具有复制功能或实现该功能的第三方软件。 It sounds like you're half a step away from needing all its features, so I'd suggest considering it! 听起来您距离需要其所有功能仅一步之遥,所以我建议您考虑一下! http://www.adderpit.com/practical-postgresql/x8695.htm http://www.adderpit.com/practical-postgresql/x8695.htm

Hope that helps 希望能有所帮助

It is Possible to insert data from one server database table to another server database table by using many ways (1) Oledb tranfer from the EXPORT and IMPORT utility This is the GUI base utility. 可以通过多种方式将数据从一个服务器数据库表插入到另一个服务器数据库表中(1)来自EXPORT and IMPORT实用程序的Oledb tranfer这是GUI基本实用程序。 (2) by Doing the Linked Server:- To Do this first You have to create a Link server in the Destination database of Source database. (2)通过执行链接服务器:-首先,您必须在Source数据库的Destination数据库中创建一个Link服务器。 Object Explorer => Server Object => Linked Server => New Linked Server => server name and login and the password 对象资源管理器=>服务器对象=>链接服务器=>新建链接服务器=>服务器名称和登录名以及密码

And then You can excess the tables of the other database in other server. 然后,您可以超出其他服务器中另一个数据库的表。

暂无
暂无

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

相关问题 如何将表从一个数据库复制到其他服务器的另一个数据库 - How to copy tables from one DB to another DB Of Different server 如何在PHP和MySQL中将几条记录从一台服务器上的表复制到另一台服务器上具有相同结构的表? - How to copy few records from a table on one server to the table with same structure on another server in PHP and MySQL? 将MySql DB从一台服务器复制到另一台服务器 - copy MySql DB from one server to another 在Java中将数据从一个数据库服务器复制到另一数据库服务器 - Data Copy From one db server to another db server in java Yii2 将表从一个数据库复制到另一个数据库 - Yii2 Copy table from one db to another db Drupal DB:必须通过在远程服务器上检查条件来将一些数据从一个表移动到另一个表。 - Drupal DB : Have to move some data from one table to another by cheking the condition at remote server..! 将一个表的外键约束复制到mysql中同一个数据库中的另一个 - copy the foreign key constraints of one table to another in the same db in mysql 仅将新记录从一个数据库服务器插入另一个数据库 - Inserting only new records from one db server to another 从一个表中获取数据列表,从另一个表中获取一些记录,是否可以在一个查询中执行? - Get the list of data from one table, and some count of records from another, is it possible to do in one query? 从一个mysql数据库复制到另一个,并将表数据分成不同的表 - copy from one mysql DB to another and separate table data into different tables
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM