Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

cron Job for an SQL query

Discussion in 'General Discussion' started by tben2505, May 27, 2010.

  1. tben2505

    tben2505 Registered

    May 27, 2010
    Likes Received:
    Trophy Points:
    Hi guys,

    I wondered if anyone could help us out. We have an SQL database running on a linux server and wish to regularly run SQL queries on it. It's basically to replace foreign characters which are somehow written to our database from the front-end forms.

    A typical SQL query we'd like to run looks something like this:

    update MainData set MD_Comment = replace(MD_Comment, '%u2013','-');

    which replaces "–" with "-" in the field "MD_Comment" in the table "MainData".

    As I understand it we can run these queries using cronjobs, which indeed we have in the past - but are now not working for some reason.

    If the database was called "database", and the username and password is "user" and "pass" for arguments sake, would someone be able to have a go at writing the cron command required in the cpanel cronjobs section?

    Many thanks for any help here, guys.


    PS It might be worth mentioning we'd need to run a few dozen of these queries, say once ever hour - in case that's useful to know. Cheers.
    #1 tben2505, May 27, 2010
    Last edited: May 27, 2010
  2. Spiral

    Spiral BANNED

    Jun 24, 2005
    Likes Received:
    Trophy Points:
    While I suppose you could directly redirect an SQL file into mysql on a cron schedule that is not really the best way to go about doing that.

    I would write a shell script (BASH or PHP works fine) that performs all the queries or processing that you want to do and then simply call that script via the cron at whatever timing that you wish.
  3. Trueliar

    Trueliar Registered

    May 30, 2010
    Likes Received:
    Trophy Points:
    Just create a script or anything else that can interact with the server (as Spiral have already suggested) and add it as cron job.
    Pay attention to where you put that script/application and it's permissions.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice