{"id":14,"date":"2012-08-26T00:18:55","date_gmt":"2012-08-25T22:18:55","guid":{"rendered":"http:\/\/catyellow.net\/blog\/?p=14"},"modified":"2013-06-04T21:31:11","modified_gmt":"2013-06-04T19:31:11","slug":"how-to-move-mysql-datadir","status":"publish","type":"post","link":"https:\/\/catyellow.net\/blog\/?p=14","title":{"rendered":"How to move mysql datadir"},"content":{"rendered":"<p>This example will show you how to move MySQL datadir to another dir (in my case to &#8220;\/mysqldata&#8221;) step-by-step (OS: Linux Mint):<\/p>\n<p>1. create new dir (\/mysqldata) and set permissions to it<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo mkdir \/mysqldata\r\nsudo chown mysql:mysql \/mysqldata\/\r\n<\/pre>\n<p><!--more--><\/p>\n<p>2. stop mysql<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo \/etc\/init.d\/mysql stop<\/pre>\n<p>3. copy mysql datadir with all their permissions<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo cp -R -p \/var\/lib\/mysql\/* \/mysqldata\/<\/pre>\n<p>4. edit mysql configuration file (\/etc\/my.cnf)<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo vi \/etc\/my.cnf<\/pre>\n<p>and change there datadir variable (under [mysqld] section)<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">datadir = \/mysqldata<\/pre>\n<p>5. start mysql<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo \/etc\/init.d\/mysql start<\/pre>\n<p>6. check if it works<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">mysql -u root -p -e &quot;select @@datadir\\G&quot;\r\n*************************** 1. row ***************************\r\n@@datadir: \/mysqldata\/\r\n<\/pre>\n<p>it works!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This example will show you how to move MySQL datadir to another dir (in my case to &#8220;\/mysqldata&#8221;) step-by-step (OS: Linux Mint): 1. create new dir (\/mysqldata) and set permissions to it<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[4,3],"_links":{"self":[{"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/14"}],"collection":[{"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14"}],"version-history":[{"count":10,"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/14\/revisions"}],"predecessor-version":[{"id":22,"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/14\/revisions\/22"}],"wp:attachment":[{"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}