{"id":43,"date":"2018-04-25T11:00:06","date_gmt":"2018-04-25T09:00:06","guid":{"rendered":"http:\/\/www.wabbi.fr\/?p=43"},"modified":"2018-04-25T11:00:06","modified_gmt":"2018-04-25T09:00:06","slug":"how-to-move-mysql-data-files-to-a-bigger-partition-in-linux","status":"publish","type":"post","link":"https:\/\/www.wabbi.net\/index.php\/2018\/04\/25\/how-to-move-mysql-data-files-to-a-bigger-partition-in-linux\/","title":{"rendered":"How to move MySQL data files to a bigger partition in Linux"},"content":{"rendered":"<p>Sometimes, you install MySQL on a relatively\u00a0small partition. Then you discover that its size is no longer sufficient. It happened to me on a small AWS EC2 instance.<\/p>\n<p>The solution was to mount another partition and move MySQL data files to this location. As the performance wasn&#8217;t very important on my test server, I used an AWS EFS partition, mounted on (\/efs), for that purpose. In general, you need a high-speed SSD partition instead. Here is the process:<\/p>\n<h1>Step 1 &#8211; Stop MySQL service<\/h1>\n<p>Login to your Linux machine, and acquire\u00a0root permissions:<\/p>\n<p><strong>$\u00a0\u00a0<\/strong>sudo<strong> -i<\/strong><\/p>\n<p>Login to MySQL using command line interface:<\/p>\n<p><strong>$\u00a0\u00a0<\/strong>mysql<strong> -u root -p<\/strong><\/p>\n<p>Display the path to the data files:<\/p>\n<p><strong>mysql&gt;\u00a0\u00a0select @@datadir;<\/strong><\/p>\n<p>The result would be (\/var\/lib\/mysql)\u00a0in general.<\/p>\n<p>Type (Exit) to log out of MySQL, then stop its service:<\/p>\n<p><strong>$\u00a0\u00a0<\/strong>systemctl<strong> stop <\/strong>mysql<\/p>\n<h1>Step 2 &#8211; Copy the files to the new location<\/h1>\n<p><strong>$\u00a0\u00a0<\/strong>rsync<strong> -av \/var\/lib\/<\/strong>mysql<strong>\u00a0\u00a0<span class=\"highlight\">\/efs<\/span><\/strong><\/p>\n<p>You may change (\/efs) to the new location where you want to transfer the data files to.<\/p>\n<h1>Step 3 &#8211; Modify MySQL configuration<\/h1>\n<p>The name of MySQL configuration file is (my.cnf) or (mysqld.cnf) somewhere in (\/etc\/mysql\/) directory. Edit this file:<\/p>\n<p><strong>$\u00a0 vi \/etc\/mysql\/my.cnf<\/strong><\/p>\n<p>Search for a line that containes (datadir=) option. Make it like this:<\/p>\n<p><strong>datadir=\/efs\/mysql<\/strong><\/p>\n<p>Again, you may replace (\/efs) by your own location.<\/p>\n<p>You may now empty the original location (\/var\/lib\/mysql). I recommend deleting files only and keep the directory structure. This structure is tested is some of MySQL scripts and you may encounter some error messages if you delete the\u00a0directory (\/var\/lib\/mysql) entirely.<\/p>\n<h1>Step 4 &#8211; Start MySQL service<\/h1>\n<p><strong>$\u00a0\u00a0<\/strong>systemctl<strong> start <\/strong>mysql<\/p>\n<p>You may check that MySQL now uses the new location, just as we did in Step 1.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes, you install MySQL on a relatively\u00a0small partition. Then you discover that its size is no longer sufficient. It happened to me on a small AWS EC2 instance. The solution was to mount another partition and move MySQL data files to this location. As the performance wasn&#8217;t very important on my test server, I used &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.wabbi.net\/index.php\/2018\/04\/25\/how-to-move-mysql-data-files-to-a-bigger-partition-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to move MySQL data files to a bigger partition in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[14,15,16],"class_list":["post-43","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-linux","tag-mysql","tag-performance"],"_links":{"self":[{"href":"https:\/\/www.wabbi.net\/index.php\/wp-json\/wp\/v2\/posts\/43","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wabbi.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wabbi.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wabbi.net\/index.php\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wabbi.net\/index.php\/wp-json\/wp\/v2\/comments?post=43"}],"version-history":[{"count":2,"href":"https:\/\/www.wabbi.net\/index.php\/wp-json\/wp\/v2\/posts\/43\/revisions"}],"predecessor-version":[{"id":45,"href":"https:\/\/www.wabbi.net\/index.php\/wp-json\/wp\/v2\/posts\/43\/revisions\/45"}],"wp:attachment":[{"href":"https:\/\/www.wabbi.net\/index.php\/wp-json\/wp\/v2\/media?parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wabbi.net\/index.php\/wp-json\/wp\/v2\/categories?post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wabbi.net\/index.php\/wp-json\/wp\/v2\/tags?post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}