How to migrate mysql storage location to a new disk

How to migrate mysql storage location to a new disk

1. Prepare a new disk and format it with the same file system as the current root partition, create a directory and mount the disk

]#fdisk -l # View disk information ]#fdisk /dev/sdb # Partition ]# df -T # You can view the file system type of the root partition ]#mkfs.xfs /dev/sdb1 # Format the new disk partition ]#mkdir /data
]#mount /dev/sdb1 /data #Mount the disk or write to the /etc/fatab file, add a line: /dev/sdb1 /data xfs defaults 0 0 Automatically mount at boot]#df -h //Confirm the mount result

2. Stop the database service and modify the configuration file

]#systemctl stop mysqld
]#vim /etc/my.cnf

   datadir=/data/mysql
   socket=/data/mysql/mysql.sock
   log-error=/data/log/mysqld.log 
   log_bin=/data/mysql/bin-log
   log-bin-index=/data/mysql/bin-log.index
  [client]
   socket=/data/mysql/mysql.sock #The mysql client sock reads /var/lib/mysql/mysql.sock by default, so you need to add the client sock configuration in the configuration file.
  ]#vim /data/mysql/bin-log.index

Modify the binlog index file and re-specify the binlog storage path.

3. Create the corresponding directory and change the permissions. Migrate the database directory.

]#chown -R mysql:mysql /data
]#mkdir /data/log
]#mv /usr/lib/mysql /data/

4. Start the service and view the change results.

]#systemctl start mysqld
Enter the database mysql >show variables like 'datadir';
#You can see the storage location of the database and check whether the data is correct.
mysql>show variables like '%sock%';
#Check the location of the sock file, or check whether the data in the corresponding directory /data/ is correct.

The firewall is turned off and selinux is in Disabled state.

Summarize

The above is what I introduced to you on how to migrate the MySQL storage location to a new disk. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Implementation of mysql8.0.11 data directory migration
  • How to migrate the data directory in mysql8.0.20
  • Analysis of the principle of MySQL large table extraction mode from the perspective of cloud data migration service
  • How to migrate local mysql to server database
  • Things to note when migrating MySQL to 8.0 (summary)
  • Detailed explanation of MySQL event modification events (ALTER EVENT), disabling events (DISABLE), enabling events (ENABLE), event renaming and database event migration operations
  • 5 ways to migrate from MySQL to ClickHouse
  • Detailed explanation of how to migrate a MySQL database to another machine
  • MySQL database migration quickly exports and imports large amounts of data
  • MySQL online log library migration example

<<:  Detailed tutorial on running selenium+chromedriver on the server

>>:  JavaScript canvas realizes dynamic point and line effect

Recommend

Problems encountered in using MySQL

Here are some problems encountered in the use of ...

Introduction to Semantic HTML Tags

In the past few years, DIV+CSS was very popular in...

Detailed explanation of JavaScript Proxy object

Table of contents 1. What is Proxy? 2. How to use...

How to install babel using npm in vscode

Preface The previous article introduced the insta...

Navicat imports csv data into mysql

This article shares with you how to use Navicat t...

Don’t bother with JavaScript if you can do it with CSS

Preface Any application that can be written in Ja...

A brief discussion on how to use slots in Vue

How to define and use: Use the slot tag definitio...

CSS3 animation to achieve the effect of streamer button

In the process of learning CSS3, I found that man...

How to check whether a port is occupied in LINUX

I have never been able to figure out whether the ...

Install OpenSSL on Windows and use OpenSSL to generate public and private keys

1. OpenSSL official website Official download add...

Solve the error of installing VMware Tools on Ubuntu 18.04

1. According to the online tutorial, the installa...

Docker-compose creates a bridge, adds a subnet, and deletes a network card

1. Create a docker network card [root@i ~]# brctl...

How to manually upgrade the node version under CentOs

1. Find the corresponding nodejs package, refer t...

Detailed tutorial on how to monitor Nginx/Tomcat/MySQL using Zabbix

Table of contents Zabbix monitors Nginx Zabbix mo...