Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2010
    Location
    Clearwater, FL
    Posts
    41

    How to symlink /var/lib/mysql if /var mount becomes full

    Most of you may already know how to do this, so forgive if this is too simple, but this may be helpful for some dedicated server owners whose /var mount (some hosts use separate partitions for /usr, /var, /home etc) has become full, which is usually do to large databases in /var/lib/mysql. There is usually plenty of room in /the /home partition. This will work on cPanel servers as well.

    This simple tutorial lays out the steps involved to copy contents of /var/lib/mysql to /home and then symlink /var/lib/mysql to /home/mysql. Of course adjust accordingly if moving/symlinking to a different mount or directory.

    1) Go to webpage that uses mysql to verify working pre-copy

    2) Stop mysql service (I will usually also stop cpanel & http service just to be safe).

    /etc/init.d/mysql stop
    /etc/init.d/httpd stop
    /etc/init.d/cpanel stop

    3) Do the copy:

    rsync -av /var/lib/mysql /home/

    4) Verify copied folder same size as source with du:

    du -sh /var/lib/mysql
    du -sh /home/mysql

    5) Move /var/lib/mysql to /home/mysql-bak (essentially removing /var/lib/mysql because the folder must not exist when symlink is created)

    mkdir /home/mysql-bak
    mv /var/lib/mysql /home/mysql-bak/

    6) Create symlink:

    ln -s /home/mysql /var/lib/mysql

    7) Verify the symlink is correct when listing the contents of new symlinked /var/lib/mysql (you can refer to the rsync copy to make sure the paths are the same - they should be)

    8) Restart mysql, httpd, cpanel

    9) Verify mysql-reliant webpage is loading without issue

    10) You should now have freed up space on /var. Verify with 'df -h'
    Sago Networks-Internet Solutions Company
    Servers|Colocation|VPS|Backup|Managed Services
    See Our VPS DEALS Toll free 866-366-3640

  2. #2
    Join Date
    Sep 2011
    Location
    UK
    Posts
    166
    Thank you. I guess you should place any future tutorials in tutorials section (e.g. Dedicated Server Tutorials).

  3. #3
    +1

    Thanks for sharing.
    HostXNow - Shared Web Hosting | Semi Dedicated Hosting | Enterprise Reseller Hosting | VPS Hosting

  4. #4
    Join Date
    Oct 2002
    Location
    Vancouver, B.C.
    Posts
    2,699
    Quote Originally Posted by SagoJonB View Post
    2) Stop mysql service (I will usually also stop cpanel & http service just to be safe).

    /etc/init.d/mysql stop
    /etc/init.d/httpd stop
    /etc/init.d/cpanel stop
    Stopping httpd and cpanel aren't necessary; so long as mysql is stopped, there wouldn't be any open writes happening.

    Quote Originally Posted by SagoJonB View Post
    3) Do the copy:

    rsync -av /var/lib/mysql /home/
    Using cp -a will probably be quicker. No point in doing a comparison of files when you know they won't exist in the new location.
    ASTUTE INTERNET: Advanced, customized, and scalable solutions with AS54527 Premium Performance and Canadian Optimized Network (Level3, Shaw, CogecoPeer1, GTT/Tinet),
    AS63213 Cost Effective High Performance Network (Cogent, HE, GTT/Tinet)
    Dedicated Hosting, Colo, Bandwidth, and Fiber out of Vancouver, Seattle, LA, Toronto, NYC, and Miami

  5. #5
    Join Date
    Jun 2010
    Location
    Clearwater, FL
    Posts
    41
    The reason I use rsync instead of cp is mostly to get the readout of what was copied for logging purposes.
    Sago Networks-Internet Solutions Company
    Servers|Colocation|VPS|Backup|Managed Services
    See Our VPS DEALS Toll free 866-366-3640

Similar Threads

  1. Symlink: /var/lib/mysql -> /home/mysql... Is that OK?
    By oaziz in forum Hosting Security and Technology
    Replies: 3
    Last Post: 09-02-2011, 03:32 PM
  2. symlink /var/lib/mysql to /home/mysqlvartmp ?
    By sharmaine1111 in forum Hosting Security and Technology
    Replies: 17
    Last Post: 11-24-2009, 12:25 PM
  3. ERROR: The partition with /var/lib/mysql is too full!
    By jjk2 in forum Programming Discussion
    Replies: 6
    Last Post: 06-19-2009, 03:07 AM
  4. What in /var/lib/mysql/
    By dunhill in forum Hosting Security and Technology
    Replies: 11
    Last Post: 12-11-2008, 06:30 AM
  5. What are these files in /var/lib/mysql ?
    By suhailc in forum Hosting Security and Technology
    Replies: 5
    Last Post: 09-12-2005, 01:36 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •