Site Fuse! programming, design, hosting, promotion and advertising tips for webmasters

Running MySQL from another partition (moving data dir)

Home  \  Forums  \  Programming & Development Forums  \  MySQL & Databases Forums  \  Running MySQL from another partition (moving data dir)
Share   

user photo

MrPhear   1 years, 6 months ago

Here're the steps to move your MySQL data dir to another partition or HDD.

Stop MySQL

Create MySQL and database directories;

mkdir /2ndpartition/mysql
mkdir /2ndpartition/mysql/dbname


Copy table files from your original database dir to the partition you're going to use;

cp -a /var/lib/mysql/dbname /2ndpartition/mysql/dbname


(verify data moved by checking home directory contents - VERY IMPORTANT)

Make backup directory just in case;
mv /var/lib/mysql/dbname /var/lib/mysql/dbname.bak


ln -s /2ndpartition/mysql/dbname /var/lib/mysql/dbname


change owner or /2ndpartition/mysql/dbname to mysql

Restart MySQL

Should work fine. I've done it a bunch of times without problem, and var partition should be cleared up.
user photo
Guest