macos 将 MySQL 转移到 SQLite
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1665061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Transfer MySQL to SQLite
提问by nevan king
I want to start using Core Date on iPhone with pre-existing MySQL databases. What's the easiest way to transfer a MySQL database to SQLite?
我想开始在 iPhone 上使用 Core Date 和预先存在的 MySQL 数据库。将 MySQL 数据库转移到 SQLite 的最简单方法是什么?
I've tried using SQLite Migrator, but I don't know where to find the ODBC drivers for Mac (Snow Leopard). I found http://www.ch-werner.de/sqliteodbc/which seems to have drivers, but they are for Power PC.
我试过使用 SQLite Migrator,但我不知道在哪里可以找到 Mac (Snow Leopard) 的 ODBC 驱动程序。我发现http://www.ch-werner.de/sqliteodbc/似乎有驱动程序,但它们适用于 Power PC。
If someone could give me a walkthrough, or tell me what the best tools for this are, I'd be grateful.
如果有人能给我一个演练,或者告诉我最好的工具是什么,我将不胜感激。
Thanks.
谢谢。
采纳答案by nevan king
To do my conversions, I ended up using an ODBC from Actual Access. I think I used it in combination with SQLite Migrator. I never liked this way though it was always clunky. Expensive too, it ended up costing about $80 for those two pieces of software.
为了进行转换,我最终使用了来自 Actual Access的ODBC。我想我将它与SQLite Migrator结合使用。我从不喜欢这种方式,尽管它总是很笨重。也很贵,这两个软件最终要花费大约 80 美元。
If I had to do this again, I'd buy SQLiteConverterby SQLabs. I use their SQLite Manager, and although it has a lot of interface problems, for database software it's not bad.
如果我不得不再次这样做,我会购买SQLabs的 SQLiteConverter。我使用他们的 SQLite Manager,虽然它有很多接口问题,但对于数据库软件来说还不错。
回答by Mike Willekes
Perhaps the simplest would be to use mysqldumpto dump the raw SQL from your MySQL database into a text file and then use the sqlite3_exec()function to execute that SQL in order to populate the SQLite database.
也许最简单的方法是使用mysqldump将 MySQL 数据库中的原始 SQL 转储到文本文件中,然后使用sqlite3_exec()函数执行该 SQL 以填充 SQLite 数据库。
回答by cethegeek
Have you looked at this Perl script? I haven't used it - just did a quick search for mysql to sqlite migration and it popped right up.
你看过这个 Perl 脚本吗?我没有用过它——只是快速搜索了 mysql 到 sqlite 的迁移,它就弹出了。
Edit (after you replied to my comment):
编辑(在您回复我的评论后):
The reverse direction is dealt with here.
If you are going to do it repeatedly and if data structure changes are to happen, maybe you would be better off using something like Django(albeit in a very hackish way). With it I would:
如果您要重复执行此操作并且要发生数据结构更改,也许您最好使用Django 之类的东西(尽管以一种非常hackish 的方式)。有了它,我会:
# This three lines are done once
django-admin.py startproject mymigrationproject
cd mymigrationproject
./manage.py startapp migration
# The following lines you repeat each time you want to migrate the data
edit settings.py and make the changes to connect to MySQL
./manage.py inspectdb > ./migration/models.py
edit ./migration/models.py to reorder tables (tables in which other tables depend on top)
mkdir fixtures
./manage.py dumpdata migration > ./fixtures/data.json
edit settings.py and make the changes to connect to SQLite
./manage.py syncdb
./manage.py loaddata ./fixtures.data.json
回答by David d C e Freitas
Here is a list of converters:
以下是转换器列表:
一种可以很好地工作但很少提及的替代方法是:使用 ORM 类为您抽象出特定的数据库差异。例如你在 PHP 中得到这些(RedBeanRedBean), Python (Django 的 ORM 层,Storm风暴,SqlAlchemySqlAlchemy)、Ruby on Rails (ActiveRecordActiveRecord), 可可 (CoreData核心数据)
i.e. you could do this:
即你可以这样做:
- Load data from source database using the ORM class.
- Store data in memory or serialize to disk.
- Store data into source database using the ORM class.
- 使用 ORM 类从源数据库加载数据。
- 将数据存储在内存中或序列化到磁盘。
- 使用 ORM 类将数据存储到源数据库中。
回答by Paul Lefebvre
You can get ODBC drivers for Mac OS X from Actual Technologies.
您可以从 Actual Technologies 获取适用于 Mac OS X 的 ODBC 驱动程序。
To connect to MySQL you need their ODBC Driver for Open Source Databases:
要连接到 MySQL,您需要用于开源数据库的 ODBC 驱动程序:
http://www.actualtech.com/product_opensourcedatabases.php
http://www.actualtech.com/product_opensourcedatabases.php
(Disclaimer: I am the author of SQLite Migrator)
(免责声明:我是 SQLite Migrator 的作者)
回答by Pavlo Svirin
You can use a trial from http://www.sqlmaestro.com/products/sqlite/datawizard/
您可以使用来自http://www.sqlmaestro.com/products/sqlite/datawizard/的试用版
It is completely functional for 30 days.
它可以完全正常运行 30 天。
回答by Greg
There is a free ETL product that can be used to migrate data from one db to another. Have a look: http://www.talend.com/index.php
有一个免费的 ETL 产品可用于将数据从一个数据库迁移到另一个数据库。看看:http: //www.talend.com/index.php
Good luck!
祝你好运!