Get the App
SLTechnology News&Howtos  ›  Database  › 

Migrate the mysql database to another hard drive

Shulou Source: shulou.com Published: 2022-06-01 11:20:26 10月03日 Update

Archliun system mysql database

1. Partition and format the new hard disk

1) # fdisk / dev/sdb

2) # mkfs.ext4 / dev/sdb1

2. Stop the MYSQL service

Systemctl stop mysqld

3. Copy the database file

# cp-Rp data/ mnt/data/

4. Delete the original data file

# rm-rf / data

5. Prohibit booting self-starting MYSQL service

# systemctl disable mysqld

6. Mount the self-booting sdb1 partition to data

# vi / etc/fstab

/ dev/sdb1 / data ext4 rw,relatime,data=ordered 0 2

7. Copy the database file back to the original path

# cp-Rp / mnt/data/* / data/

8. Delete / mnt/data database directory

# rm-rf / mnt/data

9. Set / dara permissions

# chown-R mysql:mysql / data

10. Restore mysql service

# systemctl enable mysqld

# systemctl start mysqld

Tags: Data database file service copy hard disk permission format directory system path Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi vpn OPPO Reno MariaDB Xiaomi