473,385 Members | 1,311 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Removing a row when compared to another database or text file.

Hello,
I have a company MySQL database containing e-mail addresses. Some of
these addresses are bad. I have a text file with the addresses I need
to remove from the MySQL database.

Is there a way to compare the database against my text file, then when
an address matches, remove the row from the database?

Should I imnport the text file to new database then do the compare?
What I'm stuck on is how to execute a compare then remove the row if a
match is found. (Still a little new to MySQL). A point in the right
direction needed.

Thanks!
Frank Maestas
Jul 20 '05 #1
1 1449
Frank Maestas wrote:
Is there a way to compare the database against my text file, then when
an address matches, remove the row from the database?


Easiest way that comes to my mind is something like this:

You have a text file that looks like this:
-----------------
ad*****@domain.com.invalid
ad******@domain.com.invalid
ad******@domain.com.invalid
-----------------

And you have a table that looks perhaps like this:

| mytable |
-----------
| id |
| name |
| email |
-----------

You could use a text editor (a little more advanced than notepad) to
modify your text file to look something like this:

----------------
delete from mytable where email = 'ad*****@domain.com.invalid';
delete from mytable where email = 'ad******@domain.com.invalid';
delete from mytable where email = 'ad******@domain.com.invalid';
----------------

With a modern text editor you should be able to for example find and
replace line change with

';\ndelete from mytable where email = '

And then manually fix the first and last line.

Then when you got the file ready, you can use for example mysql console
program to execute sql-statements:

mysql -u root -p databasename < yourfile.txt

Since you are deleting stuff from the database, I advice to take a
backup from database before giving commands that will delete rows. (Of
course this should be obvious, but I am telling it anyway, because so
many people don't take backups and then they cry about the lost data...)
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

66
by: Cor | last post by:
Hi, I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever. It...
4
by: sri2097 | last post by:
Hi all, I'm storing number of dictionary values into a file using the 'cPickle' module and then am retrieving it. The following is the code for it - # Code for storing the values in the file...
7
by: Simon Hart | last post by:
Hi, I have a requirement to remove the xmlns from the DOM in order to pass over to MS CRM 3.0 Fetch method.It seems the fetch method blows up if there is a xmlns present!?! The reason I have a...
14
by: @sh | last post by:
Guys, We're in the midst of building a new site and have some decisions to make RE the meta data, i.e. Title, Keywords and Description. We need to allow other non development staff to update...
3
by: LurfysMa | last post by:
I would like to hear opinions on the tradeoffs of putting the tables, forms, and queries for several related datasets in separate databases vs one combined database. I am working on an...
17
by: Eric_Dexter | last post by:
def simplecsdtoorc(filename): file = open(filename,"r") alllines = file.read_until("</CsInstruments>") pattern1 = re.compile("</") orcfilename = filename + "orc" for line in alllines: if not...
1
by: cgillett76 | last post by:
Hello, I'm using InfoPath to write data to a accessvdatabase. Once the form has been submitted a VB script runs to create a text file to input to another application. Some of the fields contain...
24
by: sonos | last post by:
Hi, I am working on a program to archive data to disk. At what point is it best to use a relational database like MySQL as the backend instead of a C program alone? Thanks to any and all...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.