WordPress.org

Ready to get started?Download WordPress

Codex

zh-cn:数据库描述

Contents


以下是在WordPress3.0版本标准安装过程中所创建的数据库表的大纲和描述。目前,WordPress3.0仅支持 MySQL 4.1.2及更高版本的数据库。

参见:

由于WordPress自己与数据库接口,作为终端用户,不必过分担心它的结构。而如果你是在编写插件,你也许会对学习如何直接与数据库接口感兴趣。WordPress提供了wpdb类简化了这一过程。

数据库图表

下面的图表提供了一个图形化的WordPress数据库概览,以及在WordPress(WordPress2.5+)标准安装过程中创建的表之间的关系。以下的数据表概览包含了表和列的额外详细说明。

(WP 3.0 Database diagram)

请注意,在wp的标准安装过程中表之间的完整性不是强制性的,比如文章和评论之间。如果你正在创建操作数据库的插件或扩展,你的代码应该做些清理工作,以便没有无用的记录留在表里。比如当外键被删除时,使用一个SQL命令集来删除其它表中的数据(不要忘记提醒用户,在进行此类操作前进行备份)。

表概述

这一节是在wp标准安装过程中创建的所有数据表的概述。详细内容在以下各表中。


wp2.8数据表(10)
表名 描述 WordPress用户界面相关区域
wp_comments WordPress中的评论 存储在wp_comments表中 评论是由读者创建的作为对文章的回应。评论由管理员管理,通过管理 > 评论 > 评论
wp_links wp_links 保存包含在WordPress Links feature部分的链接的相关信息。
wp_options 管理 > 设置面板下的选项存储在wp_options表里。
wp_postmeta 每篇文章的特性信息被称为元数据,它存储在wp_postmeta. 有些插件可能会添加他们自己的信息到这个表里.
wp_posts 数据的核心是文章,它存储在wp_posts表.
wp_terms 文章和链接分类以及文章的tag分类可以在wp_terms表里找到.
wp_term_relationships 文章有关的分类、来自wp_terms表的tags以及这一关联存在于wp_term_relationships表里. 链接与各自分类的联系也存储于这张表中.
wp_term_taxonomy 这张表描述了wp_terms表中每个条目的分类系统 (分类,链接,或tag).
wp_usermeta 每个用户的特性信息称为元数据,它存储在wp_usermeta.
wp_users 用户列表存在于wp_users表.


表详细资料

以下是在wp标准安装过程中创建的数据表每个字段的详细信息。

Table: wp_commentmeta

FieldTypeNullKeyDefaultExtra
meta_idbigint(20) unsigned PRINULLauto_increment
comment_idbigint(20) unsigned IND0FK->wp_comments.comment_id
meta_keyvarchar(255)YESINDNULL 
meta_valuelongtextYES NULL 

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY0meta_ID
comment_idINDEXnonecomment_id
meta_keyINDEXnonemeta_key

Table: wp_comments

FieldTypeNullKeyDefaultExtra
comment_IDbigint(20) unsigned PRINULLauto_increment
comment_post_IDbigint(20) unsigned IND0FK->wp_posts.ID
comment_authortinytext    
comment_author_emailvarchar(100)    
comment_author_urlvarchar(200)    
comment_author_IPvarchar(100)    
comment_datedatetime  0000-00-00 00:00:00 
comment_date_gmtdatetime IND & IND Pt20000-00-00 00:00:00 
comment_contenttext    
comment_karmaint(11)  0 
comment_approvedvarchar(20) IND & Ind Pt11 
comment_agentvarchar(255)    
comment_typevarchar(20)    
comment_parentbigint(20) unsigned  0FK->wp_comments.ID
user_idbigint(20) unsigned  0FK->wp_users.ID

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY1comment_ID
comment_approvedINDEXNonecomment_approved
comment_post_IDINDEXNonecomment_post_ID
comment_approved_date_gmtINDEXNonecomment_approved
comment_date_gmt
comment_date_gmtINDEXNonecomment_date_gmt
comment_parentINDEXNonecomment_parent

Table: wp_links

FieldTypeNullKeyDefaultExtra
link_idbigint(20) unsigned PRINULLauto_increment
link_urlvarchar(255)    
link_namevarchar(255)    
link_imagevarchar(255)    
link_targetvarchar(25)    
link_descriptionvarchar(255)    
link_visiblevarchar(20) INDY 
link_ownerbigint(20) unsigned  1 
link_ratingint(11)  0 
link_updateddatetime  0000-00-00 00:00:00 
link_relvarchar(255)    
link_notesmediumtext    
link_rssvarchar(255)    

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY7link_ID
link_categoryINDEXNonelink_category
link_visibleINDEXNonelink_visible

Table: wp_options

FieldTypeNullKeyDefaultExtra
option_idbigint(20) unsigned PRI Pt1NULLauto_increment
blog_idint(11) PRI Pt20 
option_namevarchar(64) PRI Pt3 & IND  
option_valuelongtext   
autoloadvarchar(20)  yes 

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY184option_id
blog_id
option_name
option_nameUNIQUE184option_name

Table: wp_postmeta

FieldTypeNullKeyDefaultExtra
meta_idbigint(20) unsigned PRINULLauto_increment
post_idbigint(20) unsigned IND0FK->wp_posts.ID
meta_keyvarchar(255)YESINDNULL 
meta_valuelongtextYES NULL 

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY13meta_ID
post_idINDEX15post_id
meta_keyINDEX7meta_key

Table: wp_posts

FieldTypeNullKeyDefaultExtra
IDbigint(20) unsigned PRI & IND Pt4 auto_increment
post_authorbigint(20) unsigned  0FK->wp_users.ID
post_datedatetime IND Pt30000-00-00 00:00:00 
post_date_gmtdatetime  0000-00-00 00:00:00 
post_contentlongtext    
post_titletext    
post_excerpttext    
post_statusvarchar(20) IND PT2publish 
comment_statusvarchar(20)  open 
ping_statusvarchar(20)  open 
post_passwordvarchar(20)    
post_namevarchar(200) IND  
to_pingtext    
pingedtext    
post_modifieddatetime  0000-00-00 00:00:00 
post_modified_gmtdatetime  0000-00-00 00:00:00 
post_content_filteredtext   
post_parentbigint(20) unsigned  0FK->wp_posts.ID
guidvarchar(255)    
menu_orderint(11)  0 
post_typevarchar(20) IND Pt1post 
post_mime_typevarchar(100)    
comment_countbigint(20)  0 

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY2ID
post_nameINDEXNonepost_name
type_status_dateINDEXNonepost_type
post_status
post_date
ID
post_parentINDEXNonepost_parent
post_authorINDEXNonepost_author

Table: wp_terms

FieldTypeNullKeyDefaultExtra
term_idbigint(20) unsigned PRI auto_increment
namevarchar(200)     
slugvarchar(200) UNI  
term_groupbigint(10)  0 

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY2term_ID
slugUNIQUE2slug
nameIndexnonename

Table: wp_term_relationships

FieldTypeNullKeyDefaultExtra
object_idbigint(20) unsigned PRI Pt10 
term_taxonomy_idbigint(20) unsigned PRI Pt2 & IND0FK->wp_term_taxonomy.term_taxonomy_id
term_orderint(11)  0 

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY8object_id
term_taxonomy_id
term_taxonomy_idINDEXNoneterm_taxonomy_id

Table: wp_term_taxonomy

FieldTypeNullKeyDefaultExtra
term_taxonomy_idbigint(20) unsigned PRI auto_increment
term_idbigint(20) unsigned UNI Pt10 FK->wp_terms.term_id
taxonomyvarchar(32) UNI Pt2  
descriptionlongtext    
parentbigint(20) unsigned  0 
countbigint(20)  0 

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY2term_taxonomy_id
term_id_taxonomyUNIQUE2term_id
taxonomy
taxonomyINDEXNonetaxonomy

Table: wp_usermeta

FieldTypeNullKeyDefaultExtra
umeta_idbigint(20) unsigned PRINULLauto_increment
user_idbigint(20) unsigned  '0'FK->wp_users.ID
meta_keyvarchar(255)YesINDNULL 
meta_valuelongtextYesINDNULL 

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY9umeta_id
user_idINDEXNoneuser_id
meta_keyINDEXNonemeta_key

Table: wp_users

FieldTypeNullKeyDefaultExtra
IDbigint(20) unsigned PRINULLauto_increment
user_loginvarchar(60) IND  
user_passvarchar(64)    
user_nicenamevarchar(50) IND  
user_emailvarchar(100)    
user_urlvarchar(100)    
user_registereddatetime  0000-00-00 00:00:00 
user_activation_keyvarchar(60)   
user_statusint(11)  0 
display_namevarchar(250)     

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY1ID
user_login_keyINDEXNoneuser_login
user_nicenameINDEXNoneuser_nicename

多站点表概述

本部分是Wordpress的Multisite特性所建立的表的概述。这些表通过Administration > Tools > Network下的操作建立。

这些表被看作是全局多站点的表。

WordPress 3.0 Multisite Tables
Table Name Description Relevant Area(s) of WordPress User Interface
wp_blogs Each site created is stored in the table, wp_blogs.
wp_blog_versions The current database version status of each site is maintained in the wp_blogs_versions table and is updated as each site is upgraded.
wp_registration_log The wp_registration_log records the admin user created when each new site is created.
wp_signups This table holds the user that have registered for a site via the login registration process. User registration is enable in Administration > Super Admin > Options.
wp_site The wp_site table contains the main site address.
wp_sitecategories If global terms (global_terms_enabled = true) are enabled for a site the wp_sitecategories table holds those terms.
wp_sitemeta Each site features information called the site data and it is stored in wp_sitemeta. Various option information, including the site admin is kept in this table.
wp_users The list of all users is maintained in table wp_users. Multisite add two fields not in the stand-alone version.
wp_usermeta This table is not re-create for multisite, but meta data of users for each site are stored in wp_usermeta.
Site Specific Tables The data of the main site are stored in existing unnumbered tables. The data of additional sites are stored in new numbered tables.


多站点表详细资料

The following describe the tables and fields created during the network installation. Note that a global set of tables is created upon creation of the network, and site-specific tables are established as each site is created.

Table: wp_blogs

FieldTypeNullKeyDefaultExtra
blog_idbigint(20) unsigned PRINULLauto_increment
site_idbigint(20) unsigned IND0
domainvarchar(200)NO 0 
pathvarchar(100)NO   
registereddatetimeNO 0000-00-00 00:00:00 
last_updateddatetimeNO 0000-00-00 00:00:00 
publictinyint(2)NO 0 
archivedenum('0','1')NO 0 
maturetinyint(2)NO 0 
spamtinyint(2)NO 0 
deletedtinyint(2)NO 0 
lang_idint(11)NO 0 

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY2blog_id
domainINDEXnonedomain(50),path(5)
lang_idINDEXnonelang_id

Table: wp_blog_versions

FieldTypeNullKeyDefaultExtra
blog_idbigint(20) unsigned PRI0FK->wp_blogs.blog_id
db_versionvarchar(20)NO   
last_updateddatetimeNO 0000-00-00 00:00:00 

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY2blog_id
db_versionINDEXnonedb_version

Table: wp_registration_log

FieldTypeNullKeyDefaultExtra
IDbigint(20) unsigned PRINULLauto_increment
emailvarchar(255)NO   
IPvarchar(30)NO   
blog_idbigint(20) unsigned PRI0FK->wp_blogs.blog_id
date_registereddatetimeNO 0000-00-00 00:00:00 

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY1ID
IPINDEXnoneIP

Table: wp_signups

FieldTypeNullKeyDefaultExtra
domainvarchar(200)NO 0 
pathvarchar(100)NO   
titlelongtextNO   
user_loginvarchar(60)NOIND  
user_emailvarchar(100)NO   
registered_datedatetimeNO 0000-00-00 00:00:00 
activateddatetimeNO 0000-00-00 00:00:00 
activetinyint(1)NO  
activation_keyvarchar(50)NO   
metalongtext     

Indexes

KeynameTypeCardinality Field
activation_keyINDEXNoneactivation_key
domainINDEXNonedomain

Table: wp_site

FieldTypeNullKeyDefaultExtra
idbigint(20) unsigned PRINULLauto_increment
domainvarchar(200)NO 0 
pathvarchar(100)NO   

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY1id
domainINDEXnonedomain,path

Table: wp_sitecategories

FieldTypeNullKeyDefaultExtra
cat_idbigint(20) unsignedNOPRINULLauto_increment
cat_namecarchar(55)NO   
category_nicenamevarchar(200)NO   
last_updatedtimestampNO   

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY9cat_id
category_nicenameINDEXNonecategory_nicename
last_updatedINDEXNonelast_updated

Table: wp_sitemeta

FieldTypeNullKeyDefaultExtra
meta_idbigint(20) unsigned PRINULLauto_increment
site_idbigint(20) unsigned  '0'FK->wp_site.site_id
meta_keyvarchar(255)YesINDNULL 
meta_valuelongtextYesINDNULL 

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY9meta_id
meta_keyINDEXNonemeta_key
site_idINDEXNonesite_id

Table: wp_users

FieldTypeNullKeyDefaultExtra
IDbigint(20) unsigned PRINULLauto_increment
user_loginvarchar(60) IND  
user_passvarchar(64)    
user_nicenamevarchar(50) IND  
user_emailvarchar(100)    
user_urlvarchar(100)    
user_registereddatetime  0000-00-00 00:00:00 
user_activation_keyvarchar(60)   
user_statusint(11)  0 
display_namevarchar(250)     
spamtinyint(2)NO  0
deletedtinyint(2)NO  0

Indexes

KeynameTypeCardinality Field
PRIMARYPRIMARY1ID
user_login_keyINDEXNoneuser_login
user_nicenameINDEXNoneuser_nicename

Site Specific Tables

When a new additional site is created, the site-specific tables, similar to the stand-alone tables above, are created. Each set of tables for a site are created with the site ID (blog_id) as part of the table name. These are the tables that would be created for site ID 2 and table_prefix wp:

The data of the main site are stored in unnumbered tables.

资源

更新日志