Changing values with MySQL in a table over time - mysql

I have a resource table for a game I'm trying to code, and each resource has a fixed income rate over time. But I can't find any description on how to increase the stored values of the MySQL Table over time automatically.
I'm using NetBeans to connect the program with the database, but I want the values to be updated on the server without the need to run the program. Otherwise I would just have had the time recorded and just add the time difference value.
Is there a way of doing this?
Table:
Player ID: 1
Gold: 100
Wood: 100
Increase rate: 50 per hour

One way of doing this is using Cron jobs and schedule some script to run.
Otherwise you can simply calculate the time elapsed from the beginning and (whithout updating your DB) calculate values based on the time when your program is running.

You can define a cron job on the server, that runs a query to update the values.

Yes, you can by adding a scheduled event like this. However, if you update the value in the database, the value/variable stored by the program will not be updated in real-time: you have to query the database for the updated value.

Related

MySQL Event Scheduler Limit

Hi I was thinking of setting around 40-50 or even more MySQL Event that run on an hourly basis to update a specific column data. Is it gonna cause application failure if i do so ?
The main purpose is to implement an hourly billing system by updating the column data with a fixed rate hourly

How to get MySQL status variables every second?

I am using MySQL workbench 6.3 CE. I want to take the snapshots of MySQL status variables.
I want to store the values of status variables after every 1 second during the execution of query.
I can simply show the variables using 'show global status'. But I want to execute it automatically after every 1 second.
You can run a procedure and a query at the same time by having two separate connections. Workbench is a handy tool, but you should learn to use the mysql commandline tool, too.
The query is rather simple. INDEX(l_shipdate) is likely to be the best for it.
The real way to speed up the query (assuming that is your ultimate goal) is to build and maintain a "Summary table" of daily or monthly subtotals. Then sum the sums and sum the counts. Avg is (SUM(sums)/SUM(counts)).
More discussion: http://mysql.rjweb.org/doc.php/summarytables
Be cautious about running (via EVENT or cron) any code that might take longer than the interval time. If it gets behind, it is likely to cascade and bring the server down, or at least slow things down severely. For that reason, I much prefer the WHILE loop.

Server Monitoring Software - designing database MySQL

I want to create a monitoring script that will check my servers. Right now I'm stuck on a problem, I need to find out a way to get uptime percentage. Basically all data is stored in MySQL server, for me the easiest way to get uptime is to create a function that will add a new record to mysql server every minute with date, time, information is it online etc. but if I will use this method and I will have for example 1000 servers to monitor, I will end up with 518 400 000 records in MySQL server per year.
Another idea was to create one record per server with two rows online and offline, but without any date and time I'm not able to get uptime...
Any ideas how to design database for monitoring system ?
The MySQL information_schema contains uptime information (expressed in seconds) for each server. I am not sure how accurate your figure has to be, but you could get this value at a set interval and compare it to the previous value. Depending on the interval, this could give you a good approximation.
SELECT Variable_Value FROM SESSION_STATUS S WHERE Variable_Name = 'UPTIME';
Also, the MySQL error log contains a date and time stamp when the server starts. Scrape this info periodically and add to your server table.

Running multiple query concurrently

I've have a event which runs every morning at 1 AM.
The aim of the event is to do some calculation on the database and save it in a table.
I have a procedure, say spCalc which takes a unique mission_id as parameter. i have to calculate for 5 missions, so i have to execute the procedure like
call spCalc(1);
call spCalc(2);
..
call spCalc(5);
Can i run this stored procedures concurrently so i can insert into a table more faster.
Update:
The reason why i'm inserting data a table is:
I've to generate reports with more than 10 lakhs of records and to join more than 30 tables, as you know, it will take couple of hours to generate a report. We want to reduce this delay.
I'm doing some calculation like , i need to use max() function and to process all the data to find the highest. It would take lot of time when we process all the data.
So what we decided is to run the calculations every day morning and to save it, so it would be faster to retrieve.

How to ask database to automatically reassign a certain value in a table after 24 hours?

Let's say a player's energy is recorded in a table as "20". As he engages in mission, his energy decreases and reaches 0. However, it would be replenish back to "20" the following day. How do the database detect that a new day has arrive and then automatically assign some value in a certain table?
Store in database the time (date and hour) when energy should be restored. Then each time player logs in check if this time passed yet or not. If it has, restore the energy.
Upgrade to MySQL 5.1 and use events. http://dev.mysql.com/tech-resources/articles/mysql-events.html
for people who are using shared hosting like me, go look for "cron jobs" in your control panel and then set your automated task there.
Not at all. Call a stored procedure / execute SQL regularly from OUTSIDE the database.
Use a Trigger that'll run when your condition is verified