472,804 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,804 software developers and data experts.

How to automatically update a MySQL database every day

uranuskid
Hey folks,

I'm curious about how to perform following task:

I need to update a MySQL database every day in terms of deleting expired entries.Therefore, I have to fields in the db named 'date' and 'expired' (which is the actual date ... How do I get that again?).

So, I want to run a script that compares both fields and deletes respective entries where both fields match.

I want to do this at the end of the day and the auto_increment field should be updated for the whole db.

If anyone could drop me some hints would be appreciated.

Thanks
uranuskid
Mar 11 '07 #1
8 31478
michaelb
534 Expert 512MB
I think the SQL to update your table may look like this:
Expand|Select|Wrap|Line Numbers
  1. delete from my_table where current_date >= expiration_date
  2.  
I am not sure about this:
>> the auto_increment field should be updated for the whole db.
You did not say anything about this field, and auto_increment is something that typically managed by the database (a new record ID, for example)

You can execute your script using the MySQL Event Scheduler.
It allows you create a new event, set the schedule, and provide the SQL for this event.

You may find these links helpful:
http://dev.mysql.com/tech-resources/...t-feature.html

http://dev.mysql.com/doc/refman/5.1/en/events.html
Mar 11 '07 #2
ronverdonk
4,258 Expert 4TB
I want to do this at the end of the day and the auto_increment field should be updated for the whole db.
When you want to reset your auto_increment field, you'll have to create a new table (like the one you have now) and insert your current table in that one.
That way the auto_increment field is re-started from the beginning.
After that delete the old table one and rename the new one.

Ronald :cool:
Mar 12 '07 #3
I think the SQL to update your table may look like this:
Expand|Select|Wrap|Line Numbers
  1. delete from my_table where current_date >= expiration_date
  2.  
You may find these links helpful:
http://dev.mysql.com/tech-resources/...t-feature.html

http://dev.mysql.com/doc/refman/5.1/en/events.html
Thanks for the help.

Just to get it right, what I need to do is create a recurrent even scheduler that updates my current date and then compares it with expiring date and then deletes all entries that are expired. Do you reckon I'll get problems doing this with MyPHPadmin on the webserver?

Cheers,
uranuskid
Mar 12 '07 #4
michaelb
534 Expert 512MB
If you're asking whether you can use MyPHPadmin to create an event I don't see why not.
Provided that you have required privileges/permissions to the database, you should be able to run the "CREATE EVENT ..." sql just like you run "CREATE TABLE ..." or any other DML, using MyPHPadmin or any other interface you may have.

I don't quite understand why you need the current_date column.
Unless there's something you did not tell us, I would drop this nuisance and compare column expiration_date with result of CURRENT_TIMESTAMP() or CURRENT_DATE(), or whichever date/time function is appropriate for your situation.
In this case your SQL may look like this:

Expand|Select|Wrap|Line Numbers
  1. delete from my_table where expiration_date >= CURRENT_DATE()
  2.  
Mar 12 '07 #5
Also ich hab das jetzt alles mal ausprobiert und das entsprechende im Manula gelesen. Kling alles sehr logisch. Nur leider geht es bei mir nicht. Liegt das an meiner MYSQL version (4.1.21) oder an meinem code:
Expand|Select|Wrap|Line Numbers
  1. CREATE event delete 
  2. on schedule every 1 day starts at timestamp '2007-03-25 23:59:00' 
  3. do delete from rides where current_date()v>=v RideDate();
Mar 25 '07 #6
Also ich hab das jetzt alles mal ausprobiert und das entsprechende im Manula gelesen. Kling alles sehr logisch. Nur leider geht es bei mir nicht. Liegt das an meiner MYSQL version (4.1.21) oder an meinem code:
Expand|Select|Wrap|Line Numbers
  1. CREATE event delete 
  2. on schedule every 1 day starts at timestamp '2007-03-25 23:59:00' 
  3. do delete from rides where current_date()v>=v RideDate();
Sorry, that was German. Forgott that I'm on an English forum. Well, I tried all the advices and they seem logic, also I read the respective Manual pages. However, it won't work. I wonder is it because of my version (4.1.21) or because of the wrong code (see above)

Cheers,
Frank
Mar 25 '07 #7
michaelb
534 Expert 512MB
I think you are correct with your first assumption; the Event Scheduler Syntax manual says this:
MySQL 5.1.6 and later provides several SQL statements for working with scheduled events:

Does upgrading to v. 5.1 look like a feasible option for you?
Mar 26 '07 #8
Ahhu
1
There is a problem in the syntax you used:
Expand|Select|Wrap|Line Numbers
  1. on schedule every 1 day starts at timestamp '2007-03-25 23:59:00'
Should be only:
Expand|Select|Wrap|Line Numbers
  1. on schedule every 1 day starts '2007-03-25 23:59:00'
If you're using phpMyAdmin, just go to:
http://YOURDOMAIN/phpmyadmin/db_events.php?db=YOUR_DB
And you can quickly create as many events as you want without ever knowing the proper syntax for events.
But if you insist in DIY, double check your syntax with:
http://dev.mysql.com/doc/refman/5.1/...ate-event.html

Btw, thanks for your code, it was the first time I saw SQL events like this and I used your code for a similar purpose. It worked after I removed that "at timestamp".
Mar 4 '15 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: vishal | last post by:
i have created one database in mysql. first i have created all tables are of innodb type then i converted all tables to myisam type. i know that for each myisam type table three files are created...
2
by: Carlos Eduardo Peralta | last post by:
Hello: Can i update a MySQL database with just copy the files MYI MYD and FRM in the right dir? I know this work. The question is how MySQL manage the user that are usig that database in that...
7
by: sime | last post by:
Hi, I have a blob field in a mysql database table. I want to copy a blob from one record to another. I am having trouble transferring the data via a php variable. Maybe I need to addslashes or...
2
by: Ville Mattila | last post by:
Hi there, I will post my question to this group too bacause the .data group seems to be rather quiet. I've been playing with VB.NET and ADO for a week now and find the different data handling...
0
by: Hans | last post by:
Hi, That's my first time to send mail to this address for asking help. Sorry for my poor english firstly. My case is like this: Many guys are using a mysql database, each guy has a database...
1
tolkienarda
by: tolkienarda | last post by:
i need to update a database table using variables in unusual places here are the update statements mysql_query("UPDATE 'grades' SET '$class' = '$grade' WHERE student='$student'");...
1
by: Master Ken | last post by:
Hi All, I'm very new to C# and ASP and I am asking for some help as I don't really know where to start on this project. Some background info first I run a report each week which outputs data...
3
by: olddocks | last post by:
i have a strange problem. I have a massive database with primary key being autoincrement ID and other fields. The company i work with often publishes the data in excel sheet and i converted to mysql...
3
by: Neil Domingo | last post by:
I have an online hosted website that uses mysql database. Now, what I am trying to do was to update my remote database. What I mean was, a different mysql database that is not online. I used...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.