您现在的位置是:首页 > 教程 > WordPress教程WordPress教程

Wordpress数据库表的用途作用说明

怀萍2025-03-17 22:47:00WordPress教程已有2人查阅

导读以下是在WordPress3.0版本标准安装过程中所创建的数据库表的大纲和描述。目前,WordPress3.0仅支持 MySQL 4.1.2及更高版本的数据库。由于WordPress自己与数据库接口,作为终端

以下是在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表?业?
管理 > 文章 > Tags
管理 > 文章 > 分类
管理 > 链接 > 链接分类
管理 > 文章 > 添加
管理 > 文章 > 编辑
管理 > 文章 > 添加
管理 > 文章 > 编辑
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_commentmetaField Type Null Key Default Extra
meta_id bigint(20) unsignedPRI NULL auto_increment
comment_id bigint(20) unsignedIND 0 FK->wp_comments.comment_id
meta_key varchar(255) YES IND NULL
meta_value longtext YESNULL
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 0 meta_ID
comment_id INDEX none comment_id
meta_key INDEX none meta_key
Table: wp_commentsField Type Null Key Default Extra
comment_ID bigint(20) unsignedPRI NULL auto_increment
comment_post_ID bigint(20) unsignedIND 0 FK->wp_posts.ID
comment_author tinytext
comment_author_email varchar(100)
comment_author_url varchar(200)
comment_author_IP varchar(100)
comment_date datetime 0000-00-00 00:00:00
comment_date_gmt datetimeIND & IND Pt2 0000-00-00 00:00:00
comment_content text
comment_karma int(11) 0
comment_approved varchar(20)IND & Ind Pt1 1
comment_agent varchar(255)
comment_type varchar(20)
comment_parent bigint(20) unsigned 0 FK->wp_comments.ID
user_id bigint(20) unsigned 0 FK->wp_users.ID
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 1 comment_ID
comment_approved INDEX None comment_approved
comment_post_ID INDEX None comment_post_ID
comment_approved_date_gmt INDEX None comment_approved
comment_date_gmt
comment_date_gmt INDEX None comment_date_gmt
comment_parent INDEX None comment_parent
Table: wp_linksField Type Null Key Default Extra
link_id bigint(20) unsignedPRI NULL auto_increment
link_url varchar(255)
link_name varchar(255)
link_image varchar(255)
link_target varchar(25)
link_description varchar(255)
link_visible varchar(20)IND Y
link_owner bigint(20) unsigned 1
link_rating int(11) 0
link_updated datetime 0000-00-00 00:00:00
link_rel varchar(255)
link_notes mediumtext
link_rss varchar(255)
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 7 link_ID
link_category INDEX None link_category
link_visible INDEX None link_visible
Table: wp_optionsField Type Null Key Default Extra
option_id bigint(20) unsignedPRI Pt1 NULL auto_increment
blog_id int(11)PRI Pt2 0
option_name varchar(64)PRI Pt3 & IND
option_value longtext
autoload varchar(20) yes
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 184 option_id
blog_id
option_name
option_name UNIQUE 184 option_name
Table: wp_postmetaField Type Null Key Default Extra
meta_id bigint(20) unsignedPRI NULL auto_increment
post_id bigint(20) unsignedIND 0 FK->wp_posts.ID
meta_key varchar(255) YES IND NULL
meta_value longtext YESNULL
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 13 meta_ID
post_id INDEX 15 post_id
meta_key INDEX 7 meta_key
Table: wp_postsField Type Null Key Default Extra
ID bigint(20) unsignedPRI & IND Pt4auto_increment
post_author bigint(20) unsigned 0 FK->wp_users.ID
post_date datetimeIND Pt3 0000-00-00 00:00:00
post_date_gmt datetime 0000-00-00 00:00:00
post_content longtext
post_title text
post_excerpt text
post_status varchar(20)IND PT2 publish
comment_status varchar(20) open
ping_status varchar(20) open
post_password varchar(20)
post_name varchar(200)IND
to_ping text
pinged text
post_modified datetime 0000-00-00 00:00:00
post_modified_gmt datetime 0000-00-00 00:00:00
post_content_filtered text
post_parent bigint(20) unsigned 0 FK->wp_posts.ID
guid varchar(255)
menu_order int(11) 0
post_type varchar(20)IND Pt1 post
post_mime_type varchar(100)
comment_count bigint(20) 0
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 2 ID
post_name INDEX None post_name
type_status_date INDEX None post_type
post_status
post_date
ID
post_parent INDEX None post_parent
post_author INDEX None post_author
Table: wp_termsField Type Null Key Default Extra
term_id bigint(20) unsignedPRIauto_increment
name varchar(200)
slug varchar(200)UNI
term_group bigint(10) 0
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 2 term_ID
slug UNIQUE 2 slug
name Index none name
Table: wp_term_relationshipsField Type Null Key Default Extra
object_id bigint(20) unsignedPRI Pt1 0
term_taxonomy_id bigint(20) unsignedPRI Pt2 & IND 0 FK->wp_term_taxonomy.term_taxonomy_id
term_order int(11) 0
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 8 object_id
term_taxonomy_id
term_taxonomy_id INDEX None term_taxonomy_id
Table: wp_term_taxonomyField Type Null Key Default Extra
term_taxonomy_id bigint(20) unsignedPRIauto_increment
term_id bigint(20) unsignedUNI Pt1 0 FK->wp_terms.term_id
taxonomy varchar(32)UNI Pt2
description longtext
parent bigint(20) unsigned 0
count bigint(20) 0
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 2 term_taxonomy_id
term_id_taxonomy UNIQUE 2 term_id
taxonomy
taxonomy INDEX None taxonomy
Table: wp_usermetaField Type Null Key Default Extra
umeta_id bigint(20) unsignedPRI NULL auto_increment
user_id bigint(20) unsigned '0' FK->wp_users.ID
meta_key varchar(255) Yes IND NULL
meta_value longtext Yes IND NULL
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 9 umeta_id
user_id INDEX None user_id
meta_key INDEX None meta_key
Table: wp_usersField Type Null Key Default Extra
ID bigint(20) unsignedPRI NULL auto_increment
user_login varchar(60)IND
user_pass varchar(64)
user_nicename varchar(50)IND
user_email varchar(100)
user_url varchar(100)
user_registered datetime 0000-00-00 00:00:00
user_activation_key varchar(60)
user_status int(11) 0
display_name varchar(250)
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 1 ID
user_login_key INDEX None user_login
user_nicename INDEX None user_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.
Administration > Tools > Network
Administration > Super Admin > Sites
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.
Administration > Super Admin > Update
wp_registration_log The wp_registration_log records the admin user created when each new site is created.
Administration > Super Admin > Sites
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.
Administration > Settings > General
wp_site The wp_site table contains the main site address.
Administration > Tools > Network
wp_sitecategories If global terms (global_terms_enabled = true) are enabled for a site the wp_sitecategories table holds those terms.
Administration > Super Admin > Options
Administration > Posts > Add New
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.
Administration > Super Admin > Options
wp_users The list of all users is maintained in table wp_users. Multisite add two fields not in the stand-alone version.
Administration > Users
Administration > Super Admin > Users
Administration > Super Admin > Sites - Edit Site
wp_usermeta This table is not re-create for multisite, but meta data of users for each site are stored in wp_usermeta.
Administration > Users
Administration > Super Admin > Users
Administration > Super Admin > Sites - Edit Site
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.
Administration > Super Admin > Sites - Add Site
多站点表详细资料
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_blogsField Type Null Key Default Extra
blog_id bigint(20) unsignedPRI NULL auto_increment
site_id bigint(20) unsignedIND 0
domain varchar(200) NO0
path varchar(100) NO
registered datetime NO0000-00-00 00:00:00
last_updated datetime NO0000-00-00 00:00:00
public tinyint(2) NO0
archived enum('0','1') NO0
mature tinyint(2) NO0
spam tinyint(2) NO0
deleted tinyint(2) NO0
lang_id int(11) NO0
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 2 blog_id
domain INDEX none domain(50),path(5)
lang_id INDEX none lang_id
Table: wp_blog_versionsField Type Null Key Default Extra
blog_id bigint(20) unsignedPRI 0 FK->wp_blogs.blog_id
db_version varchar(20) NO
last_updated datetime NO0000-00-00 00:00:00
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 2 blog_id
db_version INDEX none db_version
Table: wp_registration_logField Type Null Key Default Extra
ID bigint(20) unsignedPRI NULL auto_increment
email varchar(255) NO
IP varchar(30) NO
blog_id bigint(20) unsignedPRI 0 FK->wp_blogs.blog_id
date_registered datetime NO0000-00-00 00:00:00
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 1 ID
IP INDEX none IP
Table: wp_signupsField Type Null Key Default Extra
domain varchar(200) NO0
path varchar(100) NO
title longtext NO
user_login varchar(60) NO IND
user_email varchar(100) NO
registered_date datetime NO0000-00-00 00:00:00
activated datetime NO0000-00-00 00:00:00
active tinyint(1) NO
activation_key varchar(50) NO
meta longtext
IndexesKeyname Type Cardinality Field
activation_key INDEX None activation_key
domain INDEX None domain
Table: wp_siteField Type Null Key Default Extra
id bigint(20) unsignedPRI NULL auto_increment
domain varchar(200) NO0
path varchar(100) NO
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 1 id
domain INDEX none domain,path
Table: wp_sitecategoriesField Type Null Key Default Extra
cat_id bigint(20) unsigned NO PRI NULL auto_increment
cat_name carchar(55) NO
category_nicename varchar(200) NO
last_updated timestamp NO
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 9 cat_id
category_nicename INDEX None category_nicename
last_updated INDEX None last_updated
Table: wp_sitemetaField Type Null Key Default Extra
meta_id bigint(20) unsignedPRI NULL auto_increment
site_id bigint(20) unsigned '0' FK->wp_site.site_id
meta_key varchar(255) Yes IND NULL
meta_value longtext Yes IND NULL
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 9 meta_id
meta_key INDEX None meta_key
site_id INDEX None site_id
Table: wp_usersField Type Null Key Default Extra
ID bigint(20) unsignedPRI NULL auto_increment
user_login varchar(60)IND
user_pass varchar(64)
user_nicename varchar(50)IND
user_email varchar(100)
user_url varchar(100)
user_registered datetime 0000-00-00 00:00:00
user_activation_key varchar(60)
user_status int(11) 0
display_name varchar(250)
spam tinyint(2) NO0
deleted tinyint(2) NO0
IndexesKeyname Type Cardinality Field
PRIMARY PRIMARY 1 ID
user_login_key INDEX None user_login
user_nicename INDEX None user_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:
wp_2_commentmeta
wp_2_comments
wp_2_links
wp_2_options
wp_2_postmeta
wp_2_posts
wp_2_terms
wp_2_term_relationships
wp_2_term_taxonomy
The data of the main site are stored in unnumbered tables.
资源
A look inside the WordPress database 一篇Leonid Mamchenkov 的关于数据库表的深入探讨.
更新日志
3.0 :
comments table: 增加comment_parent索引.
posts table: 增加post_author索引.
开启Multisite特性时:
增加multisite tables.
增加spam和deleted字段到users table.
2.9 :
commentmeta table: 用于存储评论相关的数据.
options table: 增加唯一索引option_name.
更新了数据库图表
2.8 :
comments table : 修改 comment_post_ID 列为 bigint(20), unsigned.
links table : 删除 link_category 列.
posts table: 删除 post_category 列.
term_taxonomy table:添加键 taxonomy.
添加 unsigned 属性到类型为 bigint(20) 的字段.
2.7 :
term table : 修改 name 字段 varchar(55) -> varchar(200).
添加键 name 到 term table.
添加键 post_parent 到 posts table.
2.5 :
所有 enum 类型字段改为 varchar(20):
comments table: comment_approved field
links table: link_visible
options table: autoload
posts table: post_status, comment_status, ping_status
添加键 comment_approved_date_gmt 和 comment_date_gmt 到 comments table.
添加 term_order 字段到 term_relationships table
参见: Migrating Plugins and Themes to 2.5 - Database changes
2.3 :
添加 terms, term_taxonomy and term_relationships 表. 删除 categories, link2cat和 post2cat表.
删除 options table中的6个字段. (option_can_override, option_type, option_width, option_height, option_description, and option_admin_level)
添加新状态 'pending'到posts table的post_status字段.
参见: WordPress Taxonomy
2.1 :
删除linkcategories表. 链接分类数据合并到categories表, 重设IDs.
添加post_type字段到posts table (in 2.0.x, post_status = 'static' for Pages)
添加新状态 'future' posts table的 post_status字段 , 代替2.0.x版本中的 NOW().
参见: Migrating Plugins and Themes to 2.1 - Core WordPress Database Changes

本文标签:

很赞哦! (0)

暂无内容
暂无内容
暂无内容
暂无内容
留言与评论 (共有 0 条评论)
昵称:
匿名发表 登录账号
         
验证码: