简体   繁体   English

同步2个数据库

[英]Synchronizing 2 databases

I have a database in MySQL and another database that runs on MS SQL. 我有一个MySQL数据库和另一个在MS SQL上运行的数据库。 The MySQL is the backend database for my website running on Joomla. MySQL是我在Joomla上运行的网站的后端数据库。 I have an ERP running my store. 我的商店正在运行ERP。 This ERP is made by a 3rd party in .Net 该ERP由.Net中的第3方创建

A table called the orders gets updated whenever a user places an order in my website. 每当用户在我的网站上下the orders时,称为the orders的表都会更新。 The order details must get flushed to my orders table in my ERP. 订单明细必须刷新到我的ERP中的orders表中。 The table structure in the two databases are totally different so I will do the mapping myself. 两个数据库中的表结构完全不同,因此我将自己进行映射。

My questions are: 我的问题是:

  1. How frequently should I transfer the data from my MySQL database to MS SQL? 我应该多久将数据从MySQL数据库传输到MS SQL?
  2. Someone suggested that I could write a web service that would periodically pump data to my table in the ERP. 有人建议我可以编写一个Web服务,该服务会定期将数据泵到ERP中的表中。 So I started thinking about Nusoap webservices. 因此,我开始考虑Nusoap Web服务。 Is this the right way or is there a better way to do it ?? 这是正确的方法还是有更好的方法呢?
  3. I will also have to retrieve inventory-related information from my ERP to my MySQL database. 我还必须从ERP到MySQL数据库检索与库存相关的信息。

1: Depends on how often your data is changing, and how often you need to sync up (ie, depends on your business). 1:取决于数据更改的频率以及您需要同步的频率(即,取决于您的业务)。

2 & 3: A web service to transfer data could work just fine. 2&3:传输数据的Web服务可以正常工作。 But unless you're trying to come up with a general solution, this sounds like a lot more trouble than it's worth. 但是,除非您试图提出一个通用的解决方案,否则这听起来比实际值要麻烦得多。

If I were doing this, I would export the data from Sql Server to a file, then import that file into mysql ( mysql my_db < file.sql ). 如果执行此操作,则将数据从Sql Server导出到文件中,然后将该文件导入mysql( mysql my_db < file.sql )。

Getting data OUT of sql server in this format isn't so easy (there's no equivalent to mysqldump on Sql Server). 以这种格式获取sql server的数据并不是那么容易(没有Sql Server上的mysqldump等效)。 But check out this question for some ideas. 但是,请查看此问题以获取一些想法。

If the data itself is compatible between systems (if the columns are equivalent data types), you can overcome the table structure differences by just creating a query in SQL Server which exports the data in the correct order. 如果数据本身在系统之间是兼容的(如果列是等效的数据类型),则可以通过仅在SQL Server中创建一个按正确顺序导出数据的查询来克服表结构的差异。

In fact, you may be able to create a query who's output is the file.sql for import into mysql. 实际上,您也许可以创建一个查询,该查询的输出要导入到mysql中的file.sql。 For example, a query such as: 例如,查询如下:

SELECT CONCAT(
    'INSERT INTO MYTABLE VALUES (', 
    myColumn, 
    ',', 
    myOtherColumn,
    ');'
) AS SQL_STATEMENT

Produces output something like: 产生如下输出:

INSERT INTO MYTABLE VALUES (myColumnValue1, myOtherColumnValue1);    
INSERT INTO MYTABLE VALUES (myColumnValue2, myOtherColumnValue2);    
....

I've exported data from sql server that way on at least one occasion. 我至少有一次从sql server中导出了数据。

  1. How up to date do you need the ms sql database. 您如何最新需要ms sql数据库。 That is going to be the deciding factor 这将是决定性因素
  2. I don't see any huge advantage to this being a web service. 对于Web服务,我没有看到任何巨大的优势。
  3. This isn't a question. 这不是问题。

Deciding how often you transfer the order across is a business decision not a technical one. 确定跨订单转移的频率是一项业务决定,而不是技术决定。 But it is hard to see what competitive advantage you might gain from not processing your customers' orders as soon as possible, so it ought to be a no brainer. 但是很难看到不尽快处理客户的订单会获得什么样的竞争优势,因此应该毫不费力。

Without knowing a lot more about your infrastructure and architecture we cannot give you definitive advice about approach. 在不了解您的基础架构和体系结构的情况下,我们无法为您提供有关方法的明确建议。 I would expect a decently written ERP package to include interfaces for importing and exporting information. 我希望编写一个体面的ERP软件包,包括用于导入和导出信息的接口。 Alas such expectations are often confounded. such,这样的期望经常被混淆。 If you do need to write your own interface, avoid web services. 如果确实需要编写自己的界面,请避免使用Web服务。 Unless you have a very peculiar set-up all WS will mean is that it will take longer to satisfy your customers. 除非您有非常特殊的设置,否则所有WS都意味着需要更长的时间才能满足客户的需求。 I think we have already agreed that is not a good idea. 我认为我们已经同意这不是一个好主意。

Considerations for a Syncronization API: 同步API的注意事项:

  1. You need to track which new orders have not been transferred to the ERP database. 您需要跟踪哪些新订单尚未转移到ERP数据库。 A flag is clumsy, a queue is perhaps more elegant. 旗帜很笨拙,队列也许更优雅。
  2. Have a job/daemon polling continuously to identify orders which need to be transferred and transfer them in near-real time. 连续进行作业/守护程序轮询,以识别需要转移的订单,并以近实时的方式进行转移。
  3. Have a plan for handling the unavailability of the ERP database. 有一个计划来处理ERP数据库的不可用。
  4. Construct the mapping in a modular fashion so you do not have to rewrite the entire thing just because of a change to the structure of one of your tables. 以模块化的方式构造映射,因此您不必仅因为其中一个表的结构更改而重写整个过程。
  5. The inventory data will probably have to be pulled from the MySQL database, as it seems unlikely that the third party will allow you to put code into their database. 库存数据可能必须从MySQL数据库中提取,因为第三方似乎不太可能允许您将代码放入其数据库中。 But it's worth reading the contract. 但是值得阅读合同。

Okay based on the replies I got I will rephrase my question giving more details. 好的,根据我得到的答复,我将重述我的问题,并提供更多详细信息。

I have an eCommerce portal running on Joomla and Virtue mart (never mind what they are !!) The backend database here is MySQL. 我有一个在Joomla和Virtue mart上运行的电子商务门户(不管它们是什么!!),这里的后端数据库是MySQL。 I have an erp written in .net by my friend and the Db used there is MSSQL Now I am going to host my eCommerce portal. 我有一个由朋友用.net编写的erp,使用的Db是MSSQL现在,我将托管我的电子商务门户。

Following are actions that will take place and questions related to the actions 以下是将要采取的行动以及与这些行动有关的问题

Action 1: At the start of the day my friend updates inventory of various products on and erp table question: I want the updated inventory from the erp (MS SQL) to get reflected on my website database (MySQL) automatically. 动作1:在一天开始时,我的朋友更新了erp表和erp表上的各种产品的库存:我希望erp(MS SQL)中更新的库存自动反映在我的网站数据库(MySQL)中。 How do I do it ? 我该怎么做 ?

Action 2: People come to my site and place orders.These orders are stored in an order table in my website(MYSQL). 动作2:人们来到我的网站并下订单。这些订单存储在我的网站(MYSQL)的订单表中。 Question 2: I want these update orders related data from my website (MySQL) to be updated on a corresponding table in my erp (MS SQL) 问题2:我希望在我的erp(MS SQL)的对应表上更新来自我的网站(MySQL)的这些与更新订单相关的数据

More over the db structures of the tables in my erp and my website are completely different 关于我的erp和我的网站中表的数据库结构的更多信息完全不同

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

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