Mysql Partition that will delete data that is 30 days older












0















Mysql table structure is as follows :



CREATE TABLE `golden` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`query` varchar(255) NOT NULL DEFAULT '',
`store` varchar(255) NOT NULL,
`augment` longtext NOT NULL,
`intent` longtext NOT NULL,
`parsed_query` longtext NOT NULL,
`query_store` longtext NOT NULL,
`FSN` longtext,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `myIndex` (`query`,`updated_at`)
) ENGINE=InnoDB AUTO_INCREMENT=1837 DEFAULT CHARSET=utf8;


This table gets populated with 5000 queries everyday. Need a way to partition the data on 'updated_at' so that it will have only 60 days data and older data will get auto deleted.



Fairly new to this whole mysql partitions. Please help!










share|improve this question


















  • 1





    Create a process that will delete data older than 60 days and set in the cron to run it daily.

    – Samir
    Nov 16 '18 at 10:15











  • Have a requirement to use partition itself. :(

    – Archie
    Nov 16 '18 at 10:17











  • May be this will help you mysqltutorial.org/mysql-triggers/working-mysql-scheduled-event

    – Valentyn Hruzytskyi
    Nov 16 '18 at 10:29











  • Are you certan you need to use partitioning for that? Partitions do not autodelete, you still need to delete them. Partitioning has some disadvantages, and they have to be outweighted by the advantages. The advantage here is that you can delete a complete partition very fast, but it might not be worth the trouble to be able to delete 5000 rows in 0.01ms instead of 3s once a day. Also, if partitioning is used for this, it is usally a monthly thing (e.g. keep the last 3 month, which is ~60 days on the 1st and ~90 days on the 30th/31th). Could you clarify if that is ok?

    – Solarflare
    Nov 16 '18 at 13:24











  • @Solarflare Yes I need these partitions deleted every 3 months. And one 3-month partition will have around 4.5 lakh records. i want to partition my DB on 3 months.

    – Archie
    Nov 19 '18 at 6:43
















0















Mysql table structure is as follows :



CREATE TABLE `golden` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`query` varchar(255) NOT NULL DEFAULT '',
`store` varchar(255) NOT NULL,
`augment` longtext NOT NULL,
`intent` longtext NOT NULL,
`parsed_query` longtext NOT NULL,
`query_store` longtext NOT NULL,
`FSN` longtext,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `myIndex` (`query`,`updated_at`)
) ENGINE=InnoDB AUTO_INCREMENT=1837 DEFAULT CHARSET=utf8;


This table gets populated with 5000 queries everyday. Need a way to partition the data on 'updated_at' so that it will have only 60 days data and older data will get auto deleted.



Fairly new to this whole mysql partitions. Please help!










share|improve this question


















  • 1





    Create a process that will delete data older than 60 days and set in the cron to run it daily.

    – Samir
    Nov 16 '18 at 10:15











  • Have a requirement to use partition itself. :(

    – Archie
    Nov 16 '18 at 10:17











  • May be this will help you mysqltutorial.org/mysql-triggers/working-mysql-scheduled-event

    – Valentyn Hruzytskyi
    Nov 16 '18 at 10:29











  • Are you certan you need to use partitioning for that? Partitions do not autodelete, you still need to delete them. Partitioning has some disadvantages, and they have to be outweighted by the advantages. The advantage here is that you can delete a complete partition very fast, but it might not be worth the trouble to be able to delete 5000 rows in 0.01ms instead of 3s once a day. Also, if partitioning is used for this, it is usally a monthly thing (e.g. keep the last 3 month, which is ~60 days on the 1st and ~90 days on the 30th/31th). Could you clarify if that is ok?

    – Solarflare
    Nov 16 '18 at 13:24











  • @Solarflare Yes I need these partitions deleted every 3 months. And one 3-month partition will have around 4.5 lakh records. i want to partition my DB on 3 months.

    – Archie
    Nov 19 '18 at 6:43














0












0








0








Mysql table structure is as follows :



CREATE TABLE `golden` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`query` varchar(255) NOT NULL DEFAULT '',
`store` varchar(255) NOT NULL,
`augment` longtext NOT NULL,
`intent` longtext NOT NULL,
`parsed_query` longtext NOT NULL,
`query_store` longtext NOT NULL,
`FSN` longtext,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `myIndex` (`query`,`updated_at`)
) ENGINE=InnoDB AUTO_INCREMENT=1837 DEFAULT CHARSET=utf8;


This table gets populated with 5000 queries everyday. Need a way to partition the data on 'updated_at' so that it will have only 60 days data and older data will get auto deleted.



Fairly new to this whole mysql partitions. Please help!










share|improve this question














Mysql table structure is as follows :



CREATE TABLE `golden` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`query` varchar(255) NOT NULL DEFAULT '',
`store` varchar(255) NOT NULL,
`augment` longtext NOT NULL,
`intent` longtext NOT NULL,
`parsed_query` longtext NOT NULL,
`query_store` longtext NOT NULL,
`FSN` longtext,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `myIndex` (`query`,`updated_at`)
) ENGINE=InnoDB AUTO_INCREMENT=1837 DEFAULT CHARSET=utf8;


This table gets populated with 5000 queries everyday. Need a way to partition the data on 'updated_at' so that it will have only 60 days data and older data will get auto deleted.



Fairly new to this whole mysql partitions. Please help!







mysql database-partitioning






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 10:12









ArchieArchie

244




244








  • 1





    Create a process that will delete data older than 60 days and set in the cron to run it daily.

    – Samir
    Nov 16 '18 at 10:15











  • Have a requirement to use partition itself. :(

    – Archie
    Nov 16 '18 at 10:17











  • May be this will help you mysqltutorial.org/mysql-triggers/working-mysql-scheduled-event

    – Valentyn Hruzytskyi
    Nov 16 '18 at 10:29











  • Are you certan you need to use partitioning for that? Partitions do not autodelete, you still need to delete them. Partitioning has some disadvantages, and they have to be outweighted by the advantages. The advantage here is that you can delete a complete partition very fast, but it might not be worth the trouble to be able to delete 5000 rows in 0.01ms instead of 3s once a day. Also, if partitioning is used for this, it is usally a monthly thing (e.g. keep the last 3 month, which is ~60 days on the 1st and ~90 days on the 30th/31th). Could you clarify if that is ok?

    – Solarflare
    Nov 16 '18 at 13:24











  • @Solarflare Yes I need these partitions deleted every 3 months. And one 3-month partition will have around 4.5 lakh records. i want to partition my DB on 3 months.

    – Archie
    Nov 19 '18 at 6:43














  • 1





    Create a process that will delete data older than 60 days and set in the cron to run it daily.

    – Samir
    Nov 16 '18 at 10:15











  • Have a requirement to use partition itself. :(

    – Archie
    Nov 16 '18 at 10:17











  • May be this will help you mysqltutorial.org/mysql-triggers/working-mysql-scheduled-event

    – Valentyn Hruzytskyi
    Nov 16 '18 at 10:29











  • Are you certan you need to use partitioning for that? Partitions do not autodelete, you still need to delete them. Partitioning has some disadvantages, and they have to be outweighted by the advantages. The advantage here is that you can delete a complete partition very fast, but it might not be worth the trouble to be able to delete 5000 rows in 0.01ms instead of 3s once a day. Also, if partitioning is used for this, it is usally a monthly thing (e.g. keep the last 3 month, which is ~60 days on the 1st and ~90 days on the 30th/31th). Could you clarify if that is ok?

    – Solarflare
    Nov 16 '18 at 13:24











  • @Solarflare Yes I need these partitions deleted every 3 months. And one 3-month partition will have around 4.5 lakh records. i want to partition my DB on 3 months.

    – Archie
    Nov 19 '18 at 6:43








1




1





Create a process that will delete data older than 60 days and set in the cron to run it daily.

– Samir
Nov 16 '18 at 10:15





Create a process that will delete data older than 60 days and set in the cron to run it daily.

– Samir
Nov 16 '18 at 10:15













Have a requirement to use partition itself. :(

– Archie
Nov 16 '18 at 10:17





Have a requirement to use partition itself. :(

– Archie
Nov 16 '18 at 10:17













May be this will help you mysqltutorial.org/mysql-triggers/working-mysql-scheduled-event

– Valentyn Hruzytskyi
Nov 16 '18 at 10:29





May be this will help you mysqltutorial.org/mysql-triggers/working-mysql-scheduled-event

– Valentyn Hruzytskyi
Nov 16 '18 at 10:29













Are you certan you need to use partitioning for that? Partitions do not autodelete, you still need to delete them. Partitioning has some disadvantages, and they have to be outweighted by the advantages. The advantage here is that you can delete a complete partition very fast, but it might not be worth the trouble to be able to delete 5000 rows in 0.01ms instead of 3s once a day. Also, if partitioning is used for this, it is usally a monthly thing (e.g. keep the last 3 month, which is ~60 days on the 1st and ~90 days on the 30th/31th). Could you clarify if that is ok?

– Solarflare
Nov 16 '18 at 13:24





Are you certan you need to use partitioning for that? Partitions do not autodelete, you still need to delete them. Partitioning has some disadvantages, and they have to be outweighted by the advantages. The advantage here is that you can delete a complete partition very fast, but it might not be worth the trouble to be able to delete 5000 rows in 0.01ms instead of 3s once a day. Also, if partitioning is used for this, it is usally a monthly thing (e.g. keep the last 3 month, which is ~60 days on the 1st and ~90 days on the 30th/31th). Could you clarify if that is ok?

– Solarflare
Nov 16 '18 at 13:24













@Solarflare Yes I need these partitions deleted every 3 months. And one 3-month partition will have around 4.5 lakh records. i want to partition my DB on 3 months.

– Archie
Nov 19 '18 at 6:43





@Solarflare Yes I need these partitions deleted every 3 months. And one 3-month partition will have around 4.5 lakh records. i want to partition my DB on 3 months.

– Archie
Nov 19 '18 at 6:43












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335631%2fmysql-partition-that-will-delete-data-that-is-30-days-older%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335631%2fmysql-partition-that-will-delete-data-that-is-30-days-older%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values