{"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 \u201ccreate\u201d the same indexes on another db<\/p>\n<p>You can run this sql \u2014 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(\u2018add index \u2018, i.index_name , \u2018 using BTREE(\u2018,<br \/>\ngroup_concat(i.column_name order by i.seq_in_index), \u2018),\u2019) cmd<br \/>\nFROM\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 information_schema.STATISTICS i\u00a0\u00a0\u00a0\u00a0\u00a0 \u2014 i for index<br \/>\nWHERE\u00a0\u00a0 i.table_name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = \u2018DCAS\u2019<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 \u201ccreate\u201d the same indexes on another db You can run this sql \u2014 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":[],"categories":[1],"tags":[3],"_links":{"self":[{"href":"https:\/\/meekconsulting.com\/index.php?rest_route=\/wp\/v2\/posts\/6"}],"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}]}}