{"id":2276,"date":"2018-05-05T13:42:23","date_gmt":"2018-05-05T08:12:23","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=2276"},"modified":"2026-09-30T08:56:44","modified_gmt":"2026-09-30T03:26:44","slug":"change-mysql-data-directory-on-cpanel-safely-move-mysql-data-directory-centos","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/change-mysql-data-directory-on-cpanel-safely-move-mysql-data-directory-centos\/","title":{"rendered":"How to Safely Move the MySQL Data Directory on cPanel\/CentOS"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Post Date<\/strong>: May 5, 2018<br><strong>Last Updated<\/strong>: September 19, 2026<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By default, MySQL stores its database files under <code>\/var\/lib\/mysql<\/code>. When the existing MySQL data directory requires additional storage, better disk allocation, or a dedicated filesystem, it may be necessary to move the MySQL data directory to another location.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This article explains how to safely move the MySQL data directory from <code>\/var\/lib\/mysql<\/code> to <code>\/home\/mysql<\/code> on a cPanel\/CentOS server. The procedure includes copying the existing database files, stopping MySQL, performing a final synchronization, updating the MySQL configuration, and restarting the service.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before moving the MySQL data directory, ensure the following requirements are met:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Root or sudo access<\/strong> to the server.<\/li>\n\n\n\n<li><strong>Sufficient disk space<\/strong> is available in <code>\/home<\/code> to store the complete MySQL data directory.<\/li>\n\n\n\n<li><strong>A valid backup<\/strong> of the MySQL databases is available before making any changes.<\/li>\n\n\n\n<li>Verify the current MySQL data directory, normally <code>\/var\/lib\/mysql<\/code>.<\/li>\n\n\n\n<li>Schedule a <strong>maintenance window<\/strong>, as MySQL must be stopped during the final synchronization and configuration change.<\/li>\n\n\n\n<li>Ensure no critical applications or websites are actively writing to the databases during the migration.<\/li>\n<\/ol>\n\n\n<h2>Implementation<\/h2>\n<p>This post explains how to move or set up a different data directory for the MySQL application. If no database exists, skip the first step. This post deals with moving the data directory to \/home\/mysql<\/p>\n<p>Create an existing data directory in a tar file. The default data directory for MySQL is <em>\/var\/lib\/mysql<\/em><\/p>\n<p><code>tar -cvf mysql.tar \/var\/lib\/mysql<\/code><\/p>\n<p>Create the directory \/home\/mysql<\/p>\n<p><code>mkdir -p \/home\/mysql<\/code><\/p>\n<p>Now, rsync the data directory from \/var\/lib\/mysql to \/home\/mysql. If the data directory is huge, then we recommend running the rsync process in screen<\/p>\n<p><code>screen -S rsync<\/code><\/p>\n<p><code>rsync -avp \/var\/lib\/mysql\/ \/home\/mysql<\/code><\/p>\n<p>Press\u00a0<strong>Ctrl + A +\u00a0 D\u00a0<\/strong>to come out of screen<\/p>\n<p>Depending on the size of the directory, it may take a little while.\u00a0 Now, open the screen and view the progress state.<\/p>\n<p><code>screen -ls<\/code><\/p>\n<p><code>screen -x screenID<\/code><\/p>\n<p>Now, stop the MySQL service.<\/p>\n<p><code>\/etc\/init.d\/mysql stop<\/code><\/p>\n<p>Initiate the rsync process again to copy the data directory.<\/p>\n<p><code>rsync -avp --delete \/var\/lib\/mysql\/ \/home\/mysql\/<\/code><\/p>\n<p>Change the permissions of the new data directory with mysql<\/p>\n<p><code>chown -R mysql.mysql \/home\/mysql<\/code><\/p>\n<p>Edit the mysql configuration with new data directory(\/etc\/my.cnf)<\/p>\n<p><code>vi \/etc\/my.cnf<\/p>\n<p><\/code>datadirectory=\/home\/mysql<\/p>\n<p>Now, start the MySQL service.<\/p>\n<p><code>\/etc\/init.d\/mysql start<\/code><\/p>\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Moving the MySQL data directory to <code>\/home\/mysql<\/code> can help when additional storage or a dedicated filesystem is required. The migration should be performed carefully by first copying the existing data, stopping MySQL, running a final <code>rsync<\/code> synchronization, correcting ownership, updating the MySQL configuration, and then starting the service.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After the migration, verify that MySQL starts successfully and that the databases are accessible from the cPanel accounts and applications. Keep the original <code>\/var\/lib\/mysql<\/code> data intact until the new data directory has been fully verified and confirmed to be working correctly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. What is the default MySQL data directory?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The default MySQL data directory is usually:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>\/var\/lib\/mysql<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Why would I move the MySQL data directory?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The data directory may be moved when additional storage is required, a separate filesystem is available, or better disk-space management is needed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Can I move the MySQL data directory while MySQL is running?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">It is recommended to stop the MySQL service before performing the final synchronization and changing the data directory configuration. This helps ensure that all database files are copied consistently.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/configure-dream-weaver-in-to-access-mysql-database-via-ftp-cpanel-access-database-via-remote-connection\/\">Configure Dreamweaver to access MySQL database via FTP \u2013 cPanel \u2013 Access database via remote connection<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Talk to our experts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Looking for the right technology solution for your business?. Our experts can help with&nbsp;web hosting, domain registration, DevOps and cloud, software development, web applications, mobile applications, and enterprise solutions. Get in touch with our team&nbsp;<a href=\"https:\/\/pheonixsolutions.com\/contact\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Post Date: May 5, 2018Last Updated: September 19, 2026 Introduction By default, MySQL stores its database files under \/var\/lib\/mysql. When [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_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":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1019],"tags":[263,261,179],"class_list":["post-2276","post","type-post","status-publish","format-standard","hentry","category-cloud-aws","tag-cpanel","tag-linux","tag-mysql-2","psol-cat-cloud-aws"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-AI","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=2276"}],"version-history":[{"count":2,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2276\/revisions"}],"predecessor-version":[{"id":12024,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2276\/revisions\/12024"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=2276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=2276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=2276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}