Batch Replace/Delete Data in MySQL Database: VPS BIBLE




new password?
login
X

Update (Replace or Delete) MySQL Data

website file structure image

Change repetitive db data with one single syntax command. Rather than manually find & alter each instance, isolate the lot & update multiple content.

This is handy when you want to swap or lose an identical content string across all the data entries in a db table field.

Use it with care but, hey, talk about a time saver.

Setup Unmanaged VPS: The Ubuntu-Nginx Guide

Take your virtual private server from zero to hero

  .. from blank box to cute-as server ..  

with this easy-to-follow copy/paste guide.

22+ parts with video, here’s the index.

Log into your CLI, then into mysql like this:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

.. and input your mysql password.

Now, let’s open the database we want to manipulate:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

.. where database is the name of your db.

The command itself:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

“Update” Syntax Broken Down

  • UPDATE tells mysql we want to change something
  • table is the database table in which we want to change something
  • SET field will isolate the specific field, within the table we specified already, for alteration
  • = tells mysql we’re about to equate the actual change within that specified field within that specified table
  • field is where we remind mysql of the field. I dunno why we repeat ourselves but we just do
  • old is the string of data we want to change
  • new is the content to replace the old string

NB we use backticks (`) to target tables and fields, and quotation marks () to specify the content

OK. Here’s an example.

Let’s say you’ve got a WordPress blog littered with references to some bloke called Jack, but Jack just had a change of mind and now answers to the name of Jill. OK, sorry, but bear with me, it’s a spur of the moment example. So you want to swap Jack for Jill.

The string Jack can be found in a specific field within a specific table. In this case, and with WordPress, the table is wp_posts and the field within is post_content. We’ve already specified our db. When making the content change, we must now isolate the field, within its table.

Here’s the code:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

MySQL will come back and tell you it’s done with something like:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

And to Delete a String of Content in MySQL?

Probably there are other ways to do this, but this related method works for me:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

.. Now we’ve replaced Jack with nothing. He’s gone.

Setup Unmanaged VPS: The Ubuntu-Nginx Guide

Take your virtual private server from zero to hero

with this easy-to-follow copy/paste guide.

“My local PC runs Windows” Show me for Linux

22+ parts with video, here’s the index ..

Manage Unmanaged VPS: Ubuntu-Nginx Administration

Already set it up? We’d best maintain it then.

Toggle to the ..  Ubuntu-Nginx Admin Index

Manage Unmanaged VPS: Ubuntu-Nginx Administration

Maintain your virtual private server with ..

.. cheatsheets, tutorials, tips & guides.

Head back to the ..  Ubuntu-Nginx Installation Index

Nginx Admin: In the Works ..

This lot’s marked for addition already:-

  • Setup or Edit DNS using Bind
  • Network Tools Troubleshooting Guide
  • The Comprehensive Permissions Guide
  • Configuring Nginx Rewrites
  • Custom Website Error Page
  • Setting up Cron Jobs
  • Rsync for Incremental Remote-to-Local Backup
  • Cron & Rsync for Automatic Backup
  • Cron & mysqldump for Auto DB Backup
  • Safeguard Bandwidth with Hotlink Protection
  • Block Access with Nginx’ IP Deny



Got a Question? Want to Comment?

This site has no comments system. We've got a better system!

Please use the link at the top of the post and goto this topic's forum thread:-

  • to help build community
  • for a superior knowledge base
  • to keep info in one place, not diluted between forum & comments.

For those posts ported from Guvnr.com (pre-Feb/2010), archive comments remain.

Handy info from these comments is in the process of being ported to the forum and attributed to the original author.

If you think this idea sucks, let me know.

Thank you.