{"id":1281,"date":"2015-02-12T07:24:16","date_gmt":"2015-02-12T06:24:16","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=1281"},"modified":"2015-02-13T14:21:58","modified_gmt":"2015-02-13T13:21:58","slug":"linux-move-mysql-data-directory","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=1281","title":{"rendered":"LINUX &#8211; Move MySQL data directory"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"965\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=965\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/linux2.png\" data-orig-size=\"129,150\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"Linux\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/linux2.png\" class=\" size-full wp-image-965 alignleft\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/linux2.png\" alt=\"Linux\" width=\"129\" height=\"150\" \/>In newer versions of Linux it&#8217;s not easily possible to just move the MySQL data directory to another location and modify my.cnf or create a symbolic link. There is a secutity\/protection &#8220;daemon&#8221; running in background checking which locations is some process trying to access. If it&#8217;s allowed, then access is granted, otherwise the process is unable to read\/write the required data. This guardian is called &#8220;APPARMOR&#8221;<!--more--><\/p>\n<p>I wanted to move the <em>MySQL<\/em> data directory (among others, like <em>\/var\/www<\/em>, <em>git<\/em> projects repositories, <em>owncloud<\/em> data directory, media like <em>photos<\/em>, <em>videos<\/em>, <em>music<\/em>, &#8230;) to another location on my file system due to separation of data from the rest of the running system &#8211; in case of failure I&#8217;d just re-install the system, but data stored on separated partition will remain untouched and can just be binded\/mounted to the fresh installed system.<\/p>\n<p>Let&#8217;s assume I&#8217;ve my data partition mounted as <em>\/mnt\/data. <\/em>So I moved the MySQL data directory there using:<\/p>\n<pre lang=\"bash\" gutter=\"false\">sudo mv \/var\/lib\/mysql \/mnt\/data<\/pre>\n<p>And created a symbolic link on original location<\/p>\n<pre lang=\"bash\" gutter=\"false\">cd \/var\/lib\r\nsudo ln -s \/mnt\/data\/mysql<\/pre>\n<p>When I tried to start MySQL server daemon I got the following error message:<\/p>\n<pre lang=\"bash\" gutter=\"false\">start: Job failed to start<\/pre>\n<p>So I edited the Apparmor configuration alias file for MySQL:<\/p>\n<pre lang=\"bash\" gutter=\"false\">sudo nano \/etc\/apparmor.d\/tunables\/alias<\/pre>\n<p>with the following content:<\/p>\n<pre lang=\"bash\" gutter=\"false\">...\r\nalias \/var\/lib\/mysql\/ -&gt; \/backup\/mysql\/,\r\n...<\/pre>\n<p>and reloaded the configuration using command<\/p>\n<pre lang=\"bash\" gutter=\"false\">sudo \/etc\/init.d\/apparmor reload<\/pre>\n<p>Now the MySQL server should be started correctly<\/p>\n<pre lang=\"bash\" gutter=\"false\">mysql start\/running, process 27288<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In newer versions of Linux it&#8217;s not easily possible to just move the MySQL data directory to another location and modify my.cnf or create a symbolic link. There is a secutity\/protection &#8220;daemon&#8221; running in background checking which locations is some &hellip; <a href=\"https:\/\/oprsteny.cz\/?p=1281\">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":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"LINUX - Move MySQL data directory","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[39,45,38,5],"tags":[387,66],"class_list":["post-1281","post","type-post","status-publish","format-standard","hentry","category-infrastructure","category-linux","category-software","category-tools","tag-apparmor","tag-mysql"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-kF","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1281"}],"version-history":[{"count":4,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1281\/revisions"}],"predecessor-version":[{"id":1287,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1281\/revisions\/1287"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}