数据库描述
本文简要介绍了WordPress 2.8版本标准安装下生成的数据库表格。WordPress 2.8的数据库目前只支持MySQL 4.0及更高版本。
WordPress自动与数据库连接,因此终端用户无需过于担心WordPress的数据库结构。但编写插件的用户可能会对数据库连接产生兴趣。WordPress使用WordPress数据库类来简化数据库连接。
数据库图解
下面的图表展示了WordPress数据库的整体情况以及在WordPress标准安装下创建的多个表格(WordPress2.5以上版本)之间的关系。下一节中的表格概况中详细介绍了各个表格的详细情况。

(WP 2.5数据库图解)
注意,在WordPress标准安装下,不强制各个表格之间的完整性(如日志和评论)。如果用户正开发可操作WordPress数据库的插件,所编写的代码需要能够整理表格内容,确保表格中不剩下任何单个记录,例如删除外部关键字时,可以用SQL命令集删除其他表格中的记录(操作前提醒用户进行备份)。
表格概况
这一节是对在WordPress标准安装下生成的所有表格的整体情况概述。
| WordPress 2.8表格(10) | ||
| 表格名称 | 说明 | WordPress相关用户界面 |
| wp_comments | WordPress中的评论存储在wp_comments表中 | 评论是读者对文章的反应,由管理者通过管理面板的评论菜单进行管理 |
| wp_links | wp_links中存储了在WordPress的link功能中输入的链接 |
|
| wp_options | 在Administration > 设置中的设置被存储在wp_options表中 |
|
| wp_postmeta | 日志的meta data信息被存储在wp_postmeta表中。一些插件会在wp_postmeta中添加关于自己的信息。 |
|
| wp_posts | 日志是WordPress的重要信息,存储在wp_posts表中。 |
|
| wp_terms | 日志、链接的类别以及日志标签都存储在wp_terms表中 |
|
| wp_term_relationships | 日志与wp_terms中的类别与标签联合起来共同存储在wp_terms_relationships表中。类别相关链接也存储在wp_terms_relationships中。 | |
| wp_term_taxonomy | 该表格对wp_terms表中的条目分类(类别、链接以及标签)进行说明 | |
| wp_usermeta | 用户的meta data信息存储在wp_usermeta中 |
|
| wp_users | 用户列表被存储在wp_users中 |
|
表格详细信息
以下是WordPress标准安装生成的表格中的特定字段。
表:wp_comments
| Field | Type | Null | Key | Default | Extra |
|---|---|---|---|---|---|
| comment_ID | bigint(20) unsigned | PRI | NULL | auto_increment | |
| comment_post_ID | bigint(20) unsigned | IND | 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 | datetime | IND & 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 |
索引
| Keyname | 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 |
表:wp_links
| Field | Type | Null | Key | Default | Extra |
|---|---|---|---|---|---|
| link_id | bigint(20) unsigned | PRI | 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) |
索引
| Keyname | Type | Cardinality | Field |
|---|---|---|---|
| PRIMARY | PRIMARY | 7 | link_ID |
| link_category | INDEX | None | link_category |
| link_visible | INDEX | None | link_visible |
表:wp_options
| Field | Type | Null | Key | Default | Extra |
|---|---|---|---|---|---|
| option_id | bigint(20) unsigned | PRI 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 |
索引
| Keyname | Type | Cardinality | Field |
|---|---|---|---|
| PRIMARY | PRIMARY | 184 | option_id blog_id option_name |
| option_name | INDEX | 184 | option_name |
表:wp_postmeta
| Field | Type | Null | Key | Default | Extra |
|---|---|---|---|---|---|
| meta_id | bigint(20) unsigned | PRI | NULL | auto_increment | |
| post_id | bigint(20) unsigned | IND | 0 | FK->wp_posts.ID | |
| meta_key | varchar(255) | YES | IND | NULL | |
| meta_value | longtext | YES | NULL |
索引
| Keyname | Type | Cardinality | Field |
|---|---|---|---|
| PRIMARY | PRIMARY | 13 | meta_ID |
| post_id | INDEX | 15 | post_id |
| meta_key | INDEX | 7 | meta_key |
表:wp_posts
| Field | Type | Null | Key | Default | Extra |
|---|---|---|---|---|---|
| ID | bigint(20) unsigned | PRI & IND Pt4 | auto_increment | ||
| post_author | bigint(20) unsigned | 0 | FK->wp_users.ID | ||
| post_date | datetime | IND 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 |
索引
| Keyname | 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 |
表:wp_terms
| Field | Type | Null | Key | Default | Extra |
|---|---|---|---|---|---|
| term_id | bigint(20) unsigned | PRI | auto_increment | ||
| name | varchar(200) | ||||
| slug | varchar(200) | UNI | |||
| term_group | bigint(10) | 0 |
索引
| Keyname | Type | Cardinality | Field |
|---|---|---|---|
| PRIMARY | PRIMARY | 2 | term_ID |
| slug | UNIQUE | 2 | slug |
| name | Index | none | name |
表:wp_term_relationships
| Field | Type | Null | Key | Default | Extra |
|---|---|---|---|---|---|
| object_id | bigint(20) unsigned | PRI Pt1 | 0 | ||
| term_taxonomy_id | bigint(20) unsigned | PRI Pt2 & IND | 0 | FK->wp_term_taxonomy.term_taxonomy_id | |
| term_order | int(11) | 0 |
索引
| Keyname | Type | Cardinality | Field |
|---|---|---|---|
| PRIMARY | PRIMARY | 8 | object_id term_taxonomy_id |
| term_taxonomy_id | INDEX | None | term_taxonomy_id |
表:wp_term_taxonomy
| Field | Type | Null | Key | Default | Extra |
|---|---|---|---|---|---|
| term_taxonomy_id | bigint(20) unsigned | PRI | auto_increment | ||
| term_id | bigint(20) unsigned | UNI Pt1 | 0 | FK->wp_terms.term_id | |
| taxonomy | varchar(32) | UNI Pt2 | |||
| description | longtext | ||||
| parent | bigint(20) unsigned | 0 | |||
| count | bigint(20) | 0 |
索引
| Keyname | Type | Cardinality | Field |
|---|---|---|---|
| PRIMARY | PRIMARY | 2 | term_taxonomy_id |
| term_id_taxonomy | UNIQUE | 2 | term_id taxonomy |
| taxonomy | INDEX | None | taxonomy |
表:wp_usermeta
| Field | Type | Null | Key | Default | Extra |
|---|---|---|---|---|---|
| umeta_id | bigint(20) unsigned | PRI | 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 |
索引
| Keyname | Type | Cardinality | Field |
|---|---|---|---|
| PRIMARY | PRIMARY | 9 | umeta_id |
| user_id | INDEX | None | user_id |
| meta_key | INDEX | None | meta_key |
表:wp_users
| Field | Type | Null | Key | Default | Extra |
|---|---|---|---|---|---|
| ID | bigint(20) unsigned | PRI | 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) |
索引
| Keyname | Type | Cardinality | Field |
|---|---|---|---|
| PRIMARY | PRIMARY | 1 | ID |
| user_login_key | INDEX | None | user_login |
| user_nicename | INDEX | None | user_nicename |
修改记录
WordPress 2.8版本:
- comments 表:将comment_post_ID栏改为bigint(20), unsigned
- links表:删除link_category一栏
- posts表:删除post_category一栏
- term_taxonomy表:添加KEY分类
- 为不同的bignit(20)字段添加unsigned属性
分类:中文手册