停更了一個月後,咱們再次開始更新。具體緣由只能說是過年事情太多,幼時不知努力,長大了卻又事事纏身。java
這一期主要是根據WordPress執行的效果來觀察數據庫,從而分析WordPress的程序設計。mysql
項目github地址:github.com/pc859107393…android
個人簡書首頁是:www.jianshu.com/users/86b79…git
上一期是:[手把手教程][第二季]java 後端博客系統文章系統——No4github
根據WordPress文章保存和草稿保存分析程序設計web
首先咱們打開WordPress登陸到控制檯後隨便保存草稿和文章,而後導出數據庫中posts表增長內容以下:spring
{
"RECORDS":[
{
"ID":"329",
"post_author":"1",
"post_date":"02-16-2017 09:57:29",
"post_date_gmt":"02-16-2017 01:57:29",
"post_title":"[java 手把手教程][第二季]java 後端博客系統文章系統——No4",
"post_excerpt":"",
"post_status":"inherit",
"comment_status":"closed",
"comment_count":"0",
"ping_status":"closed",
"post_password":"",
"post_name":"328-revision-v1",
"to_ping":"",
"pinged":"",
"post_modified":"02-16-2017 09:57:29",
"post_modified_gmt":"02-16-2017 01:57:29",
"post_content_filtered":"",
"post_parent":"328",
"guid":"http://acheng1314.cn/?p=329",
"menu_order":"0",
"post_type":"revision",
"post_mime_type":"",
"comment_count(2)":"0"
},
{
"ID":"328",
"post_author":"1",
"post_date":"02-16-2017 09:58:19",
"post_date_gmt":"02-16-2017 01:58:19",
"post_title":"[java 手把手教程][第二季]java 後端博客系統文章系統——No4",
"post_excerpt":"",
"post_status":"publish",
"comment_status":"open",
"comment_count":"0",
"ping_status":"open",
"post_password":"",
"post_name":"java-%e6%89%8b%e6%8a%8a%e6%89%8b%e6%95%99%e7%a8%8b%e7%ac%ac%e4%ba%8c%e5%ad%a3java-%e5%90%8e%e7%ab%af%e5%8d%9a%e5%ae%a2%e7%b3%bb%e7%bb%9f%e6%96%87%e7%ab%a0%e7%b3%bb%e7%bb%9f-no4",
"to_ping":"",
"pinged":"",
"post_modified":"02-16-2017 09:58:19",
"post_modified_gmt":"02-16-2017 01:58:19",
"post_content_filtered":"",
"post_parent":"0",
"guid":"http://acheng1314.cn/?p=328",
"menu_order":"0",
"post_type":"post",
"post_mime_type":"",
"comment_count(2)":"0"
},
{
"ID":"327",
"post_author":"1",
"post_date":"02-14-2017 23:20:15",
"post_date_gmt":"02-14-2017 15:20:15",
"post_title":"個人草稿",
"post_excerpt":"",
"post_status":"inherit",
"comment_status":"closed",
"comment_count":"0",
"ping_status":"closed",
"post_password":"",
"post_name":"323-revision-v1",
"to_ping":"",
"pinged":"",
"post_modified":"02-14-2017 23:20:15",
"post_modified_gmt":"02-14-2017 15:20:15",
"post_content_filtered":"",
"post_parent":"323",
"guid":"http://acheng1314.cn/?p=327",
"menu_order":"0",
"post_type":"revision",
"post_mime_type":"",
"comment_count(2)":"0"
},
{
"ID":"326",
"post_author":"1",
"post_date":"02-14-2017 23:20:01",
"post_date_gmt":"02-14-2017 15:20:01",
"post_title":"",
"post_excerpt":"",
"post_status":"inherit",
"comment_status":"closed",
"comment_count":"0",
"ping_status":"closed",
"post_password":"",
"post_name":"323-revision-v1",
"to_ping":"",
"pinged":"",
"post_modified":"02-14-2017 23:20:01",
"post_modified_gmt":"02-14-2017 15:20:01",
"post_content_filtered":"",
"post_parent":"323",
"guid":"http://acheng1314.cn/?p=326",
"menu_order":"0",
"post_type":"revision",
"post_mime_type":"",
"comment_count(2)":"0"
},
{
"ID":"325",
"post_author":"1",
"post_date":"02-10-2017 22:34:41",
"post_date_gmt":"00-00-00 00:00:00",
"post_title":"自動草稿",
"post_excerpt":"",
"post_status":"auto-draft",
"comment_status":"open",
"comment_count":"0",
"ping_status":"open",
"post_password":"",
"post_name":"",
"to_ping":"",
"pinged":"",
"post_modified":"02-10-2017 22:34:41",
"post_modified_gmt":"00-00-00 00:00:00",
"post_content_filtered":"",
"post_parent":"0",
"guid":"http://acheng1314.cn/?p=325",
"menu_order":"0",
"post_type":"post",
"post_mime_type":"",
"comment_count(2)":"0"
},
{
"ID":"323",
"post_author":"1",
"post_date":"02-14-2017 23:20:15",
"post_date_gmt":"00-00-00 00:00:00",
"post_title":"個人草稿",
"post_excerpt":"",
"post_status":"draft",
"comment_status":"open",
"comment_count":"0",
"ping_status":"open",
"post_password":"",
"post_name":"",
"to_ping":"",
"pinged":"",
"post_modified":"02-14-2017 23:20:15",
"post_modified_gmt":"02-14-2017 15:20:15",
"post_content_filtered":"",
"post_parent":"0",
"guid":"http://acheng1314.cn/?p=323",
"menu_order":"0",
"post_type":"post",
"post_mime_type":"",
"comment_count(2)":"0"
}
]
}複製代碼
在上面的數據中咱們已經刪除了文章內容的數據(數據量太大,不方便查閱)。而後咱們仔細分析上面的json數據,咱們能夠得出結論以下:sql
經過上面的對比咱們大體能夠得出這樣一個結論:數據庫
---->正式發佈
"post_status":"publish",
"comment_status":"open",
"ping_status":"open",
"post_name":"java-%e6%89%8b%e6%8a%8a%e6%89%8b%e6%95%99%e7%a8%8b%e7%ac%ac%e4%ba%8c%e5%ad%a3java-%e5%90%8e%e7%ab%af%e5%8d%9a%e5%ae%a2%e7%b3%bb%e7%bb%9f%e6%96%87%e7%ab%a0%e7%b3%bb%e7%bb%9f-no4",
"post_type":"post",
"post_parent":"0",
---->歷史記錄
"post_status":"inherit",
"comment_status":"closed",
"ping_status":"closed",
"post_name":"328-revision-v1",
"post_type":"revision",
"post_parent":"328",複製代碼
草稿:json
小結:
文章分組相關分析
SELECT
`ID`,
`post_title`,
`post_date`,
`post_content`
FROM
`wp_posts`
WHERE
`post_type` = 'post'
AND
`post_status` = 'publish'
ORDER BY
`ID`複製代碼
上面的語句可以查找出來公開的文章,文章ID一目瞭然。
同時咱們觀察數據庫能夠得出跟文章的歸類相關的數據庫有:
可是這麼多表都是文章分類相關的東西,那麼文章分類又分爲何些呢?按照WordPress的簡單構架支撐大量的數據來看,那麼咱們能夠確定文章標籤和目錄分類確定是在一塊兒的。因此咱們先看最根本的wp_terms。
term_id | name | slug | term_group |
---|---|---|---|
1 | java web | java-web | 0 |
2 | C語言學習 | how2use_c | 0 |
3 | Android開發 | makeandroid | 0 |
4 | 綜合總結 | all_log | 0 |
5 | 我的生活 | myself_life | 0 |
6 | post-format-aside | post-format-aside | 0 |
7 | 轉載 | from_others | 0 |
8 | Android Coder | android-coder | 0 |
9 | 友情連接 | %e5%8f%8b%e6%83%85%e9%93%be%e6%8e%a5 | 0 |
10 | JavaWeb | javaweb | 0 |
11 | java web | java-web | 0 |
12 | Spring | spring | 0 |
13 | Mybatis | mybatis | 0 |
14 | java後端 | java%e5%90%8e%e7%ab%af | 0 |
15 | JavaWeb | javaweb | 0 |
16 | MySQL數據庫 | mysql%e6%95%b0%e6%8d%ae%e5%ba%93 | 0 |
17 | 全棧教程 | %e5%85%a8%e6%a0%88%e6%95%99%e7%a8%8b | 0 |
18 | java | java | 0 |
上面這張表是我線上服務器上面的wp_term表,可能咱們暫時不明白什麼意思,不過問題不大。咱們接着看wp_term_taxonomy。
term_taxonomy_id | term_id | taxonomy | description | parent | count |
---|---|---|---|---|---|
1 | 1 | category | 0 | 17 | |
2 | 2 | category | 0 | 0 | |
3 | 3 | category | 0 | 20 | |
4 | 4 | category | 0 | 6 | |
5 | 5 | category | 0 | 1 | |
6 | 6 | post_format | 0 | 44 | |
7 | 7 | category | 0 | 8 | |
8 | 8 | link_category | 0 | 2 | |
9 | 9 | nav_menu | 0 | 0 | |
10 | 10 | link_category | 0 | 0 | |
11 | 11 | post_tag | 0 | 2 | |
12 | 12 | post_tag | 0 | 4 | |
13 | 13 | post_tag | 0 | 4 | |
14 | 14 | post_tag | 0 | 3 | |
15 | 15 | post_tag | 0 | 2 | |
16 | 16 | post_tag | 0 | 3 | |
17 | 17 | post_tag | 0 | 3 | |
18 | 18 | post_tag | 0 | 1 |
經過上面這種表咱們就能夠明白了term_id所對應的name分別是什麼用的,他們分別有文章分組、文章標籤、連接標記等。
可是說這麼多都沒把上面文章的文章分類在哪找到,因此咱們接着看wp_term_relationships表裏面的東西。
object_id | term_taxonomy_id | term_order |
---|---|---|
1 | 8 | 0 |
2 | 8 | 0 |
9 | 4 | 0 |
9 | 6 | 0 |
11 | 4 | 0 |
11 | 6 | 0 |
16 | 3 | 0 |
16 | 6 | 0 |
··· | ··· | ··· |
表裏面數據還有不少此處暫時省略。
上面表中的object_id顧名思義就是說對象的ID,說明它不單是文章也還有其餘分類的信息。
咱們再看看咱們線上的wp_posts(文章)表,裏面的簡略內容以下:
ID | post_title | post_date | post_content |
---|---|---|---|
9 | IT產品文檔列表 | 2015-09-22 16:44:48 | 內容省略··· |
11 | 建站伊始,一切從頭再來,本站用wordpress搭建,基於PHP。 | 2015-09-22 16:45:32 | ··· |
其實數據不須要那麼多,咱們只須要一丟丟數據簡單對比就能知道結果了。
term_id | taxonomy |
---|---|
category | post_format |
term_id | name | slug | term_group |
---|---|---|---|
4 | 綜合總結 | all_log | 0 |
6 | post-format-aside | post-format-aside | 0 |
因此最後咱們經過這樣就能夠明白分類信息的大概查找結構,文章分類的大概查找以下:
文章id ➡ wp_term_relationships中的object_id對應的term_taxonomy_id ➡ wp_term_taxonomy的ID能夠看到分別是什麼分類同時能夠查找到term_id ➡ 最後在wp_term表中根據term_id能夠查找到具體的名稱。
至此分類信息基本查找完成。
總結