473,549 Members | 2,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to automatically update a MySQL database every day

uranuskid
19 New Member
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.Therefo re, 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 31786
michaelb
534 Recognized Expert Contributor
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 Recognized Expert Specialist
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
uranuskid
19 New Member
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 Recognized Expert Contributor
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_TIMESTA MP() 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
uranuskid
19 New Member
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
uranuskid
19 New Member
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 Recognized Expert Contributor
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 New Member
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
1637
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 tablename.frm tablename.myi and tablename.myd. i have created database before one month. today i checked database and i show somefiles exist in...
2
3891
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 moment. Can i close all the connection to that database? How can i tell MySQL deamon that don´t use that database any more? Thank you in advance.
7
11446
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 convert to Hex or something. I've tried a few things but can't quite get it. Here is simplified code. mysql_select_db($dbname, $connection);
2
2315
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 functions very easy and nice. Anyway, I'm afraid that I haven't understood the data binding things correct. I'm using MySQL Connector/.NET to...
0
5742
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 copy in his own PC, they need to do some changes in their local database from time to time. then all guys need submit the changes to the central...
1
1987
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'"); mysql_query("UPDATE 'assignments' SET '$class' = '$grade' WHERE student='$student'"); mysql_query("UPDATE 'comments' SET '$class' = '$grade' WHERE...
1
2900
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 to an excel spreadsheet, I then have to manually do insert and update query's to our oracle database using this spreadsheet. I would like to...
3
2698
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 table. what if they make new changes to existing data? how do i update my mysql data base accordingly?
3
4379
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 php and mysql in my website and vb.net and mysql on the remote computer. I needed something of an update button on my vb.net application to...
0
7521
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7959
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7810
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
764
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.