2

The problem is: I've got a SQLite database which is constantly being updated though a proprietary application.

I'm building an application which uses MySQL and the database design is very different from the one of SQLite.

I then have to copy data from SQLite to MySQL but it should be done very carefully as not everything should be moved, tables and fields have different names and sometimes data from one table goes to two tables (or the opposite).

In short, SQLite should behave as a client to MySQL inserting what is new and updating the old in an automated way. It doesn't need to be updating in real time; every X hours would be enough.

A google search gave me this: http://migratedb.sourceforge.net/

And asking a friend I got information about the Multisource plugin (Squirrel SQL) in this page: http://squirrel-sql.sourceforge.net/index.php?page=plugins

I would like to know if there is a better way to solve the problem or if I will have to make a custom script myself.

Thank you!

4

2 回答 2

1

我为此推荐一个自定义脚本:

  1. 如果不是表和字段之间的一对一转换,那么工具可能无济于事。在你的问题中,你说:

    ...有时来自一个表的数据会转到两个表(或相反)。

  2. 如果您只想要差异,那么您需要为此构建逻辑,除非 SQLite 数据库中的每条记录都有时间戳。

  3. 你要更新 MySQL 数据库吗?如果没有,您可以完全删除 MySQL 数据库并使用 SQLite 中的所有数据每 X 小时刷新一次吗?

此外,如果您对脚本语言(如 php、python、perl、ruby 等)感到满意,它们有 SQLite 和 MySQL 的 API;构建自己的脚本很容易,您可以根据程序逻辑更轻松地控制自定义。特别是如果您想在数据之间运行“转换”,而不仅仅是简单的映射。

于 2012-09-14T06:55:06.360 回答
0

我希望我对您的理解正确,您将定期将存储在 SQLite DB 中的数据刷新到 MySQL DB。正确的?

所以我会这样做。

  1. 创建一个 Cron,它每 x 分钟启动一次脚本。
  2. 将 SQLite 中的数据导出到 CSV 文件中。
  3. LOAD DATA INFILECSV 数据导入 MySQL

代码示例LOAD DATA INFILE

LOAD DATA INFILE 'PATH_TO_EXPORTED_CSV' REPLACE INTO TABLE your_table FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES ( @value_column1, @unimportend_value, @value_column2, @unimportend_value, @unimportend_value, @value_column3) SET diff_mysql_column1 = @value_column1, diff_mysql_column2 = @value_column2, diff_mysql_column3 = @value_column3);

这段代码你可以查询到你想要的尽可能多的数据库表。您也可以更改变量@value_column1。我很急。现在就是这样。询问是否有不清楚的地方。问候迈克尔

于 2012-09-14T06:12:41.717 回答