WordPress MySQL Search and Replace

by | Jul 3, 2014 | Technical Help, WordPress

There are times when you must enter the WordPress MySQL database to search and replace some content. If you don’t have to do this, then DO NOT DO THIS. If you have to do this, then your head should be examined carefully, opened up and inspected for programming errors, and then you may proceed with due and diligent care.

When might this insanity occur? This overwhelming need to destroy your blog? Most commonly it happens when you change domain or email addresses and need to make sure that all the old links are gone, replaced with the new links. Or if you have just imported massive content into the database and you’ve discovered a recurring boo boo across the majority of posts.

Reason why NOT to do this. First, because it can and will destroy your blog and database if used incorrectly. Second, if the item you wish to search and replace is found in 20 or fewer posts, fix them manually. Much less invasive and destructive.

Third, what you search for MUST be unique. It must only be found at the point where you want the change made. Searching for a domain name or email address is pretty unique content, but a group of words or code that can be found in other places will search and replace ALL of the code, screwing up everything. For example, if you search and replace every “there” for a “their”, you will end up with “their’s no place like home” or “theirfore”. I once made the mistake of deciding that “website” was to be spelled consistently on my site as “web site”. A massive search and replace turned links with the word “website” into “web%20site” which broke all such links. Do you know how many people have the word “website” in their links? Too many, and I think I linked to all of them.

If you are still willing to go forward with this amazingly stupid and risky thing to do, here are the final warnings and instructions.

BE VERY CAREFUL WITH THIS. IT WILL HURT.

Should I say, “don’t do this at home”, too? You get the point.

1. BACKUP YOUR DATABASE FIRST.

2. From within PHPMyAdmin, open your database.

3. Check the names of the table and field holding the information you want to change. For WordPress users, the most common search and replace is done on the content so we’ll use the wp-posts table and the post-content field within that table.

4. To search and replace text within your wp-posts table and the post-content field, click on the SQL tab and enter the following with the exact item you want to search for in the third line, and what you want to replace it with in the last line.

UPDATE wp_posts SET post_content = REPLACE (
post_content,
‘Item to replace here’,
‘Replacement text here’);

5. Making sure that the ONLY parts you change are within the little single ‘quotes‘.

6. Make sure EVERYTHING is spelled right and that the names of wp-posts and post_content, or whatever table and fields you are using, match the table and field within your database. Make sure that post_content is listed twice and that they match.

4. When you are sure, and you have made arrangements to have your body and brain donated to science when your brain explodes because this destroys everything in your database (okay, not really, but I’m impressing upon you the care you have to take with this – got it? Can I stop now? Good.), then click the GO or APPLY or whatever the DO IT NOW button looks like in your version of PHPMyAdmin.

5. It will then go through your database’s wp_posts table in the post_content field looking for the first line in the search and replace command, and replacing it with the second line.

6. The results will tell you how many records were changed. Let’s hope it’s the number you anticipated. If not, then restore your backup and start over.

While I jest about this process, it is a very serious and risky thing to do, but it is also very helpful. When setting up a test WordPress site, I often want all the pings closed. When I move a test site out to the public, pings need to be turned back on. To turn all the pings back on for every post and Page within my site, I used the following shortcut version of the above search and replace command:

UPDATE wp_posts SET ping_status=”open”;

If the ping_status was “closed”, it was now “open” and if it was blank, it was also now “open”. I then went through the Pages for my “About”, “Contact”, and other posts and Pages I didn’t want open to comments or pings and turned them off manually.

Again, I never do this without a backup, and even I have screwed this up, so if I can do it, I’m sure you will, too. 😉

 

CLICK HERE to find your domain name!   CLICK HERE to transfer your domain name!

Archives

Tags

24 hour (1) Accessibility (2) Accounting (1) Advertising (15) AdWare (1) Alex Johnson (2) Alignment (1) Android (2) Anti-Virus (1) Antivirus (1) Antrim Computer Repair and Service (3) APC Back-UPS (1) Appearance (2) Apple Mail (4) Apple Mobile Mail (2) Attachments (1) Audit (1) Authorized (1) Autoresponder (5) Availability (1) Backups (1) Badges (3) Bank Account (1) Bank Statement (1) Battery Backup (2) Better Business Bureau (3) Bob Hill (1) Bookkeeper (1) Branding (8) Budget (2) Business (27) Business Management (1) Catalog (1) Categories (1) Charles Oropallo (1) CharlesWorks (42) Cherryl Jensen (1) Chrome (1) CleanTalk (1) Cloud (1) Code (2) Communicating (1) Competition (1) Computer (2) Computer Cache (1) Computer Hardware (1) Computer Security (2) Constant Contact (1) Consultation (1) Contact Information (2) Content (1) Content Management (34) Content Management System (1) Copiers (1) Copy Machine (1) Coronavirus (2) Courteous (1) COVID-19 (3) Credibility (9) Credit Card (1) Credit Card Processing (1) CSS (9) Customer Service (2) Database (1) Debian (1) Design (45) Design Expertise (1) Desktop (1) Dialup (1) DirectAdmin (4) Directions (1) DIVI (7) DNS (2) Do-it-Yourself (1) Documentation (1) Domains (18) Domain Transfers (5) E-Commerce (1) ecommerce (1) Elementor (1) Email (64) Email Lists (4) Email Management (4) Email marketing (4) Etiquette (3) Eudora 6 (1) Exchange (1) Expanding (1) Facebook (1) Financial (1) Finish (1) Firefox (1) Fonts (1) Forms (2) Forms Protection (1) Fraud (2) Galaxy S4 (1) General Info (1) Gmail (1) GoDaddy (1) Google (1) Google Adwords Certified Partner (1) Google Chrome (2) Groups (1) Happy Holidays (1) Hardware Help (1) Hill Specialty Networks (1) Hosting (1) Images (1) IMAP (1) include (1) Infected (1) Information (32) insert pages (1) install (1) Internet Browsing Errors (1) Internet Consultant (1) Internet Explorer (1) Joomla! (1) Keywords (2) Laptop (1) Legibility (1) Linux (11) Logging on (1) Macintosh (1) Mail 6.0 (1) Mail 2011 (2) Make-Over (1) Malicious (1) Malware (1) Marketing (8) Matt Burke (3) MDaemon (3) MelbourneIT (2) menu (1) Merchant (1) meta (1) Microsoft (1) Microsoft Edge (1) Microsoft Hosted Exchange (5) Microsoft Live (2) Mobile Email Setup (1) Monadnock Region (1) Mozilla Firefox (2) MySQL (1) Nathan Wesley (1) Netscape (1) Netscape Messenger (1) Office Copiers (1) OfficeLive (1) Online (1) Outlook (9) Outlook 2010 (2) Outlook Express (1) PayPal (1) Pay Per Click (2) PC (1) Personal (1) Peter Harris (1) Peter Harris Creative (1) Phishing (2) PHP (3) pixel (1) plugins (1) Pop Email (1) Popularity (1) Portfolio (1) Power Grid Failure (1) PPC (1) Prevent Fraud (1) Privacy (1) Private (1) Product (6) products (1) Professional (6) Projects (2) Protect (1) Protection (1) QR codes (1) Quality (2) QuickBooks (1) Reconciliation (1) Reduce Risk (1) Register (1) Reliability (2) Renew (1) Reseller (2) Resolution (1) Restrict User Access (1) Results (1) Review (2) Risk (1) Robin Snow (1) Roundcube (1) Safe (1) Samsung (2) Scam (16) Scammer (16) Search (1) Search and Replace (1) Search Engine Optimization (SEO) (20) Security (25) Security Risk (1) Selling (1) Servers (2) Service (11) Shopping Cart (1) Site (1) SmarterMail (9) Social Engineering (1) Social Networking (1) Software (1) Solutions for Today (1) Spam (1) Spam Filtering (16) Spammer (1) Spyware (2) SquirrelMail (1) SSL (8) Statistics (2) Stats (2) Stone Pond Technology (1) Storage (1) Support (1) Tablet (1) Target Market (1) Technical Help (1) Testimonials (9) The CW Corner (1) Thom Little (1) Thom Little Associates (1) Thunderbird (3) Thunderbird 10 (2) TLD (1) Topic (1) Top Level Domains (3) Transaction (2) Transfer Data (1) Transfer Funds (1) Typography (1) Update (2) Uploading (1) UPS System (2) Up to Date (1) Virtualmin (1) Virus (2) Viruses (1) Vista (1) Web (1) Web-Over (1) Web Development (99) Web Hoster (1) Web Hosting (2) Web Hosting Company (1) Web Mail (1) Webmail (8) Webmaster (10) Webmin (1) Web Presence (26) Website (110) Website Development (1) websites (2) Web Stats (1) Web terms (1) Web Writing (1) Windows 7 (2) Windows Mail (6) Windows XP (1) WooCommerce (5) WordPress (88) WordPress Updates (1) Working Remote (2) Writing (1) YouTube (1)
Protected by CleanTalk Anti-Spam