一. move.sql
use items set @endTime=(select DATE_SUB(now(),INTERVAL 3 MONTH)); REPLACE INTO new_items (url, title) SELECT url, title FROM old_items WHERE created < @endTime ORDER BY created; DELETE FROM old_items WHERE created < @endTime
二. 执行脚本mysql.sh
#!/bin/sh cd /opt/projects/my_project mysql -hlocalhost -uxx -pxxx < move.sql