将MYSQL数据库从一台计算机复制到另一台计算机 [英] Copy MYSQL Database from one computer to another in different networks
问题描述
我在一个系统中有一个源数据库。我想在另一个网络中的另一个系统中创建一个目标数据库(与Source数据库具有相同的模式)(两个系统都没有以任何方式连接)。
现在我们在系统1上创建一个转储但是我们正在通过C#寻找更好的解决方案。
我已经在系统1上创建了sqldump,现在我需要帮助我如何从系统1访问系统2以使用转储文件并创建目标数据库,或者我应该编写一个代码在系统2中运行,而系统2又转发system1数据库的转储?我应该如何解决这个问题?
创建目标数据库后,我将继续进行一些数据库验证,比较2个数据库并同步数据两者中。
所以我正在寻找一个C#解决方案。
任何想法?
PS在系统1上创建sqldump的代码:
I have a source database in one system. I want to create a target Database (with same schema as Source database) in another system in a different network (both systems are not connected in any way).
now we are creating a dump on system 1 and using a stick to copy it into system 2. But we are looking for a better solution through C#.
I have already created sqldump on system 1 and now I need help on how I can access the system 2 from system 1 to use the dump file and create a target database or should I be writing a code to be run in system 2 that in turn takes the dump of system1 database? how should I be going about with this?
I will go on further to do some database verification once the Target db is created, comparing the 2 databases and syncing the data among the two.
So I am looking for a C# solution.
any ideas?
P.S. code that creates sqldump on system 1:
string constring1 = "SERVER=localhost;" + "DATABASE=;" + "UID=root;" + "PASSWORD=;" + "Convert Zero Datetime=True;" +
"Allow Zero Datetime=True";
using (MySqlConnection conn = new MySqlConnection(constring1))
{
using (MySqlCommand cmd = new MySqlCommand())
{
using (MySqlBackup mb = new MySqlBackup(cmd))
{
cmd.Connection = conn;
conn.Open();
mb.ExportInfo.AddCreateDatabase = true;
mb.ExportInfo.ExportTableStructure = true;
mb.ExportInfo.ExportRows = false;
mb.ExportToFile(file1);
}
}
}
推荐答案
选项1:使用网络服务。
在服务器2上创建一个Web服务器并托管一个Web服务。
服务器1将通过字节[]发送(字节数组)通过Web服务到服务器2.
选项2:使用网页
在服务器2上,创建一个接受http帖子的ASP.NET网页。
服务器1将以编程方式访问网页并上传文件。
Server 2,一旦在网页上收到文件,ASP.NET引擎就会处理它。
选项3:打开一个在服务器2上使用C#的TCP客户端/服务器端口
在服务器2上创建一个C#套接字。
服务器1将连接套接字然后通过套接字将byte []传送到服务器2.
Option 1: By using web services.
Create a web server and host a web service at server 2.
Server 1 will send over the byte[] (byte array) to server 2 through the web service.
Option 2: By using a web page
At server 2, create a ASP.NET web page that accept a http post.
Server 1 will access the web page programmatically and upload the file.
Server 2, once the file received at the web page, ASP.NET engine will process it.
Option 3: By opening a TCP Client/Server port using C# at server 2
Create a C# Socket at server 2.
Server 1 will connect the socket then transmit the byte[] to server 2 through the socket.
这篇关于将MYSQL数据库从一台计算机复制到另一台计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!