{"id":307,"date":"2013-09-03T23:42:08","date_gmt":"2013-09-03T23:42:08","guid":{"rendered":"https:\/\/reviewsignal.com\/blog\/?p=307"},"modified":"2021-08-15T15:09:05","modified_gmt":"2021-08-15T19:09:05","slug":"how-to-configure-mysql-innodb-to-save-tables-in-unique-files","status":"publish","type":"post","link":"https:\/\/reviewsignal.com\/blog\/2013\/09\/03\/how-to-configure-mysql-innodb-to-save-tables-in-unique-files\/","title":{"rendered":"How To Configure MySql InnoDB to Save Tables In Unique Files"},"content":{"rendered":"<p>MySql is a great database and InnoDB is one of the engines you can use; the other popular choice is MyISAM (a good <a href=\"http:\/\/www.mysqlperformanceblog.com\/2009\/01\/12\/should-you-move-from-myisam-to-innodb\/\">post<\/a> explaining the differences). If you work with large amounts of data you can sometimes run into weird problems you didn't know about or expect.<\/p>\n<p>InnoDB saves all the tables in your database into one file: ibdata1 (and an ib_log file). That's all well and good, except it doesn't delete information from them when you erase a table. So your ibfile1 will never decrease in size. This only becomes a problem with large amounts of data and the use of temporary tables. I don't know why this is the default behavior, but there is a very simple solution to get around this problem: use unique files for each table.<\/p>\n<h2>Instructions<\/h2>\n<p><strong>Make sure you backup everything before doing this and I don't recommend doing this on a live system.<\/strong><\/p>\n<p>1. Open up your my.cnf (mysql configuration file)<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"bash\" style=\"font-family:monospace;\"><span style=\"color: #c20cb9; font-weight: bold;\">nano<\/span> <span style=\"color: #000000; font-weight: bold;\">\/<\/span>etc<span style=\"color: #000000; font-weight: bold;\">\/<\/span>mysql<span style=\"color: #000000; font-weight: bold;\">\/<\/span>my.cnf<\/pre><\/td><\/tr><\/table><\/div>\n\n<p>If you don't know where it is try searching for it:<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"bash\" style=\"font-family:monospace;\"><span style=\"color: #c20cb9; font-weight: bold;\">find<\/span> <span style=\"color: #000000; font-weight: bold;\">\/<\/span> <span style=\"color: #660033;\">-name<\/span> my.cnf<\/pre><\/td><\/tr><\/table><\/div>\n\n<p>2. Add the following under [mysqld] portion of the config:<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"bash\" style=\"font-family:monospace;\">innodb_file_per_table<\/pre><\/td><\/tr><\/table><\/div>\n\n<p>3. Remove old files: ibdata1 and ib_log<\/p>\n<p>4. Restart mysql (a couple examples below)<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"bash\" style=\"font-family:monospace;\">service mysqld restart<\/pre><\/td><\/tr><\/table><\/div>\n\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"bash\" style=\"font-family:monospace;\"><span style=\"color: #000000; font-weight: bold;\">\/<\/span>etc<span style=\"color: #000000; font-weight: bold;\">\/<\/span>init.d<span style=\"color: #000000; font-weight: bold;\">\/<\/span>mysqld restart<\/pre><\/td><\/tr><\/table><\/div>\n\n<p>MySql will now save innodb tables into unique files and delete them when you delete the tables.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySql is a great database and InnoDB is one of the engines you can use; the other popular choice is MyISAM (a good post explaining the differences). If you work with large amounts of data you can sometimes run into weird problems you didn&#8217;t know about or expect. InnoDB saves all the tables in your [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":311,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[66],"tags":[77,76,67,74],"_links":{"self":[{"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/posts\/307"}],"collection":[{"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/comments?post=307"}],"version-history":[{"count":5,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/posts\/307\/revisions"}],"predecessor-version":[{"id":3078,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/posts\/307\/revisions\/3078"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/media\/311"}],"wp:attachment":[{"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/media?parent=307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/categories?post=307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/tags?post=307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}