Manual:Shared database/zh

本页简要概述了在 MediaWiki 中使用共享数据库. 此处的大部分信息应该适用于 MediaWiki 的简单安装（不包含扩展）. 任何扩展要求都会被注明. 请注意，这是关于 MySQL 数据库设计的. MediaWiki 1.17 中添加了对 SQLite 的支持. MediaWiki 1.19 中添加了对 PostgreSQL 的支持. 其他数据库可能不支持这种共享数据库方式.

基础用法
共享数据库在您的 中配置了 3 个主要的全局 ：



根据您的需求和环境，您可能不需要使用所有这些.

最简单的设置：共享用户表
共享用户表可用于拥有多个共享用户注册的 wiki，因此用户只需注册一个 wiki.

默认情况下，$wgSharedTables 包含 user 和 user_properties 表. 向其中添加'actor'是 planned.

数据库权限
共享 wiki 的 MySQL 用户必须至少具有主 wiki 用户表的 SELECT 和 UPDATE 权限. 如果您为每个 wiki 使用不同的 MySQL 用户，您将需要按照该 wiki 的 设置中的指定向共享 wiki 用户授予额外的权限. 这可以使用类似于以下的 MySQL 命令执行：

当用户登录时，允许您的 wiki 从主表读取用户，并更新表.

共享sessions
要在您的 wiki 之间共享登录sessions，请设置 以包括您的根域下的所有子域. 例如，如果您有网站 en.example.comfr.example.compool.example.com，请设置：

升级
从 MediaWiki 1.21 开始，当从 web 安装程序 升级 MediaWiki 时，必须在升级期间临时清除 $wgSharedTables. 否则，共享表根本不会被触发（$wgSharedPrefix 的表和 $wgDBprefix 的表都没有），这可能导致升级失败.

从命令行升级时，运行 脚本，您需要使用脚本的   参数来升级共享表.

In MediaWiki 1.24 the default password type for MediaWiki has been changed from MD5 to PBKDF2, and passwords hashes will automatically be updated as users log in. To prevent this from happening until all wikis are upgraded, set to   on all wikis, and remove it on all wikis when they have been upgraded to ensure a stronger encryption is used.

Sharing more tables
You can share tables other than the user table, but be careful when doing so. If a table contains any data specific to one wiki, sharing may cause problems. Note that each of the subsections here assume that you are also sharing the user table. Whenever adding other tables, be sure to either append to the array or include the user table in the new array definition.

The ipblocks table
By sharing the table, you can have "global blocks" so that a block on one wiki will block the user or IP on all other wikis using the shared database.

Caveats
There can be some minor issues when sharing the ipblocks table:


 * The  field is set as the "reason" on Special:Block when blocking a user. When a blocked user sees the "You are blocked" message, this is parsed as wikitext, and links are parsed on Special:BlockList, you will need to make sure when blocking a user that the message makes sense on all wikis.
 * Block logs will not be shared (sharing the table is not recommended).

The user_groups table
Sharing the table will allow you to have global user groups.

Caveats

 * As with the block log, the user rights log is not shared.
 * All user groups will be global. You can work around this somewhat by customizing your user groups. For example, to have admins on one wiki be separate from admins on another, you could do something like the following:
 * In the config for wiki 1:


 * In the config for wiki 2:


 * To prevent bureaucrats on one wiki from assigning themselves rights on other wikis that they shouldn't have, you can do a similar configuration to the above, but remove the 'userrights' right that allows them to set any group, and use / instead.

Other tables
This section covers other tables, with less common reasons to share, as well as which tables not to share.


 * The interwiki table contains mostly static data; it may be useful to share if you have many custom interwikis.
 * The site_stats table could possibly be shared, to aggregate data over all your wikis.
 * By default, the table is included in the list of shared tables. If your wikis were started using MediaWiki 1.15 or older, you should probably keep this for backward compatibility, as user preferences will be silently automatically migrated from the user table to the user_properties table. Otherwise, you can remove this from the array to allow users to have different preferences on each wiki (if desired)

Most other tables should not be shared, as they include wiki-specific data, typically connections to pages via a pageid or a namespace/title combination. This includes (but is not limited to):


 * Any of the links tables (pagelinkstemplatelinks, etc.)
 * The page table
 * The revision table
 * The image table (to have a shared media repository, see )

For more details, see