WordPress common database SQL query Daquan

https://www.wpdaxue.com/wordpress-sql.html

 

In the process of using WordPress, ultimately, we want to make changes to the database operations, such as replacing the domain name, change accessories catalog, batch modify the contents of the article and so on. This time, use the SQL query can greatly simplify our workload.

On how to manipulate SQL queries, please move " use phpMyAdmin tutorial SQL query statements modify the database information ."

Here to share some common SQL query wordpress

Note: 1. Before each use SQL queries, be sure to export the database backup! !

2. The following SQL query databases are using WordPress default  wp_  header, please according to their actual modification.

1. Remove all unused tags

1
2
3
4
5
DELETE a,b,c
FROM wp_terms AS a
LEFT JOIN wp_term_taxonomy AS c ON a.term_id = c.term_id
LEFT JOIN wp_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id
WHERE c.taxonomy = 'post_tag' AND c.count = 0

2. Delete all articles revisions (Revisions), and their Meta data

1
2
3
4
5
DELETE a,b,c
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)
WHERE a.post_type = 'revision'

3. Change the WordPress address and home address

1
2
3
UPDATE wp_options
SET option_value = replace(option_value, 'http://www.旧网址.com', 'http://www.新网址.com')
WHERE option_name = 'home' OR option_name = 'siteurl'

4. Change the GUID articles

1
2
Wp_posts UPDATE 
the SET the GUID of = REPLACE (the GUID of, 'HTTP:. // the WWW old URL .com', 'http:. // www new web site .com')

5. Change the text of the link address

1
2
Wp_posts UPDATE 
the SET post_content = REPLACE (post_content, 'HTTP:. // the WWW old URL .com', 'http:. // www new web site .com')

6. Update article Meta value

1
2
Wp_postmeta UPDATE 
the SET meta_value = REPLACE (meta_value, 'HTTP:. // the WWW old URL .com', 'http:. // www new web site .com')

7. Admin Password Reset

1
2
3
UPDATE wp_users
SET user_pass = MD5( 'new_password' )
WHERE user_login = 'admin'

8. Reset admin username

1
2
3
UPDATE wp_users
SET user_login = 'newname'
WHERE user_login = 'admin'

9. The author of a paper to transfer all of the b

1
2
3
UPDATE wp_posts
SET post_author = 'b'
WHERE post_author = 'a'

10. Delete the article meta tags

1
2
DELETE FROM wp_postmeta
WHERE meta_key = 'your-meta-key'

11. export all the comments in the e-mail address

1
2
SELECT DISTINCT comment_author_email
FROM wp_comments

12. Remove all Pingback

1
2
DELETE FROM wp_comments
WHERE comment_type = 'pingback'

13. Delete all spam

1
2
DELETE FROM wp_comments
WHERE comment_approved = 'spam'

14. Disable all active plug-ins

1
2
3
UPDATE wp_options
SET option_value = ''
WHERE option_name = 'active_plugins'

15. Meta tags list all unused

1
2
3
4
SELECT *
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE  wp.ID IS NULL

16. Close the old post comments

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

17. Update Web site's message

1
2
UPDATE wp_comments
SET comment_author_url = REPLACE( comment_author_url, 'http://旧网址.com', 'http://新网址.com' )

18. 更新正文内所有的’target=”_blank”‘为’rel=”nofollow”‘

1
2
UPDATE wp_posts
SET post_content = REPLACE (post_content, 'target="_blank',  'rel="nofollow')

以上18条来自 http://paranimage.com/19-wordpress-sql-hacks/,以后将继续补充。

19.删除未使用的Meta标签

1
2
3
4
DELETE pm
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL

20.删除重复的自定义字段(Custom Fields)

详见:https://www.wpdaxue.com/remove-duplicate-custom-fields.html

21.更改文章自定义字段的名称

1
UPDATE `wp_postmeta` SET `meta_key` = '新名称' WHERE `meta_key` = '旧名称';

#phpMyAdminSQL数据库

Guess you like

Origin blog.csdn.net/james_laughing/article/details/92778604