{"id":3081,"date":"2015-08-05T14:02:11","date_gmt":"2015-08-05T14:02:11","guid":{"rendered":"http:\/\/blog.shineservers.com\/?p=3081"},"modified":"2015-08-05T14:02:11","modified_gmt":"2015-08-05T14:02:11","slug":"how-to-move-mysql-data-directory-on-a-separate-partition","status":"publish","type":"post","link":"https:\/\/www.shineservers.com\/2015\/08\/05\/how-to-move-mysql-data-directory-on-a-separate-partition\/","title":{"rendered":"How To Move MySQL Data Directory On A Separate Partition"},"content":{"rendered":"<p><strong>Prerequisite:<\/strong> A\u00a0free partition that will serve as a dedicated MySQL partition.<\/p>\n<p>Note: These instructions assume that the partition you wish to mount is \/dev\/sdc1<\/p>\n<ol>\n<li>Backup all MySQL databases\n<div class=\"bbCodeBlock bbCodeCode\">\n<div class=\"type\">Code:<\/div>\n<pre>mysqldump --opt --all-databases | gzip &gt; \/home\/alldatabases.sql.gz<\/pre>\n<\/div>\n<\/li>\n<li>Stop tailwatchd and the mysql (tailwatchd monitors services, so disable it to prevent it from prematurely restarting mysql)\n<div class=\"bbCodeBlock bbCodeCode\">\n<div class=\"type\">Code:<\/div>\n<pre>\/scripts\/restartsrv_tailwatchd --stop\n\/scripts\/restartsrv_mysql --stop<\/pre>\n<\/div>\n<\/li>\n<li>Backup the MySQL data directory in case something goes awry\n<div class=\"bbCodeBlock bbCodeCode\">\n<div class=\"type\">Code:<\/div>\n<pre>mv \/var\/lib\/mysql \/var\/lib\/mysql.backup<\/pre>\n<\/div>\n<\/li>\n<li>Create the new mount point\n<div class=\"bbCodeBlock bbCodeCode\">\n<div class=\"type\">Code:<\/div>\n<pre>mkdir \/var\/lib\/mysql<\/pre>\n<\/div>\n<\/li>\n<li>Configure \/etc\/fstab so that the new partition is mounted when the server boots (adjust values as necessary)\n<div class=\"bbCodeBlock bbCodeCode\">\n<div class=\"type\">Code:<\/div>\n<pre>echo \"\/dev\/sdc1     \/var\/lib\/mysql     ext3     defaults,usrquota    0 1\" &gt;&gt; \/etc\/fstab<\/pre>\n<\/div>\n<\/li>\n<li>Mount the new partition. The following command will mount everything in \/etc\/fstab:\n<div class=\"bbCodeBlock bbCodeCode\">\n<div class=\"type\">Code:<\/div>\n<pre>mount -a<\/pre>\n<\/div>\n<\/li>\n<li>Change the ownership of the mount point so that it is accessible to the user &#8220;mysql&#8221;\n<div class=\"bbCodeBlock bbCodeCode\">\n<div class=\"type\">Code:<\/div>\n<pre>chown mysql:mysql \/var\/lib\/mysql<\/pre>\n<\/div>\n<\/li>\n<li>Ensure that the permissions of the mount point are correct\n<div class=\"bbCodeBlock bbCodeCode\">\n<div class=\"type\">Code:<\/div>\n<pre>chmod 711 \/var\/lib\/mysql<\/pre>\n<\/div>\n<\/li>\n<li>Start mysql and tailwatchd\n<div class=\"bbCodeBlock bbCodeCode\">\n<div class=\"type\">Code:<\/div>\n<pre>\/scripts\/restartsrv_mysql --start\n\/scripts\/restartsrv_tailwatchd --start<\/pre>\n<\/div>\n<\/li>\n<li>Ensure that the MySQL data directory is mounted correctly:\n<div class=\"bbCodeBlock bbCodeCode\">\n<div class=\"type\">Code:<\/div>\n<pre>mount |grep \/var\/lib\/mysql<\/pre>\n<\/div>\n<\/li>\n<li>You should see a line that looks like this:<br \/>\n\/dev\/sdc1 on \/var\/lib\/mysql type ext3 (rw,usrquota)<\/li>\n<\/ol>\n<p><a href=\"https:\/\/forums.cpanel.net\/threads\/how-to-move-mysql-data-directory.110481\/#post-861642\" target=\"_blank\" rel=\"noopener noreferrer\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prerequisite: A\u00a0free partition that will serve as a dedicated MySQL partition. Note: These instructions assume that the partition you wish to mount is \/dev\/sdc1 Backup all MySQL databases Code: mysqldump &#8211;opt &#8211;all-databases | gzip &gt; \/home\/alldatabases.sql.gz Stop tailwatchd and the mysql (tailwatchd monitors services, so disable it to prevent it from prematurely restarting mysql) Code: [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[200],"tags":[151,222],"class_list":["post-3081","post","type-post","status-publish","format-standard","hentry","category-mysql-2","tag-mysql","tag-mysqld"],"acf":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/3081","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/comments?post=3081"}],"version-history":[{"count":0,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/3081\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/media?parent=3081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/categories?post=3081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/tags?post=3081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}