473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 31729
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.