Clearing WordPress comments via a SQL Query

Ever have a drive-by comment spammer hit you and all a sudden you have thousands of word press comments, none of them worthwhile? If you decide that you want to declare WordPress bankruptcy and just delete all of them, you either will have a long time with the batch delete button or one simple SQL query (if you have access to the back end).

First, connect to your SQL database either via command prompt or a tool like MySql Workbench. In my case, I just ssh-ed on to the server and ran the command mysql -u <<UserName>>

After logging on I ran the command show databases; to see what databases were on my server (it had been a while since I had set up my blog) and then the command use <<database name>>; to select the proper database.

I would strongly recommend making a backup of your database before doing anything for the first time…

show tables; then listed all of the tables in the database, in my case I wanted <<wordpress prefix>>_comments. Next you run the query delete from <<wordpress prefix>>_comments where comment_approved=0;

It took a while to run but afterward, all the comments were cleaned up.

ohshit-docker (or helping a friend through some docker issues

The title is from the ohshitgit website that helps users through git related problems.
As a little bit of an introduction, it is helpful to sometimes think of docker as running containers in seperate “lightweight” VMs. This is not really the case,  but it is a helpful abstraction for this brief intro.
Just to be sure where we are at lets try running a couple of commands to be sure we are in a good state.
It is an easy thing to do after a while to have a large amount of wasted space due to old and intermedate images sitting arround but not being used. An easy quick way to clean that up is with the “docker system prune”. As the warning will tell you,

This will remove:
– all stopped containers
– all networks not used by at least one container
– all dangling images
– all dangling build cache

An -a added to the command will also prune any stopped and or unused images as well.
A good way to cut down on the need to do this is to include the –rm comand to your docker run commands.

In your case of wanting to set up a zoneminder server another feature of docker is important to remember. Docker containers by default are ephemeral, that is when they exit anything that was inside the container is gone. In your case, any configurations and data will have evaporated each time you restart your computer etc. This is less than desireable.

You said that you ran the command

docker run zoneminderhq/zoneminder:latest-ubuntu18.04

Lets break down what this exactly means… you are asking the docker daemon to run the image created by zoneminderhq named zoneminder with the tab “latest-ubuntu18.04”. If we go to the docker hub we can figure out what is actually in this image. and clicking on the dockerfile tab will show you what is in your container when it was built, command by command.
The issue with your set of commands as I was saying before is that you didn’t connect any ports to your local computer from the container and you didn’t mount in any folders to use as long term storage between container runs.

You more likely want to run something like is shown on the docker page:

docker run –rm -d -t -p 1080:80 \
-e TZ=’Europe/London’ \
-v ~/zoneminder/events:/var/cache/zoneminder/events \
-v ~/zoneminder/images:/var/cache/zoneminder/images \
-v ~/zoneminder/mysql:/var/lib/mysql \
-v ~/zoneminder/logs:/var/log/zm \
–shm-size=”512m” \
–name zoneminder \

Likely the first time you run you will need to also run before hand a script to create all the files…
mkdir ~zoneminder/
mkdir ~zoneminder/events
mkdir ~zoneminder/images
mkdir ~zoneminder/mysql
mkdir ~zoneminder/logs

So lets break down what the command is doing:

–rm cleanup any images after you exit from the container (I added this part)
-e is an environmental variable to pass into the container
-d run as detached (“daemon/service mode”)
-t allocate a psudo-tty (don’t worry about it right now)
-p expose port 80 on the container to your local port 1080
-v mount local folder to container folder
–shm sets the size of /dev/shm “tempfs”
–name an optional name (makes it easy to kill it when you want)
then the container name

By default if you don’t tell it otherwise you will start the ENTRYPOINT in the dockerfile, but if you had wanted to you could replace the -d with a -i and add to the end of the file bash and you would have a bash shell running inside the container.

You should now be able to go to http://localhost:8080/zm and see the zoneminder server.

Finally you decide that it is time to kill the container and walk away, just run the command

docker kill zoneminder


I originally shared this post on my github gist.