How do I go about do something where like every 12 hours, the webpage will add 5 to a row in Mysql? Do i have to use like unix commands or something? :0

Dani AI

Generated

asked how to add 5 to a MySQL row every ~12 hours; and pointed toward scheduling. Two practical approaches not covered above, plus safe-practice notes.

Use MySQL's built-in Event Scheduler when the server supports it and you can create events. Enable the scheduler (if not already), then create a repeating event that runs an UPDATE. Example:

SHOW VARIABLES LIKE 'event_scheduler';
SET GLOBAL event_scheduler = ON;

CREATE EVENT add_5_every_12h
ON SCHEDULE EVERY 12 HOUR
STARTS CURRENT_TIMESTAMP
DO
  UPDATE mydb.mytable
  SET counter = counter + 5
  WHERE id = 42;

CREATE EVENT requires appropriate privileges and the server-level scheduler must be enabled persistently (my.cnf) if you want it to survive restarts. See the MySQL Event Scheduler docs for details: .

If the host disallows server-side events, use a small script and an external HTTP scheduler or host task runner. A minimal PHP example using PDO:

<?php
$pdo = new PDO('mysql:host=localhost;dbname=mydb;charset=utf8mb4','user','pass',[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);
$pdo->exec("UPDATE mytable SET counter = counter + 5 WHERE id = 42");
?>

See PDO::exec for PDO usage.

Troubleshooting and cautions: test the UPDATE manually first; log the run (add a last_updated timestamp) so missed runs can be detected; server timezones affect scheduling; events do not "backfill" missed runs if the server was down β€” design the update to catch up if necessary. Verify events with SHOW EVENTS or query information_schema.EVENTS, and ensure backups exist before automating destructive changes.

Recommended Answers

All 2 Replies

Do you have access to cron on the server? With cron you can schedule it execute a file every 12hrs. That file can run the mysql query that you want.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.