Bulk remove YOURLS (spam) URLs

Is your YOURLS database getting a bit full of spam links and other crap? You can manually mass/bulk remove all those links by running a simple query on the MySQL database.

DELETE url FROM yourls_url WHERE url LIKE '%keyword%'

You might want to replace DELETE with SELECT, so you can see what you will delete first.
What this code does is: it selects the column ‘url’ from the yourls_url table and it checks if the row ‘url’ contain the keyword you entered. You can also search for the exact url, you should then remove the percentage signs.

phpmyadmin_query

If you want to remove all the links in your YOURLS URL shortener which have no clicks, you could run something like this:

DELETE url FROM yourls_url WHERE clicks = 0

 

Author Bio

Thank you for your interest in my blog! On this miniblog, I write mostly short (technical) blog posts that might interest other people. Read more about me or feel free to contact me.

 

5 thoughts on “Bulk remove YOURLS (spam) URLs

  1. Hello. I had been looking for this query…
    Can you provide code that adds another criteria?

    Delete all links with zero hits but created before this date? Thanks!

  2. Thanks for this; had accidentally done some import testing for our wordpress site where we have YOURLS shortcodes created dynamically via API, and ended up with 1,000 items which will never get any clicks, and stupidly I didn’t do DB backup “right before” and so kinda got hosed on that. So, this was lifesaver to delete the 1,000+ items with clicks = “0”

    See, sharing info on the web is a good thing :-)

  3. Hi, I know this is old thread, but just as update on our Linux server with CentOS, php 5.6, Plesk, we actually had to use this schema

    DELETE FROM `yourls_url` WHERE `yourls_url`.`clicks` = '0';
    DELETE FROM `yourls_url` WHERE `yourls_url`.`clicks` = '1';

    1. I found out that this works:

      DELETE FROM yourls_url where url like ‘%keyword%’

      Just had to remove the first occurence of “url” from the command.

Leave a Reply

Your email address will not be published. Required fields are marked *