{"id":712,"date":"2014-01-13T09:35:43","date_gmt":"2014-01-13T01:35:43","guid":{"rendered":"http:\/\/coderbee.net\/?p=712"},"modified":"2014-02-17T10:41:55","modified_gmt":"2014-02-17T02:41:55","slug":"wordpress-%e6%96%87%e7%ab%a0%e7%b4%a2%e5%bc%95-%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/coderbee.net\/index.php\/db\/20140113\/712","title":{"rendered":"wordpress \u6587\u7ae0\u7d22\u5f15 \u5b58\u50a8\u8fc7\u7a0b"},"content":{"rendered":"<p>\u6700\u8fd1\u60f3\u7ed9\u672c\u7ad9\u52a0\u4e0a\u6587\u7ae0\u7d22\u5f15\u7684\u9875\u9762\uff0c\u5c31\u662f\u5728\u4e00\u4e2a\u9875\u9762\u4e0a\u5c55\u793a\u6240\u6709\u7684\u5206\u7c7b\u53ca\u8be5\u5206\u7c7b\u7684\u6587\u7ae0\uff0c\u7136\u540e\u7f6e\u9876\u5230\u9996\u9875\uff0c\u6548\u679c\u89c1<a href=\"http:\/\/coderbee.net\/index.php\/uncategorized\/20140105\/697\">\u672c\u7ad9\u6587\u7ae0\u7d22\u5f15<\/a>\u3002\u5f00\u59cb\u7684\u601d\u8def\u662f\uff1a\u5148\u65b0\u5efa\u4e00\u4e2a\u9875\u9762\uff0c\u7136\u540e\u8bbe\u7f6e\u597d\u7f6e\u9876\u7b49\uff0c\u7528\u5b58\u50a8\u8fc7\u7a0b\u66f4\u65b0\u8be5\u9875\u9762\u7684\u5185\u5bb9\uff0c\u7528\u89e6\u53d1\u5668\u5728\u6709\u65b0\u6587\u7ae0\u53d1\u8868\u6216\u6587\u7ae0\u6807\u9898\u6709\u66f4\u65b0\u65f6\u89e6\u53d1\u6267\u884c\u5b58\u50a8\u8fc7\u7a0b\u3002\u770b\u8d77\u6765\u5e94\u8be5\u633a\u987a\u5229\u7684\uff0c\u4e0d\u8fc7\u5b9e\u73b0\u8fc7\u7a0b\u5012\u6ca1\u60f3\u8c61\u90a3\u4e48\u597d\u4e86\u3002<\/p>\n<h3>\u66f4\u65b0\u7d22\u5f15\u5b58\u50a8\u8fc7\u7a0b<\/h3>\n<p>\u8fd9\u4e2a\u5b58\u50a8\u8fc7\u7a0b\u7684\u529f\u80fd\u662f\u4ece\u6570\u636e\u5e93\u91cc\u67e5\u8be2\u51fa\u6240\u6709\u7684\u5206\u7c7b\u4ee5\u53ca\u8be5\u5206\u7c7b\u4e0b\u7684\u6587\u7ae0\u7684ID\u548c\u6807\u9898\uff0c\u7136\u540e\u7528\u6e38\u6807\u751f\u6210html\u5185\u5bb9\uff08wordpress\u76f4\u63a5\u5b58\u50a8\u9875\u9762\u7684html\u5185\u5bb9\uff09\uff0c\u518d\u66f4\u65b0\u4e3a\u7d22\u5f15\u9875\u9762\u7684\u5185\u5bb9\u3002<br \/>\n<!--more--><\/p>\n<p>\u8981\u628a\u4e0b\u9762sql\u8bed\u53e5\u91cc\u9762\u7684 \u201c\u7d22\u5f15\u9875\u9762\u7684url\u201d \u66ff\u6362\u6210\u5b9e\u9645\u7684URL\u518d\u6267\u884c\u3002<\/p>\n<pre><code class=\"sql\"><br \/>SET NAMES utf8;\n\nuse blog;\n\ndelimiter \/\/\n\ndrop procedure if exists sp_updateIndex;\n\ncreate procedure sp_updateIndex ()\nbegin\n\n    declare categroies varchar(21845);\n    declare details varchar(21845);\n    declare done int default 0;\n\n    declare lastCatgName varchar(100);\n    declare catgName varchar(200);\n    declare postId bigint(20);\n    declare postTitle varchar(200);\n\n    declare cur cursor for \n        select cast(convert(terms.name using utf8) as char), post.id, cast(convert(post.post_title using utf8) as char)\n        from wp_term_taxonomy tax\n            join wp_terms terms on tax.term_id = terms.term_id\n            join wp_term_relationships rel on tax.term_taxonomy_id = rel.term_taxonomy_id\n            join wp_posts post on rel.object_id = post.id\n        where tax.taxonomy = 'category' and post.post_status = 'publish' order by tax.term_id desc;\n\n    declare continue handler for not found set done = 1;\n\n    set lastCatgName = '';\n    set categroies = '&lt;h3&gt;index&lt;\/h3&gt;&lt;ul&gt;';\n    set details = '';\n\n    open cur;\n\n    repeat fetch cur into catgName, postId, postTitle;\n\n        if not done then\n            if strcmp(lastCatgName, catgName) != 0 then\n                set categroies = concat(categroies, '&lt;li&gt;&lt;a href=\"\u7d22\u5f15\u9875\u9762\u7684url#', catgName, '\"&gt;', catgName, '&lt;\/a&gt;&lt;\/li&gt;');\n\n                if strcmp(lastCatgName, '') = 0 then\n                    set details = concat(details, '&lt;br&gt;&lt;hr&gt;&lt;a name=\"', catgName, '\"&gt;&lt;\/a&gt;&lt;h3&gt;', catgName, '&lt;\/h3&gt;&lt;ul&gt;');\n                else\n                    set details = concat(details, '&lt;\/ul&gt;&lt;br&gt;&lt;hr&gt;&lt;a name=\"', catgName, '\"&gt;&lt;\/a&gt;&lt;h3&gt;', catgName, '&lt;\/h3&gt;&lt;ul&gt;');\n                end if;\n\n                set lastCatgName = catgName;\n            end if;\n\n            set details = concat(details, '&lt;li&gt;&lt;a target=\"_blank\" href=\"http:\/\/coderbee.net\/?p=', postId, '\"&gt;', postTitle, '&lt;\/a&gt;&lt;\/li&gt;');\n        end if;\n    until done end repeat ;\n\n    close cur;\n\n    set categroies = concat(categroies, '&lt;\/ul&gt;');\n    set details = concat(details, '&lt;\/ul&gt;');\n    update wp_posts set post_content = concat(categroies, '&lt;!--more--&gt;', details) where id = 697;\nend;\n\/\/\n<\/code><\/pre>\n<p>\u5b9e\u73b0\u662f\u4e0d\u600e\u4e48\u590d\u6742\u7684\u3002<\/p>\n<h3>\u4e71\u7801\u5751<\/h3>\n<p>\u78b0\u5230\u7684\u7b2c\u4e00\u4e2a\u5751\u662f\u4e71\u7801\uff0c\u7531\u4e8eMySQL\u91c7\u7528\u6e90\u7801\u5b89\u88c5\uff0c\u4e14\u5b89\u88c5\u65f6\u6ca1\u6709\u6307\u5b9a\u9ed8\u8ba4\u7f16\u7801\uff0c\u6240\u4ee5MySQL\u4f7f\u7528\u7684\u9ed8\u8ba4\u662f <code>latin1<\/code> \u5b57\u7b26\u96c6\uff0c\u597d\u5728wordpress\u5728\u521b\u5efa\u8868\u65f6\u628a\u8868\u7684\u7f16\u7801\u6307\u5b9a\u4e3a <code>utf8<\/code>\uff0c\u4e0d\u7136\u5904\u7406\u8981\u66f4\u591a\u70b9\uff0c\u5173\u4e8e\u7f16\u7801\u7684\u89e3\u51b3\u53ef\u4ee5\u770b <a href=\"http:\/\/coderbee.net\/index.php\/db\/20140112\/709\">MySQL \u4e71\u7801 \u4e0e \u5b57\u7b26\u96c6<\/a>\u3002<\/p>\n<h3>\u89e6\u53d1\u5668\u5751<\/h3>\n<p>\u5b58\u50a8\u8fc7\u7a0b\u6d4b\u8bd5ok\u540e\uff0c\u81ea\u7136\u5c31\u662f\u7528\u89e6\u53d1\u5668\u6765\u8c03\u7528\u4e86\uff0c\u89e6\u53d1\u5668\u4e5f\u5f88\u7b80\u5355\uff1a<\/p>\n<pre><code class=\"sql\">SET NAMES utf8;\n\nuse blog;\n\ndelimiter \/\/\n\ndrop trigger if exists trigger_updateIndex;\n\ncreate trigger trigger_updateIndex after insert on wp_posts for each row begin \n    if new.post_status = 'publish' then\n        call sp_updateIndex;\n    end if;\nend\n\/\/\n<\/code><\/pre>\n<p>\u89e6\u53d1\u5668\u7684\u521b\u5efa\u6ca1\u6709\u95ee\u9898\uff0c\u4f46\u662f\u5374\u51fa\u73b0 <code>ERROR 1442 (HY000): Can't update table 'wp_posts' in stored function\/trigger because it is already used by statement which invoked this stored function\/trigger.<\/code> \u5f02\u5e38\u3002<\/p>\n<p>\u4e4b\u6240\u4ee5\u53d8\u6210\u5751\u662f\u56e0\u4e3a\u6211\u4e00\u5f00\u59cb\u76f4\u63a5\u5728\u9875\u9762\u4e0a\u8fdb\u884c\u6d4b\u8bd5\uff0c\u6240\u4ee5\u51fa\u9519\u4e86\u4e5f\u770b\u4e0d\u5230\uff0c\u53ea\u662f\u53d1\u73b0\u6ca1\u6548\u679c\u5c31\u89c9\u5f97\u51fa\u95ee\u9898\u4e86\u3002\u540e\u6765\u5728\u547d\u4ee4\u884c\u4e0b\u76f4\u63a5\u63d2\u5165\u624d\u770b\u5230\u9519\u8bef\u4fe1\u606f\u7684\u3002<\/p>\n<p>google\u4e00\u756a\u540e\uff0c\u77e5\u9053\u8fd9\u662f<strong>MySQL\u7684\u4e00\u4e2a\u9650\u5236\uff0c\u4e0d\u80fd\u5728\u89e6\u53d1\u5668\u91cc\u5bf9\u672c\u8868\u8fdb\u884c\u66f4\u65b0\u64cd\u4f5c\uff0c\u672c\u8868\u5c31\u662f\u89e6\u53d1\u5668\u521b\u5efa\u65f6\u7528 <code>on<\/code> \u6307\u5b9a\u7684\u8868<\/strong>\u3002\u7f51\u4e0a\u6709\u4e00\u4e9b\u4eba\u7684\u89e3\u51b3\u65b9\u6cd5\u4e0d\u9002\u7528\u4e8e\u6211\u8fd9\u91cc\uff0c\u56e0\u4e3a\u9700\u6c42\u4e0d\u540c\uff0c\u4ed6\u4eec\u7684\u573a\u666f\u662f\u5982\u679c\u65b0\u7684\u8bb0\u5f55\u6ee1\u8db3\u4e00\u5b9a\u7684\u6761\u4ef6\u5c31\u66f4\u65b0\u65b0\u7684\u8bb0\u5f55\uff0c\u8fd9\u6837\u53ef\u4ee5\u7528 <code>set<\/code> \u8bed\u53e5\u7ed3\u5408 <code>before<\/code> \u641e\u5b9a\uff0c\u800c\u6211\u8fd9\u91cc\u662f\u8981\u66f4\u65b0\u4e0e\u65b0\u8bb0\u5f55\u4e0d\u540c\u7684\u67d0\u4e00\u6761\u8bb0\u5f55\u3002\u6240\u4ee5\u7528\u89e6\u53d1\u5668\u662f\u884c\u4e0d\u901a\u4e86\u3002<\/p>\n<p>\u89e3\u51b3\u7684\u4e00\u4e2a\u65b9\u6cd5\u5c31\u662f\u5728\u7a0b\u5e8f\u91cc\u89e3\u51b3\uff0c\u8c03\u7528\u63d2\u5165\u6210\u529f\u540e\u5728\u6267\u884c\u8fd9\u4e2a\u5b58\u50a8\u8fc7\u7a0b\uff0c\u4e0d\u8fc7\u5bf9wordpress\u548cphp\u90fd\u4e0d\u4e86\u89e3\uff0c\u5c31\u4e0d\u60f3\u8fd9\u6837\u641e\u4e86\u3002<\/p>\n<p>\u73b0\u5728\u7528 <a href=\"http:\/\/coderbee.net\/index.php\/linux\/20130425\/57\">cron \u8c03\u5ea6<\/a> \u52a0\u811a\u672c\u7684\u65b9\u5f0f\u6765\u641e\uff0c\u811a\u672c\u7684\u5185\u5bb9\uff1a <code>\/absolute\/path\/to\/mysql -u username --password='password' &lt; \/absolute\/path\/to\/trigger.sql<\/code>\u3002<\/p>\n<p>trigger.sql\uff1a<\/p>\n<pre><code class=\"sql\">use blog;\nset names utf8;\ncall sp_updateIndex;\n<\/code><\/pre>\n<p>\u4e2a\u4eba\u535a\u5ba2\u7684\u53d1\u8868\u9891\u7387\u662f\u5f88\u4f4e\u7684\uff0c\u628a\u9891\u7387\u8bbe\u7f6e\u4e3a\u6bcf\u5929\u4e00\u6b21\u5df2\u5b8c\u5168\u8db3\u591f\u3002<\/p>\n<h4>2014-01-27 \u66f4\u65b0\uff0cMySQL\u4e8b\u4ef6\u8c03\u5ea6\u5668 \u5b9a\u65f6\u66f4\u65b0<\/h4>\n<p>MySQL 5.1 \u5f15\u5165\u7684\u4e8b\u4ef6\u8c03\u5ea6\u5668\u53ef\u4ee5\u4f5c\u4e3a\u5b9a\u65f6\u4efb\u52a1\u8c03\u5ea6\u5668\uff0c\u53d6\u4ee3\u7cfb\u7edf\u7684cron\u8c03\u5ea6\uff0c\u8c03\u5ea6\u65f6\u95f4\u53ef\u4ee5\u7cbe\u786e\u5230\u79d2\uff0c\u5b9e\u65f6\u6027\u597d\u3002<\/p>\n<pre><code class=\"sql\">drop event if exists event_updateIndex;\n\ncreate event event_updateIndex;\non schedule every 24 hour\nstarts timestamp '2014-01-27 23:50:00'\ndo call sp_updateIndex;\n<\/code><\/pre>\n<p>\u4e8b\u4ef6\u8c03\u5ea6\u7684\u4f7f\u7528\u53ef\u53c2\u8003\uff1a <a href=\"http:\/\/coderbee.net\/index.php\/db\/20140127\/752\">http:\/\/coderbee.net\/index.php\/db\/20140127\/752<\/a><\/p>\n<hr\/>\n<p>\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u5fae\u4fe1\u516c\u4f17\u53f7: <strong>coderbee\u7b14\u8bb0<\/strong>\uff0c\u53ef\u4ee5\u66f4\u53ca\u65f6\u56de\u590d\u4f60\u7684\u8ba8\u8bba\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"258\" height=\"258\" src=\"https:\/\/coderbee.net\/wp-content\/uploads\/2019\/01\/coderbee-note.jpg\" class=\"alignnone size-full wp-image-1707\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u60f3\u7ed9\u672c\u7ad9\u52a0\u4e0a\u6587\u7ae0\u7d22\u5f15\u7684\u9875\u9762\uff0c\u5c31\u662f\u5728\u4e00\u4e2a\u9875\u9762\u4e0a\u5c55\u793a\u6240\u6709\u7684\u5206\u7c7b\u53ca\u8be5\u5206\u7c7b\u7684\u6587\u7ae0\uff0c\u7136 &hellip; <a href=\"https:\/\/coderbee.net\/index.php\/db\/20140113\/712\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[149,25],"_links":{"self":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/712"}],"collection":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/comments?post=712"}],"version-history":[{"count":12,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/712\/revisions"}],"predecessor-version":[{"id":801,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/712\/revisions\/801"}],"wp:attachment":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/media?parent=712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/categories?post=712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/tags?post=712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}