This page is a translated version of the page Manual:SQLite and the translation is 68% complete.
Outdated translations are marked like this.
SQLite标志
SQLite标志

The purpose of this page is to collect information and experiences about running MediaWiki on SQLite.

MediaWiki supports SQLite since 1.17, but please note that this is second-class support, and you may likely run into some bugs. The database most commonly used with MediaWiki is MySQL . See Phabricator for a list of issues. MediaWiki requires SQLite 3.8.0 or later. Support for SQLite by extensions which make database changes is varied.

There are two important caveats to using SQLite for MediaWiki. First, while many extensions do support SQLite, there are some popular extensions that still do not support it to this day. Second, SQLite does not scale beyond one server. In case your wiki may grow to have many concurrent users and a large amount of content, it would be better to use a database system that supports the primary-replica model such as MySQL. As a result, if your wiki may depend on using these extensions, or it may need to use a primary-replica database system, it is best to use a MySQL database for your wiki. The decision to use SQLite, MySQL, or another database system should ideally be made before you create your wiki, as it is difficult to convert from a SQLite database to a MySQL database once you have started using your wiki.

关于SQLite

SQLite是一个发布到公共领域的开源数据库。 与客户端-服务器数据库管理系统不同,SQLite链入PHP的,因此成为不可或缺的一部分服务器进程。 MediaWiki通过简单的函数调用使用SQLite的功能,这减少了数据库访问中的潜伏,因为函数调用比进程间通信更有效。

使用SQLite作为MediaWiki的数据库后端有其自身的优点和缺点:

优点
  • 您不必安装和维护MySQL等独立数据库服务器,这大大减少了用于管理的工作并消除了一些失败点。
  • 前者也意味着SQLite更适合从USB记忆棒运行的便携式MediaWiki安装。
  • 您不受共享主机上的人为数据库限制的限制。
  • 整个数据库存储为单个跨平台文件,简化了备份和迁移。
缺点
  • SQLite不具备可扩展性,所以如果你有一个大而流行的wiki,你应该使用MySQL。
  • 虽然SQLite有自己的搜索引擎,但Lucene等更先进的解决方案并不支持它。
  • 已知有几个扩展具有SQLite的数据库更新或安装问题:AbuseFilter、Echo、Flow和LiquidThreads。

安装SQLite

至少需要SQLite 3.8.0+ 版。 此外,为了使用全文搜索,必须在启用FTS3模块的情况下编译SQLite(大多数版本现在都开箱即用)。 SQLite3通过PHP的PDO函数工作。

  • 要在基于Debian或Ubuntu的系统上安装SQLite3,请使用apt install php-sqlite3
  • 来自php.net的Windows二进制文件都可以。
  • 需要加载PHP PDO SQLite模块。 您应该在php.ini中取消注释以下两行
    • extension=pdo_sqlite
  • 你应该把SQLite数据库放在哪里?默认路径似乎是$IP/../data/$dbname.sqlite。 webroot之外的任何东西都应该是安全的,把它放在附近是件好事。或者,如果您愿意,可以将其放在Web根目录中,并确保使用服务器配置拒绝访问它。

在SQLite后端安装MediaWiki

  • 如果正确安装了适用于PHP的SQLite模块,MediaWiki安装程序(/mw-config/index.php)应该为您提供使用SQLite的选项。
  • 如果在SQLite数据目录字段中没有输入任何内容,则$wgSQLiteDataDir 将保留为空,这对应于文档根目录的父代中的data目录,但此目录可能与Web不同 脚本和维护脚本从命令行运行,因此建议明确指定它。

搜索引擎

MediaWiki版本:
1.16

MediaWiki 1.16中引入了SQLite后端的搜索功能。 它们需要SQLite编译的FTS3模块,这通常存在于大多数现代版本中。 如果您最近将SQLite支持更新为包含FTS3的版本,运行更新程序,就像您要升级MediaWiki一样。 updater脚本创建搜索索引表后,使用rebuildtextindex.php 填充它。 同样适用于切换回没有FTS3的环境:重新运行更新程序将降级表以避免SQL错误。

备份

如果您的wiki当前处于脱机状态,则只需复制数据库文件即可备份其数据库。 否则,你应该使用维护脚本php maintenance/SqliteMaintenance.php --backup-to <backup file name>,这将确保操作是原子的并且没有不一致。 如果您的数据库不是很大并且服务器没有负载很重,那么编辑维基的用户只会注意到短暂的延迟。 正在阅读的用户在任何情况下都不会注意到任何事情。

故障排除

无法访问终端上的数据库

要获得对数据库的命令行访问,请在终端上键入:

sqlite3 /var/data/database_name.sqlite

/var/data替换为在安装过程中设置为SQLite数据目录。 或者,在LocalSettings.php 中查找$wgSQLiteDataDir

如果您没有SQLite经验并运行sqlite3 database_name,这可能会很棘手,因为这将打开一个完全不同的数据库(如果它不存在则创建它),因为SQLite将该参数解释为不是系统全范围的数据库名称,而是作为包含db的文件名。

问题

应该将错误报告给维基媒体的错误跟踪器。 首先检查您的问题是否已经报告,检查#sqlite的依赖关系并使用搜索。 如果找不到问题,请创建新问题在任何情况下,请采取一些措施使您的错误易于查找和跟踪:提及SQLite是其摘要字段,并使其依赖于标签sqlite。

Performance Tips

  • If possible, ensure you have the APCu php extension installed and $wgMainCacheType set to CACHE_ACCEL. If no cache is present, MediaWiki will use the database as a cache backend, which can lead to write contention. On Sqlite this can significantly slow down your wiki.
  • Make sure your SQLite database is in WAL mode (Write-Ahead Logging – WAL). This can have a major impact on performance when people are viewing and editing your site at the same time. You can do this by using the sqlite command line tool to open the DB, and run the command PRAGMA journal_mode=wal;.

参见

外部链接