Skip to main content

The proper way to move MySQL to a second drive

Comments

8 comments

  • cPanelLauren
    Hi @NabiKAZ First, yes those instructions are still valid, @Jeff P. had at one point (just this last October) added the following but it was subsequently removed and the thread was locked for reasons that were unrelated to the validity of his instructions: [QUOTE]This method will make the switch perfectly in seconds. This is for red hat, centos, etc. ___________________________________________________ CONFIRM ALL PATHS PRIOR TO RUNNING!! cpanel MySQL/MariaDB Path: /var/lib/mysql Linux non-cPanel MySQL/MariaDB Path: /var/bin/mysql The path to your harddrive may be different than mine. So, use the command lsblk to list all unmounted drives. It may be any of these, the final letter means which drive it is, "b" would mean drive #2 and "c" would mean drive #3 and so-forth: /dev/xvdb /dev/sdb /dev/hdb So find out which is yours and replace all instances of /dev/xvdb with your path in the blue code below. ___________________________________________________ Now to the actual commands: *Once you run the first line, all database powered sites will stop working. In this process, all permissions, ownership, paths and all that jazz are preserved. mysql.actual will also servce as a backup! Then the actual process, run these commands: service mysql stop; mkdir /var/lib/mysql.actual; rsync -avz /var/lib/mysql/ /var/lib/mysql.actual; /sbin/mkfs.ext4 -L /var/lib/mysql /dev/xvdb; mount /dev/xvdb /var/lib/mysql; rsync -avz /var/lib/mysql.actual/ /var/lib/mysql; service mysql start; then in fstab add this to mount at boot: (DO NOT DO THIS YOURSELF IF YOU DON'T UNDERSTAND fstab!!! YOU MIGHT NOT BOOT BACK ONLINE IF DONE WRONG.) Run command: vi /ect/fstab; then find a blank line and enter the letter s then find a blank line or make one and paste this by right clicking. LABEL=/var/lib/mysql /var/lib/mysql ext4 defaults 1 2 Now just hit :wq to save and exit. Reboot and check everything. Do this during your host's business hours so you can get help in case you set the paths wrong in fstab and be sure to contact your host to verify it FIRST if needed.
    For anything else I need to point out that this is unsupported and when you do this or perform a task like this you do so at your own peril.
    0
  • rasanjanad
    Hi @NabiKAZ First, yes those instructions are still valid, @Jeff P. had at one point (just this last October) added the following but it was subsequently removed and the thread was locked for reasons that were unrelated to the validity of his instructions: For anything else I need to point out that this is unsupported and when you do this or perform a task like this you do so at your own peril.

    How to do it when i use MariaDB? Thanks
    0
  • cPanelLauren
    Same instructions for MariaDB as noted in the example.
    0
  • rasanjanad
    Same instructions for MariaDB as noted in the example.

    Thanks for the reply. After following this steps, All databases in the MariaDB server will move to new hard drive without a problem?
    0
  • rasanjanad
    Same instructions for MariaDB as noted in the example.

    Can you help me?
    0
  • andrew.n
    Whats the problem?
    0
  • rasanjanad
    Whats the problem?

    Thanks for the reply. After following these steps, All databases in the MariaDB server will move to a new hard drive without a problem?
    0
  • andrew.n
    These are the steps yes but please be careful and adjust the steps to your OS and current environment if needed.
    0

Please sign in to leave a comment.