{"id":86,"date":"2018-11-09T16:41:38","date_gmt":"2018-11-09T15:41:38","guid":{"rendered":"http:\/\/admin.bejkon.se\/?p=86"},"modified":"2019-08-12T20:13:45","modified_gmt":"2019-08-12T18:13:45","slug":"flytta-mysql-data-fran-en-tabell-till-en-annan","status":"publish","type":"post","link":"https:\/\/admin.bejkon.se\/?p=86","title":{"rendered":"Flytta mysql data fr\u00e5n en tabell till en annan"},"content":{"rendered":"<p>Flytta data fr\u00e5n HomeAutomation temps till temps_full och d\u00e4refter rensa temps s\u00e5 den bara har 2 m\u00e5naders data kvar.<\/p>\n<p>Skapa den nya tabellen om den inte finns (med samma struktur)<br \/>\n<code>CREATE TABLE temps_full SELECT * FROM temps WHERE 1=0<\/code><\/p>\n<p>D\u00e4refter k\u00f6r: (De rader med samma primary key kommer inte att kopieras)<br \/>\n<code>INSERT IGNORE<br \/>\nINTO table_1<br \/>\nSELECT *<br \/>\nFROM table_2<br \/>\n;<\/code><\/p>\n<p>T.ex.:<\/p>\n<p><code>INSERT IGNORE<br \/>\nINTO temps_full<br \/>\nSELECT *<br \/>\nFROM temps<br \/>\n;<\/code><\/p>\n<p>F\u00f6r att rensa:<br \/>\n<code>DELETE FROM `temps` WHERE date &lt; NOW() - INTERVAL 2 MONTH;<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Flytta data fr\u00e5n HomeAutomation temps till temps_full och d\u00e4refter rensa temps s\u00e5 den bara har 2 m\u00e5naders data kvar. Skapa den nya tabellen om den inte finns (med samma struktur) CREATE TABLE temps_full SELECT * FROM temps WHERE 1=0 D\u00e4refter k\u00f6r: (De rader med samma primary key kommer inte att kopieras) INSERT IGNORE INTO table_1 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/admin.bejkon.se\/?p=86\" class=\"more-link\">Forts\u00e4tt l\u00e4sa<span class=\"screen-reader-text\"> \u201dFlytta mysql data fr\u00e5n en tabell till en annan\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,17],"tags":[21,20],"class_list":["post-86","post","type-post","status-publish","format-standard","hentry","category-nix","category-windows","tag-homeautomation","tag-mysql"],"_links":{"self":[{"href":"https:\/\/admin.bejkon.se\/index.php?rest_route=\/wp\/v2\/posts\/86","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/admin.bejkon.se\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/admin.bejkon.se\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/admin.bejkon.se\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/admin.bejkon.se\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=86"}],"version-history":[{"count":4,"href":"https:\/\/admin.bejkon.se\/index.php?rest_route=\/wp\/v2\/posts\/86\/revisions"}],"predecessor-version":[{"id":112,"href":"https:\/\/admin.bejkon.se\/index.php?rest_route=\/wp\/v2\/posts\/86\/revisions\/112"}],"wp:attachment":[{"href":"https:\/\/admin.bejkon.se\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/admin.bejkon.se\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/admin.bejkon.se\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}