Detailed Explanation of MySQL Enabling SSD Storage Instance

  • 2021-09-16 08:25:56
  • OfStack

MySQL Enable SSD Storage Example Explanation

Sometimes the slow reading and writing of OS can degrade the performance of the MySQL server, especially when OS and MySQL use the same disk. Therefore, it is best to use a separate disk for MySQL, and it is better to use SSD. To do this, you need to mount the new SSD disk on the server, assuming that the new disk is/dev/sdb.

1. Prepare a new disk:


# fdisk /dev/sdb

Press "n" to create a new partition; Press "p" to create a new primary partition. Then set the partition number (from 1 to 4), then select the size of the partition and press Enter.

If you don't want to use the whole disk as a partition, you need to continue to create a new partition.

Press "w" to make the write change.

2. Create a file system in the new partition


# mkfs.ext4 /dev/sdb1

3. Map the new partition to a directory, which I named "ssd", under the root directory of root.


# mkdir /ssd/
# mount /dev/sdb1 /ssd/

4. Make this mapping take effect when the server starts

Modify Configuration File/etc/fstab


/dev/sdb1 /ssd ext4 defaults 0 0

5. Move MySQL to a new disk

Stop the MySQL service first


# service mysqld stop

If there is a service writing MySQL in the system, it will also stop, such as


# service httpd stop
# service nginx stop

Copy the entire MySQL directory to a new disk


# cp /var/lib/mysql /ssd/ -Rp

Rename the directory of MySQL when replication is complete


# mv /var/lib/mysql /var/lib/mysql-backup

Then create symbolic links


# ln -s /ssd/mysql /var/lib/mysql

You can now start the MySQL service


# service mysqld start
# service httpd start
# service nginx start

If you have any questions, please leave a message or go to this site community to exchange and discuss, thank you for reading, hope to help everyone, thank you for your support to this site!


Related articles: