?
Solved

Remove records from mysql

Posted on 2012-04-02
19
Medium Priority
?
415 Views
Last Modified: 2012-06-22
Hi,

I have a voting poll database that received some really odd votes, the records show some very strange IPs.


4,546      Guest      455.513.414.406/24 /      April 2, 2012 @ 6:11 am
4,547      Guest      540.498.503.183/31 /      April 2, 2012 @ 6:11 am

A valid vote looks like this:


4,545      Guest      99.232.208.242 / ###.cable.rogers.com       April 2, 2012 @ 6:12 am

So i would like to run a sql query and search for all results that have these strange ip.

1) Can i run a sql command that will display the results of all strange IP addresses ?
2) Is there a REGEX sql command that that will search for invalid ip addresses ?
3) What would be the equiv. DELETE command to get rid of these queries.

Thaks,
0
Comment
Question by:ifred
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
  • 4
  • +1
19 Comments
 
LVL 32

Accepted Solution

by:
awking00 earned 0 total points
ID: 37796567
Can you provide a description of the table (i.e. column names and datatypes)?
0
 

Author Comment

by:ifred
ID: 37796675
1      pollip_id      int(10)
2      pollip_qid      varchar(10)
3      pollip_aid      varchar(10)
4      pollip_ip      varchar(100)
5      pollip_host      varchar(200)
6      pollip_timestamp      varchar(20
7      pollip_user      tinytext      utf8_general_ci
8      pollip_userid      int(10)

pollip_ip is the filed with the ip in question.
0
 
LVL 32

Expert Comment

by:awking00
ID: 37796882
So, which if any or all of these values exist in the pollip_ip field?
4,546      Guest      455.513.414.406/24 /      April 2, 2012 @ 6:11 am
4,547      Guest      540.498.503.183/31 /      April 2, 2012 @ 6:11 am
4,545      Guest      99.232.208.242 / ###.cable.rogers.com       April 2, 2012 @ 6:12 am
0
More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

 

Author Comment

by:ifred
ID: 37796912
455.513.414.406/24

and

 540.498.503.183/31

and

99.232.208.242
0
 
LVL 34

Expert Comment

by:Norie
ID: 37797048
Perhaps a stupid question, but assuming ###.cable.rogers.com is in the host field, is there always a host when the IP is valid?
0
 

Assisted Solution

by:ifred
ifred earned 0 total points
ID: 37797056
yes, i have 6000 records and i did not look at all of them but:

SELECT *
FROM  `wp_pollsip`
WHERE  `pollip_aid` LIKE  '6'
AND  `pollip_host` =  ' '
LIMIT 0 , 30

Does return me 6747 votes that i think are the ones I should null out.
0
 
LVL 34

Expert Comment

by:Norie
ID: 37797136
So you mean you want to delete the records were the host field is empty?

Try this.

DELETE FROM `wp_pollsip` WHERE `poll_host` = '';

Or this.

DELETE FROM `wp_pollsip` WHERE `poll_host` is null;
0
 

Author Comment

by:ifred
ID: 37797145
Not really. Every record has an ip, and i am wondering if one would know a SQL statement i could use that will return all fields where wp_pollsip contains an invalid IP address.
Unfortunately I am not that good with Regex expressions.
0
 
LVL 34

Expert Comment

by:Norie
ID: 37797183
So do you want to delete records with invalid IPs or validate the existing IPs?
0
 

Author Comment

by:ifred
ID: 37797194
i want to delete records with invalid IP addresses. Usually they have a number higher than 255 in at least one of the octets, those are REALLY invalid.
0
 
LVL 34

Expert Comment

by:Norie
ID: 37797273
No problem, I was trying to do something with regexp but with no luck, so when you posted the table structure I just thought using the host field might work, wishful thinking I suppose.
0
 

Author Comment

by:ifred
ID: 37797300
While it could be one of the way to do this, it is probably not the best way to do it.
Let's see if anybody else can help and thanks anyway.
0
 
LVL 32

Expert Comment

by:awking00
ID: 37797650
455.513.414.406/24
and
 540.498.503.183/31
and
99.232.208.242
So the first two are invalid why? Because they contain '/xx' at the end?
If that's the case, simply delete from wp_pollsip where instr(poll_ip,'/') >0
0
 

Author Comment

by:ifred
ID: 37797666
The first two ones are invalid because these are not valid IP numbers, IP numbers are up to 255 in any octet.
0
 
LVL 34

Expert Comment

by:Norie
ID: 37797724
An IP can't have something like /24 at the end either.
0
 
LVL 35

Assisted Solution

by:Terry Woods
Terry Woods earned 600 total points
ID: 37798256
This picks up numbers greater than 255 or more than 3 digits:

select * from wp_pollsip where pollip_ip regexp '2[6-9][0-9]|25[6-9]|[3-9][0-9]{2}|[0-9]{4}'

(edit: fixed a bug)
0
 

Assisted Solution

by:ifred
ifred earned 0 total points
ID: 37823147
I have fixed this by running a query that looked for "/" in the ip field, as i noticed it was recording this. All the fields with the "/" turned out to be invalid.
0
 
LVL 32

Expert Comment

by:awking00
ID: 37823192
Does MySQL support a regex substring command?
0
 

Author Closing Comment

by:ifred
ID: 37845919
There was not enough good answers, and my main point was still the main reason i solved my problem.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question