Delete old records based on its identifier
To delete records which have deviceid = 2 and are older than a year from the current date use

DELETE 
FROM table 
WHERE deviceid = 2 
  AND servertime &lt; CURRENT_DATE - INTERVAL 1 YEAR; -- or, maybe, &lt;=.


To delete records which are older than a year from the current date except those which have deviceid = 2 use

DELETE 
FROM table 
WHERE deviceid != 2 -- or deviceid &lt;&gt; 2
  AND servertime &lt; CURRENT_DATE - INTERVAL 1 YEAR;




To perform this action daily use MySQL's Event Scheduler. Create a schedule which is executed every day

CREATE EVENT delete_old_records
ON SCHEDULE EVERY 1 DAY          -- execute daily
            STARTS CURRENT_DATE  -- at 00:00
DO
    DELETE 
    FROM table 
    WHERE deviceid != 2
      AND servertime &lt; CURRENT_DATE - INTERVAL 1 YEAR;


And do not forget to enable event scheduler!!! Once (until disable or server restart) - by the query

SET GLOBAL event_scheduler = ON;


Permanently - by adding  --event-scheduler=ENABLED to the service command-line or event-scheduler=ENABLED to the server configuration file (preferred).