Get the App
SLTechnology News&Howtos  ›  Database  › 

How to transfer Partition of Database data File

Shulou Source: shulou.com Published: 2022-05-31 13:13:57 09月24日 Update

Database data files how to partition transfer, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Since my colleagues did not plan the disk partition before, we can see that the data and the system are in the same partition, there is no separate data partition for the database, and a partition of 640G is not used. The following is a brief introduction to the transfer process of mysql database data files.

1. Create a new data partition

Space is needed, let's keep it simple.

# fdisk / dev/sdb n-> p-> 1-> Enter- > Enter- > w # create physical volume # pvcreate / dev/sdb1 # create logical volume # vgcreate datavg/ dev/sdb1 # lvcreate-n lv_data-L + 200g datavg # format disk # mkfs.ext4 / dev/datavg/lv_data # mount # vim / etc/fstab / dev/datavg/lv_data / tmsdata ext4 defaults 00 # mount-a

2. Data transfer in mysql database

The previous data files and logs are in the / data directory, and now need to be transferred to the new data directory / tmsdata

(1) stop the database service

Systemctl stop mysqld systemctl status mysqld # write the cache to the data file, do it a few more times, you can't go wrong with sync sync

(2) transfer data files and logs

Cp-rf / data/* / tmsdata/ chmod-R 755 / tmsdata chown-R mysql:mysql / tmsdata/

(3) modify my.cnf configuration

# vim / etc/my.cnf [mysqld] datadir=/tmsdata/datafile log-error=/tmsdata/log/mysqld.log # Note that the binary log should also be changed to log-bin = / tmsdata/log/mysql-bin.log log-bin-index = / tmsdata/log/binlog.index

3. Start the mysql service and verify

If there is a master-slave service, it is best to set the database read-only when stopping the database service, and then enable read and write after opening the slave library.

# vim / etc/my.cnf [mysqld] datadir=/tmsdata/datafile log-error=/tmsdata/log/mysqld.log # Note that the binary log should also be changed to log-bin = / tmsdata/log/mysql-bin.log log-bin-index = / tmsdata/log/binlog.index

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Data databases files logs services binaries directories disks help planning clarity master and slave content colleagues this articles novices is in more best Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MariaDB vpn Microsoft macOS