{"id":6,"date":"2009-12-28T23:06:40","date_gmt":"2009-12-28T20:06:40","guid":{"rendered":"http:\/\/meekconsulting.com\/?p=6"},"modified":"2009-12-28T23:48:30","modified_gmt":"2009-12-28T20:48:30","slug":"generate-sql-to-create-indexes-in-mysql","status":"publish","type":"post","link":"https:\/\/meekconsulting.com\/?p=6","title":{"rendered":"Generate SQL to create indexes in mysql"},"content":{"rendered":"<p>If you have a mysql database table with indexes and you want to get the alter table\u00a0 commands to &#8220;create&#8221; the same indexes on another db<\/p>\n<p>You can run this sql &#8212; replacing the tablename with your table.<\/p>\n<p>Just add<\/p>\n<p>alter table TABLENAME<\/p>\n<p>Then paste the add index commands generated by the SQL below<\/p>\n<blockquote><p>SELECT\u00a0\u00a0\u00a0 concat(&#8216;add index &#8216;, i.index_name , &#8216; using BTREE(&#8216;,<br \/>\ngroup_concat(i.column_name order by i.seq_in_index), &#8216;),&#8217;) cmd<br \/>\nFROM\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 information_schema.STATISTICS i\u00a0\u00a0\u00a0\u00a0\u00a0 &#8212; i for index<br \/>\nWHERE\u00a0\u00a0 i.table_name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = &#8216;DCAS&#8217;<br \/>\nGROUP BY\u00a0\u00a0\u00a0\u00a0 i.index_name<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>If you have a mysql database table with indexes and you want to get the alter table\u00a0 commands to &#8220;create&#8221; the same indexes on another db You can run this sql &#8212; replacing the tablename with your table. Just add &hellip; <a href=\"https:\/\/meekconsulting.com\/?p=6\">Continue reading <span class=\"meta-nav\">&rarr;<\/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":[1],"tags":[3],"class_list":["post-6","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-mysql"],"_links":{"self":[{"href":"https:\/\/meekconsulting.com\/index.php?rest_route=\/wp\/v2\/posts\/6","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meekconsulting.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meekconsulting.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meekconsulting.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/meekconsulting.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6"}],"version-history":[{"count":3,"href":"https:\/\/meekconsulting.com\/index.php?rest_route=\/wp\/v2\/posts\/6\/revisions"}],"predecessor-version":[{"id":8,"href":"https:\/\/meekconsulting.com\/index.php?rest_route=\/wp\/v2\/posts\/6\/revisions\/8"}],"wp:attachment":[{"href":"https:\/\/meekconsulting.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meekconsulting.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meekconsulting.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}