{"id":174,"date":"2011-11-04T04:25:00","date_gmt":"2011-11-04T04:25:00","guid":{"rendered":"http:\/\/pheonixsolutions.com\/?p=174"},"modified":"2026-04-29T22:27:40","modified_gmt":"2026-04-29T16:57:40","slug":"change-mysql-data-directory","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/change-mysql-data-directory\/","title":{"rendered":"How to Change Mysql data directory"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MySQL stores all database data, tables, indexes, and logs in a default directory known as the <em>data directory<\/em> (commonly <code>\/var\/lib\/mysql<\/code> on Linux systems). In many real-world scenarios, administrators need to change this default location\u2014for example, when the system disk is running out of space, for performance optimization, or when separating data storage from system files for better manageability and backups.<br>Changing the MySQL data directory allows better control over storage resources while ensuring scalability and system efficiency.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before changing the MySQL data directory, ensure the following requirements are met:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Root or sudo access<\/strong> to the server. <\/li>\n\n\n\n<li><strong>MySQL\/MariaDB installed and running<\/strong> properly. <\/li>\n\n\n\n<li><strong>Sufficient disk space<\/strong> available in the new target directory. <\/li>\n\n\n\n<li><strong>Proper backup<\/strong> of all existing databases (very important to avoid data loss). <\/li>\n\n\n\n<li>MySQL service should be <strong>stopped during migration<\/strong> to prevent data corruption.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">IMPLEMENTATION<\/h2>\n\n\n<p>We can change mysql data directory by doing the following steps.<\/p>\n<p>+ Stop the mysql service.<\/p>\n<p>#<span style=\"font-weight: bold;\">\/etc\/init.d\/mysql stop<\/span><\/p>\n<p>+ Create a directory in \/home directory (Normally \/home contains large disk space)<\/p>\n<p># <span style=\"font-weight: bold;\">mkdir \/home\/var_mysql<\/span><\/p>\n<p>+ Move the mysql data directory to new location i.e., \/home\/var_mysql<\/p>\n<p># <span style=\"font-weight: bold;\">mv \/var\/lib\/mysql \/home\/var_mysql<\/span><\/p>\n<p>+ Change the permission of this directory to &#8220;mysql&#8221;.<\/p>\n<p># <span style=\"font-weight: bold;\">chown -R mysql:mysql \/home\/var_mysql\/mysql<\/span><\/p>\n<p>+ Create a symlink to \/var\/lib\/mysql.<\/p>\n<p># <span style=\"font-weight: bold;\">ln -s \/home\/var_mysql\/mysql \/var\/lib\/mysql<\/span><\/p>\n<p>+ Start mysql service.<\/p>\n<p># <span style=\"font-weight: bold;\">\/etc\/init.d\/mysql start<\/span><\/p>\n<p>+ Check the mysql data directory by using ps command. This will show the mysql data directory.<\/p>\n<p>#<span style=\"font-weight: bold;\"><b> <\/b>ps aux | grep mysql<\/span><\/p>\n<h3 style=\"height: 84px;\"><br \/><br \/>CONCLUSION<\/h3>\n<p>Changing the MySQL data directory is a critical administrative task that helps improve storage management, performance, and scalability of database systems. While the process requires careful planning and downtime, following proper steps such as taking backups, updating configuration files, and setting correct permissions ensures a smooth migration. When done correctly, it enhances system organization and supports better long-term database maintenance.<\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction MySQL stores all database data, tables, indexes, and logs in a default directory known as the data directory (commonly [&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":[1022],"tags":[],"class_list":["post-174","post","type-post","status-publish","format-standard","hentry","category-web-architecture","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-2O","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/174","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=174"}],"version-history":[{"count":2,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/174\/revisions"}],"predecessor-version":[{"id":10076,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/174\/revisions\/10076"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}