{"id":824,"date":"2012-09-10T15:09:34","date_gmt":"2012-09-10T06:09:34","guid":{"rendered":"http:\/\/www.santoshkori.com\/blog\/?p=824"},"modified":"2012-09-14T14:18:01","modified_gmt":"2012-09-14T05:18:01","slug":"some-useful-mysql-query-for-wordpress-database","status":"publish","type":"post","link":"https:\/\/www.santoshkori.com\/blog\/some-useful-mysql-query-for-wordpress-database\/","title":{"rendered":"Some useful mySql Query for WordPress database"},"content":{"rendered":"<p>Here some\u00a0Some useful mySql Query for WordPress database you shold know while working on WordPress database project.<\/p>\n<h3>Optimize the Database<\/h3>\n<p>As you work on your blog, your database transactions pile up overheads which can be a performance hog. To clear such overheads and optimize your database, use this query:<\/p>\n<blockquote><p>OPTIMIZE TABLE \u2018wp_posts\u2019;<\/p><\/blockquote>\n<h3><!--more--><\/h3>\n<h3>Transfer Posts From One User to Another<\/h3>\n<p>If you wish to transfer posts and articles attributed to one user account to another account, you can use the following query (you\u2019ll need the usernames of both the accounts):<\/p>\n<blockquote><p>UPDATE wp_posts SET post_author=NEW_AUTHOR_ID WHERE post_author=OLD_AUTHOR_ID;<\/p><\/blockquote>\n<h3>Bulk Delete Comments<\/h3>\n<p>You can use this query to delete all unapproved comments.<\/p>\n<blockquote><p>DELETE FROM wp_comments WHERE comment_approved=\u20190\u2019;<\/p><\/blockquote>\n<h3>Disable All Plugins<\/h3>\n<p>Perhaps you\u2019ve accidently activated too many plugins? Or maybe you wish to make certain changes to your website and would like to disable the plugins? You can use the following query to disable all the plugins on your WP website:<\/p>\n<blockquote><p>UPDATE wp_options SET option_value=\u2019 \u2018 WHERE option_name=\u2019active_plugins\u2019;<\/p><\/blockquote>\n<h3>Disable Comments on Older Posts<\/h3>\n<p>If you wish to close comments on posts older than a specific date (say, May 5th 2012), use the following query:<\/p>\n<blockquote><p>UPDATE wp_posts SET comment_status=\u2019closed\u2019 WHERE post_date&lt;\u20192012-05-05\u2032 AND post_status=\u2019publish\u2019;<\/p><\/blockquote>\n<h3>Change Username<\/h3>\n<p>If you wish to change the username of a given user (say, \u2018abcdef\u2019), use this query:<\/p>\n<blockquote><p>UPDATE wp_users SET user_login=\u2019New-username\u2019 WHERE user_login=\u2019abcdef\u2019;<\/p><\/blockquote>\n<h3>Change Default Administrator Name<\/h3>\n<blockquote><p>UPDATE p_users SET user_login = &#8216;NewName&#8217; WHERE user_login = &#8216;Admin&#8217;;<\/p><\/blockquote>\n<h3><strong>How To Change SITE URL\u00a0 And HOME URL<\/strong><\/h3>\n<blockquote><p>update wp_options set option_value =\u2019http:\/\/yourwebsiteurl.com\u2019 where option_name=\u2019siteurl\u2019 or option_name =\u2019http:\/\/yoursiteurl.com\u2019;<\/p><\/blockquote>\n<h3>Change Image Path Only In Post Content<\/h3>\n<blockquote><p>update wp_posts SET post_content = REPLACE (post_content, &#8216;src=&#8221;<a href=\"http:\/\/www.oldsit.com%27%2C%27src%3D%22http\/\/yourcdn.newsiteurl.com&#039;\" target=\"_blank\">http:\/\/www.oldsit.com&#8217;,&#8217;src=&#8221;<\/a><a href=\"http:\/\/newsite.com%27\/\" target=\"_blank\">http:\/\/newsite.com&#8217;<\/a>);<\/p><\/blockquote>\n<p>The above query only change the source of images not the attachments available with that post, So issue the following query also along with the above one.<\/p>\n<blockquote><p><code>UPDATE wp_posts SET guid = REPLACE (guid,'<a href=\"http:\/\/www.oldsite.com\/\" target=\"_blank\" rel=\"noopener\">http:\/\/www.oldsite.com<\/a>','<a href=\"http:\/\/newsite.com\/\" target=\"_blank\" rel=\"noopener\">http:\/\/newsite.com<\/a>') WHERE post_type = 'attachment';<\/code><\/p><\/blockquote>\n<h3>Reset Password<\/h3>\n<p>Ever wanted to reset your password in WordPress, but cannot seem to use the reset password section whatever the reason?<\/p>\n<blockquote><p><code>UPDATE<\/code><code>wp_users <\/code><code>SET<\/code><code>user_pass = MD5( <\/code><code>'new_password'<\/code><code>) <\/code><code>WHERE<\/code><code>user_login = <\/code><code>'your-username'<\/code><code>;<\/code><\/p><\/blockquote>\n<h3>Transfer posts from one user to another<\/h3>\n<blockquote>\n<pre>UPDATE wp_posts SET post_author=NEW_AUTHOR_ID WHERE post_author=OLD_AUTHOR_ID;<\/pre>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Here some\u00a0Some useful mySql Query for WordPress database you shold know while working on WordPress database project. Optimize the Database As you work on your blog, your database transactions pile up overheads which can be a performance hog. To clear such overheads and optimize your database, use this query: OPTIMIZE TABLE \u2018wp_posts\u2019;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[388,387],"class_list":["post-824","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-mysql-query-for-wordpress","tag-some-useful-mysql-query-for-wordpress-database"],"_links":{"self":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/824","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/comments?post=824"}],"version-history":[{"count":4,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/824\/revisions"}],"predecessor-version":[{"id":831,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/824\/revisions\/831"}],"wp:attachment":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/media?parent=824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/categories?post=824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/tags?post=824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}