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

Detailed explanation of the general steps for SQL statement optimization

Preface This article mainly shares with you the g...

How to create a test database with tens of millions of test data in MySQL

Sometimes you need to create some test data, base...

Detailed explanation of VUE's data proxy and events

Table of contents Review of Object.defineProperty...

Simple example of adding and removing HTML nodes

<br />Simple example of adding and removing ...

Vue implements the method example of tab routing switching component

Preface This article introduces the use of vue-ro...

Detailed explanation of JavaScript BOM composition and common events

Table of contents 1. BOM 2. Composition of BOM 2....

Public free STUN servers

Public free STUN servers When the SIP terminal us...

WeChat Mini Program implements the likes service

This article shares the specific code for the WeC...

Install nodejs and yarn and configure Taobao source process record

Table of contents 1. Download nodejs 2. Double-cl...

HTML5+CSS3 coding standards

The Golden Rule No matter how many people are wor...

Linux five-step build kernel tree

Table of contents 0. The kernel tree that comes w...

How to recover accidentally deleted messages files in Linux

If there are files that are being used by a proce...

Implementation example of scan code payment in vue project (with demo)

Table of contents Demand background Thought Analy...