14 条实用的MySQL 查询语句| Dreamcolor's Cote

鍦ㄤ娇鐢?WordPress 鐨勮繃绋嬩腑锛屾煇浜涙椂鍊欓渶瑕佷慨姝d竴浜涙暟鎹簱鏂归潰鐨勯棶棰樸€傜浉姣斾箣涓嬶紝鐩存帴鍦ㄦ暟鎹簱涓墽琛屾煡璇㈣鍙ユ槸鏈€渚挎嵎鐨勩€傚湪杩欓噷锛屾彁渚涗簡 14 鏉¢潪甯稿疄鐢ㄧ殑鏌ヨ璇彞锛屽彲浠ュ府鍔╅亣鍒扮被浼奸棶棰樼殑鐢ㄦ埛瑙e喅鐩稿簲鐨勯棶棰樸€?/p>

濡備綍鎵ц MySQL 鏌ヨ璇彞

閫氬父鎯呭喌涓嬶紝鎴戜滑鍙互鐩存帴杩涘叆鏈嶅姟鍣ㄧ殑 MySQL 鍛戒护琛屼腑鎵ц銆備篃鍙互浣跨敤闈炲父钁楀悕鐨?WEB 绋嬪簭 PHPMyAdmin 杩涜鏌ヨ銆傚鏋滄垜浠兂鍦?WordPress 鍚庡彴鐩存帴杩涜鏌ヨ锛岃繕鍙互浣跨敤 杩欎釜鎻掍欢瀵规暟鎹簱杩涜鎿嶄綔銆?/p>

娉ㄦ剰锛氳櫧鐒朵互涓嬫彁渚涚殑鏌ヨ璇彞閮藉凡缁忕粡杩囨祴璇曘€備絾鏄涓嶈鐩存帴鍦ㄧ敓浜х幆澧冧笅杩愯锛屾垨鑰呯粡杩囦竴瀹氱殑娴嬭瘯鍐嶆墽琛岋紝姣曠珶姣忎釜浜虹殑绔欑偣鐜鍙兘鐣ユ湁涓嶅悓銆傛搷浣滀箣鍓嶅垏璁拌瀵规暟鎹簱杩涜澶囦唤鎿嶄綔銆?/strong>

1. 鎵嬪姩淇敼瀵嗙爜

鏌愪簺鎯呭喌涓嬶紝鎴戜滑蹇樿浜嗙鐞嗗憳鐨勫瘑鐮併€傛垨鑰呯珯鐐归伃鍙楁敾鍑诲悗锛岀鐞嗗憳瀵嗙爜琚伓鎰忎慨鏀逛簡銆傝繖涓椂鍊欙紝鎴戜滑鑳藉仛鐨勫氨鍙湁閲嶆柊璁剧疆绠$悊鍛樼殑瀵嗙爜浜嗐€?/p>

浠ヤ笅鏌ヨ璇彞锛屼娇鐢?MySQL 鐨?MD5() 鍑芥暟灏嗘垜浠殑瀵嗙爜杩涜 MD5 鍔犲瘑銆?/p>

UPDATE 'wp_users' SET 'user_pass' = MD5('PASSWORD') WHERE 'user_login' ='admin' LIMIT 1;

鏉ユ簮锛歨ttp://www.wprecipes.com/how-to-manually-reset-your-wordpress-password

2. 鎵归噺杞崲鏃ュ紡鐨勪綔鑰?/strong>

澶у鏁板垰浣跨敤 WordPress 鐨勪汉鍙兘閮芥槸鐩存帴浣跨敤 鈥渁dmin鈥濊繖涓敤鎴锋潵鐩存帴鍙戝竷鏃ュ織銆傜瓑鎮ㄦ柊寤轰竴涓敤鎴峰悗锛屽鏋滄兂灏嗗師鏉ユ棩蹇楃殑浣滆€呮壒閲忎慨鏀逛负鏂扮敤鎴风殑鏃跺€欙紝鍙互浣跨敤浠ヤ笅鏌ヨ璇彞銆?/p>

鍦ㄦ墽琛屼箣鍓嶏紝鎮ㄩ渶瑕佺煡閬撹€佺敤鎴峰拰鏂扮敤鎴风殑鐢ㄦ埛 ID銆?/p>

UPDATE wp_posts SET post_author=NEW_AUTHOR_ID WHERE post_author=OLD_AUTHOR_ID;

鏉ユ簮锛歨ttp://www.wprecipes.com/how-to-change-author-attribution-on-all-posts-at-once

3. 鍒犻櫎鏃ュ織淇鐗堟湰鍜屽叾鐩稿叧鐨勪俊鎭?/strong>

鏃ュ織鐨勪慨璁㈢増鏈姛鑳藉湪澶氱敤鎴峰叡鍚岀淮鎶や竴涓崥瀹㈢殑鏃跺€欓潪甯告湁鐢ㄣ€備笉杩囪鍔熻兘鍦ㄦ暟鎹簱涓坊鍔犺繃澶氱殑璁板綍鏁颁篃鏄緢璁╀汉鎭肩伀鐨勩€?/p>

鎵ц浠ヤ笅璇彞锛屽彲浠ュ皢鏁版嵁搴撲腑鐨勬棩蹇椾慨璁㈢増鏈褰曚互鍙婂叾涓殑鍏朵粬淇℃伅锛堝寘鎷嚜瀹氫箟鍖哄煙绛夌瓑锛夊垹闄ゆ帀銆傛墽琛屽悗锛屼細鑺傜渷寰堝鏁版嵁搴撶┖闂淬€?/p>

DELETE a,b,c FROM wp_posts a WHERE a.post_type = 'revision' LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id);

鏉ユ簮锛歨ttp://www.onextrapixel.com/2010/01/30/13-useful-wordpress-sql-queries-you-wish-you-knew-earlier/

4. 鎵归噺鍒犻櫎鍨冨溇璇勮

鍦ㄦ偍鐨勫崥瀹㈡病鏈夊畨瑁?Akismet 鎴栧叾浠栨浛浠e搧鐨勫墠鎻愪笅锛屼竴娈垫椂闂存病鏈夎繘鍏ュ悗鍙拌繘琛岃瘎璁哄鏍搞€傚彲鑳戒細鍑虹幇鍑犵櫨鐢氳嚦涓婂崈鏉℃湭瀹℃牳鐨勮瘎璁恒€傝€屼笖澶ч儴鍒嗗彲鑳芥槸鍨冨溇璇勮銆傝繖涓椂鍊欙紝濡傛灉鎮ㄥ湪鍚庡彴杩涜鍒犻櫎锛屽彲鑳戒細娴垂鎺夋偍寰堝鏃堕棿銆備互涓嬭鍙ュ彲浠ュ湪鏁版嵁搴撲腑鎵归噺鍒犻櫎鎺夋墍鏈夋湭瀹℃牳鐨勮瘎璁恒€?/p>

濂夊姖涓€鍙ワ紝杩樻槸瀹夎 Akismet 鎴栫被浼肩殑鎻掍欢鍚э紝鍙互鐪佸嵈鎮ㄥ緢澶氱儲鎭笺€?/p>

DELETE from wp_comments WHERE comment_approved = '0';

鏉ユ簮锛歨ttp://www.wprecipes.com/mark-asked-how-to-batch-deleting-spam-comments-on-a-wordpress-blog

5. 鏌ユ壘鏈娇鐢ㄧ殑鏍囩

鏍囩鐨勮褰曟槸瀛樻斁鍦?wp_terms 杩欎釜鏁版嵁琛ㄤ腑鐨勩€傛湁鏃讹紝鍙兘閮ㄥ垎鏍囩鍒涘缓浜嗕絾鏄病鏈夎浣跨敤锛屼粬浠粛鐒朵細鍦ㄦ暟鎹〃涓€備互涓嬭鍙ュ彲浠ュ杩欎簺鏈娇鐢ㄧ殑鏍囩杩涜鏌ヨ锛屾偍鍙互瀹夊叏鐨勫皢鍏跺垹闄ゃ€?/p>

SELECT * From wp_terms wt INNER JOIN wp_term_taxonomy wtt ON wt.term_id=wtt.term_id WHERE wtt.taxonomy='post_tag' AND wtt.count=0;

鏉ユ簮锛歨ttp://www.onextrapixel.com/2010/01/30/13-useful-wordpress-sql-queries-you-wish-you-knew-earlier/

6. 鏌ユ壘骞舵浛鎹㈡暟鎹?/strong>

璇ヨ鍙ヤ笉鍏夋槸鍦?WordPress 鐨勪娇鐢ㄨ繃绋嬩腑鑳界敤鍒般€傛偍鍙互鍦ㄥ緢澶氬湴鏂圭敤鍒拌 MySQL 鏌ヨ璇彞銆傚叾浣跨敤 MySQL 鐨?replace() 鍑芥暟灏嗕竴娈靛瓧绗︿覆鏇挎崲鎴愭偍鎸囧畾鐨勫彟涓€娈靛瓧绗︿覆銆?/p>

UPDATE table_name SET field_name = replace( field_name, 'string_to_find', 'string_to_replace' ) ;

鏉ユ簮锛歨ttp://perishablepress.com/press/2007/07/25/mysql-magic-find-and-replace-data/

7. 鑾峰緱鍙戣〃璇勮璁块棶鑰呯殑鐢靛瓙閭鍦板潃鍒楄〃

璇ヨ鍙ュ彲浠ヨ繑鍥炰竴涓湪鎮ㄥ崥瀹笂杩涜璇勮鐨勭敤鎴风殑鐢靛瓙閭鍦板潃鍒楄〃銆傝鍙ヤ腑鐨?DISTINCT 鍙傛暟鐢ㄦ潵淇濊瘉姣忎釜鐢靛瓙閭鍦板潃鍙樉绀轰竴娆°€?/p>

SELECT DISTINCT comment_author_email FROM wp_comments;

鏉ユ簮锛歨ttp://www.onextrapixel.com/2010/01/30/13-useful-wordpress-sql-queries-you-wish-you-knew-earlier/

8. 涓€娆℃€х鐢ㄦ帀鎵€鏈夋彃浠?/strong>

铏界劧鏂扮増鐨?WordPress 宸茬粡鍙互鐩存帴鍦ㄥ悗鍙板鎻掍欢杩涜鎵归噺鐨勫惎鐢ㄥ拰绂佺敤鎿嶄綔銆備絾鏄綋鏌愪簺鎻掍欢寮曡捣鏁翠釜绔欑偣涓嶈兘姝e父璁块棶鐨勬椂鍊欙紝鎴戜滑灏卞彲浠ヤ娇鐢ㄤ互涓嬭鍙ョ鐢ㄦ帀绔欑偣鍐呮墍鏈夌殑鎻掍欢锛岀劧鍚庡啀杩涘叆鍒?WordPress 鍚庡彴杩涜璋冭瘯鎿嶄綔銆?/p>

UPDATE wp_options SET option_value = '' WHERE option_name = 'active_plugins';

鏉ユ簮锛歨ttp://www.wprecipes.com/how-to-disable-all-your-plugins-in-a-second

9. 鍒犻櫎鎵€鏈夋爣绛?/strong>

鏍囩鐨勪俊鎭槸瀛樻斁鍦?wp_terms 鏁版嵁琛ㄤ腑鐨勩€傝€屼笖锛屾槸鍜屽垎绫讳互鍙婂叾浠栦竴浜涗俊鎭瓨鏀惧湪鐩稿悓涓€涓〃涓€傚鏋滄偍鎯冲垹闄ゆ墍鏈夌殑鏍囩璁板綍锛屾槸鏃犳硶绠€鍗曠殑娓呯┖ wp_terms 杩欎釜鏁版嵁琛ㄧ殑銆傝繖浼氬鑷村垎绫讳俊鎭涪澶便€?/p>

鎵ц浠ヤ笅璇彞锛屽彲浠ヤ粎浠呭垹闄ゆ帀鏍囩璁板綍浠ュ強涓庢棩蹇楃殑鍏宠仈淇℃伅锛岃€屽叾浠栫殑鍒嗙被绛変俊鎭笉浼氬彂鐢熸敼鍙樸€?/p>

DELETE a,b,c
FROM
	database.prefix_terms AS a
	LEFT JOIN database.prefix_term_taxonomy AS c ON a.term_id = c.term_id
	LEFT JOIN database.prefix_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id
WHERE (
	c.taxonomy = 'post_tag' AND
	c.count = 0
	);

鏉ユ簮锛歨ttp://wordpress.org/support/topic/311665

10. 鍒椾妇鏃犵敤鐨勬棩蹇椾俊鎭?/strong>

鏃ュ織鐨?Meta 淇℃伅閫氬父鏄敱鎻掍欢鎴栬嚜瀹氫箟鍖哄煙寤虹珛鐨勩€傚畠浠潪甯稿疄鐢紝浣嗕篃浼氳鎮ㄧ殑鏁版嵁搴撳昂瀵稿揩閫熺殑鍙樺緱鑷冭偪銆備互涓嬭鍙ヤ細鏄剧ず postmeta 琛ㄤ腑閭d簺娌℃湁鍦?post 琛ㄦ湁瀵瑰簲鍏崇郴鐨勮褰曪紝渚夸簬鎮ㄥ鏁版嵁搴撹繘琛屾竻鐞嗐€?/p>

SELECT * FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;

鏉ユ簮锛歨ttp://wordpress.org/support/topic/337412

11. 绂佺敤鑰佹棩蹇楃殑璇勮鍔熻兘

鏌愪簺鏃跺€欙紝鎮ㄥ笇鏈涙妸浠ュ墠鐨勬棩蹇楄瘎璁哄姛鑳藉叧闂帀銆傚彲鑳藉鑷存偍杩欎箞浣滃嚭鍐冲畾鐨勫師鍥犳湁寰堝锛屾偍鍙互浣跨敤浠ヤ笅璇彞灏嗘寚瀹氭棩鏈熶箣鍓嶅彂甯冪殑鏃ュ織璇勮鍔熻兘鍏抽棴鎺夈€?/p>

UPDATE wp_posts SET comment_status = 'closed' WHERE post_date < '2009-01-01' AND post_status = 'publish';

鏉ユ簮锛歨ttp://perishablepress.com/press/2008/02/20/wordpress-discussion-management-enable-or-disable-comments-and-pingbacks-via-sql/

12. 鏇挎崲璇勮鑰呯殑閾炬帴

涓婃枃鎻愬埌浜?MySQL 鐨?replace() 鍑芥暟銆傝鏉¤鍙ュ氨鏄竴涓緢濂界殑渚嬪瓙銆傚鏋滄偍鐨勭珯鐐瑰煙鍚嶅彂鐢熶簡鏀瑰彉锛屾偍鍙互浣跨敤璇ヨ鍙ュ皢鎮ㄥ湪鑷繁绔欎笂鍙戣〃鐨勮瘎璁轰腑鐨勯摼鎺ユ壒閲忔浛鎹负鏂扮殑鍩熷悕銆?/p>

UPDATE wp_comments SET comment_author_url = REPLACE( comment_author_url, 'http://oldurl.com', 'http://newurl.com' );

鏉ユ簮锛歨ttp://perishablepress.com/press/2008/07/14/wordpress-link-author-comments-home-page/

13. 鏇挎崲璇勮鑰呯殑鐢靛瓙閭鍦板潃

鍜屼笂涓€鏉″樊涓嶅锛屾壒閲忔浛鎹㈡帀鐢靛瓙閭鍦板潃銆?/p>

UPDATE wp_comments SET comment_author_email = REPLACE( comment_author_email, 'old-email@address.com', 'new-email@address.com' );

鏉ユ簮锛歨ttp://perishablepress.com/press/2008/05/18/wordpress-tip-update-email-address-in-the-wordpress-database

14. 鍒犻櫎鍖呭惈鎸囧畾閾炬帴鐨勮瘎璁?/strong>

鏌愪簺鍨冨溇璇勮鍙戝竷鑰呰繕鏄緢浼氶捇绌哄瓙鐨勩€傜粡甯稿彂甯冧竴浜涜矊浼间笌鏂囩珷鐩稿叧鐨勮瘎璁猴紝鍙瘎璁哄唴瀹逛腑閫氬父鍖呭惈鎭舵剰缃戠珯鐨勯摼鎺ャ€傜瓑浣犲彂鐜扮殑鏃跺€欙紝鍙兘杩欐牱鐨勮瘎璁哄凡缁忓緢澶氫簡銆備娇鐢ㄤ互涓嬩唬鐮侊紝鍙互鏂逛究鐨勫皢鍖呭惈鎸囧畾閾炬帴鍦板潃鐨勮瘎璁轰竴娆℃€у垹闄ゆ帀銆?/p>

DELETE from wp_comments WHERE comment_author_url LIKE "%wpbeginner%" ;

鏉ユ簮锛歨ttp://perishablepress.com/press/2007/07/25/mysql-magic-find-and-replace-data/

鏈枃鍙戝竷鍦?锛岃浆杞借淇濇寔鏂囩珷瀹屾暣骞舵敞鏄庡嚭澶勩€?/p>

鍘熸枃鍦板潃锛?a href="http://www.catswhocode.com/blog/wordpress-10-life-saving-sql-queries" target="_blank">10+ life saving SQL queries

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

郑重声明:资讯 【14 条实用的MySQL 查询语句| Dreamcolor's Cote】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——