macos 使用 Python 连接到远程 sqlite3 数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2318315/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:46:56  来源:igfitidea点击:

Connect to a remote sqlite3 database with Python

pythonmacossqlite

提问by cit

I am able to create a connection to a local sqlite3 database ( Using Mac OS X 10.5 and Python 2.5.1 ) with this:

我可以通过以下方式创建到本地 sqlite3 数据库的连接(使用 Mac OS X 10.5 和 Python 2.5.1):

conn = sqlite3.connect('/db/MyDb')

How can I connect to this database if it is located on a server ( for example on a server running Ubuntu 8.04 with an IP address of 10.7.1.71 ) , and is not stored locally?

如果该数据库位于服务器上(例如,在运行 Ubuntu 8.04 且 IP 地址为 10.7.1.71 的服务器上)并且未存储在本地,我该如何连接到该数据库?

e.g. this does not seem to work:

例如,这似乎不起作用:

conn = sqlite3.connect('10.7.1.71./db/MyDb')

回答by Ignacio Vazquez-Abrams

SQLite is embedded-only. You'll need to mount the remote filesystem before you can access it. And don't try to have more than one machine accessing the SQLite database at a time; SQLite is not built for that. Use something like PostgreSQL instead if you need that.

SQLite 是嵌入式的。您需要先挂载远程文件系统,然后才能访问它。并且不要尝试让多台机器同时访问 SQLite 数据库;SQLite 不是为此而构建的。如果需要,请改用 PostgreSQL 之类的东西。

回答by Peter Hansen

The sqlite FAQ has an answer relevant to your question. It points out that although multi-machine network access is theoretically possible (using a remote filesystem) it likely won't be reliable unless the filesystem properly supports locks.

sqlite FAQ 有一个与您的问题相关的答案。它指出,尽管理论上可以进行多机网络访问(使用远程文件系统),但除非文件系统正确支持锁,否则它可能不可靠。

If you're accessing it from only one machine and process at a time, however, it should work acceptably, as that page notes (and dependent on the remote filesystem you're using).

但是,如果您一次只从一台机器访问它并处理它,那么它应该可以正常工作,如该页面所述(并且取决于您使用的远程文件系统)。