{"id":823,"date":"2010-06-07T11:14:03","date_gmt":"2010-06-07T05:44:03","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=823"},"modified":"2010-06-09T15:15:21","modified_gmt":"2010-06-09T09:45:21","slug":"changing-location-of-mysql-datastore","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/changing-location-of-mysql-datastore\/","title":{"rendered":"Changing Location of MySql DataStore"},"content":{"rendered":"<p>On one of our projects, we had to store the MySql Data at a location different from the default location. This was needed because the server was on an <a href=\"http:\/\/aws.amazon.com\/ec2\/faqs\/#What_is_the_difference_between_using_the_local_instance_store_and_Amazon_Elastic_Block_storage_for_the_root_device\" target=\"_blank\">instance-store Amazon instance<\/a> which meant that the data would get lost if the instance had to be rebooted for some reason. After going through the tutorials and articles on AWS, we came across this excellent piece on <a href=\"http:\/\/developer.amazonwebservices.com\/connect\/entry.jspa?externalID=1663\" target=\"_blank\">how to setup MySql Data store on an EBS volume<\/a>.<\/p>\n<p>Later on, I tried out the steps on the local machine and see if we could move the MySql data store to some other location on our system. As it turned out, we could and here are the steps I followed.<\/p>\n<p>Stop mysql server running on your system with the command<\/p>\n<blockquote>\n<pre lang=\"groovy\">sudo \/etc\/init.d\/mysql stop<\/pre>\n<\/blockquote>\n<p>Now, create folders named etc, lib and log at any location where you wish to save your mysql data. Let us keep them inside a folder called &#8220;\/mysqldata&#8221;<\/p>\n<blockquote>\n<pre lang=\"groovy\">mkdir etc lib log<\/pre>\n<\/blockquote>\n<p>Now, back-up your mysql data by copying the contents of \/etc\/mysql, \/var\/lib\/mysql and \/var\/log\/mysql to another location. Then, move the folders \/etc\/mysql, \/var\/lib\/mysql and \/var\/log\/mysql to the &#8220;\/mysqldata&#8221;<\/p>\n<blockquote>\n<pre lang=\"groovy\">mv \/etc\/mysql \/mysqldata\/etc\r\nmv \/var\/lib\/mysql \/mysqldata\/lib\r\nmv \/var\/log\/mysql \/mysqldata\/log<\/pre>\n<\/blockquote>\n<p>Let us now create new folders \/etc\/mysql, \/var\/lib\/mysql, \/var\/log\/mysql<\/p>\n<blockquote>\n<pre lang=\"groovy\">mkdir \/etc\/mysql\r\nmkdir \/var\/lib\/mysql\r\nmkdir \/var\/log\/mysql<\/pre>\n<\/blockquote>\n<p>Now these new directories need to be mapped with the ones we moved to &#8220;\/mysqldata&#8221;<br \/>\nThis is done by setting the mount point for each of these directories to the ones which we created.<br \/>\nTo do so, appending the following entries to &#8220;\/etc\/fstab&#8221; <\/p>\n<blockquote>\n<pre lang=\"groovy\">mkdir \/etc\/mysql\r\n\/mysqldata\/etc\/mysql \/etc\/mysql none bind\r\n\/mysqldata\/lib\/mysql \/var\/lib\/mysql none bind\r\n\/mysqldata\/log\/mysql \/var\/log\/mysql none bind\r\n<\/pre>\n<\/blockquote>\n<p>With this done, let us mount all the entries by issuing the command<\/p>\n<blockquote>\n<pre lang=\"groovy\">\r\nmount -a\r\n<\/pre>\n<\/blockquote>\n<p>MySql data store is now at another location.<\/p>\n<p>Hope this helps<\/p>\n","protected":false},"excerpt":{"rendered":"<p>On one of our projects, we had to store the MySql Data at a location different from the default location. This was needed because the server was on an instance-store Amazon instance which meant that the data would get lost if the instance had to be rebooted for some reason. After going through the tutorials [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0},"categories":[1],"tags":[248,76,8],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/823"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=823"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/823\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}