Home >Database >Mysql Tutorial >mysql delete from library

mysql delete from library

王林
王林Original
2023-05-11 16:20:07869browse

MySQL is a very commonly used open source relational database system. MySQL is mainly composed of two components: the master database and the slave database. The master library is mainly responsible for writing and updating data, while the slave library is used for data backup and reading. But in actual use, we often need to delete the slave library. So, how to delete the MySQL slave database? This article will introduce in detail the deletion methods suitable for different situations.

  1. Basic concepts

Before we officially start discussing how to delete slave libraries, we need to understand some basic concepts.

1.1 Master database and slave database

The master database is the copy in MySQL that undertakes write operations, while the slave database is a copy that uses the replication function provided by the master database to be backed up on multiple servers.

1.2 Replication

Replication in MySQL refers to creating an identical copy of the master database on the slave database for data backup and reading. Specifically, when modifications are made on the master database, replication will automatically synchronize the modifications to the slave database so that the replica on the slave database remains consistent with the master database.

1.3 Deletion from the library

When we need to stop a slave library, we need to delete the slave library. Deletion operations from the slave database include logging out of the slave database on the master database and deleting the backup on the slave database.

  1. Deletion method from the library

2.1 Delete the slave library on the main library

Sometimes, we need to delete a slave library from the main library. This can be achieved by executing the following command:

mysql> STOP SLAVE;
mysql> DROP SLAVE ‘slave_host_name’;

where slave_host_name is the host name of the slave library. These commands will unregister the slave database from the master database.

2.2 Deleting the backup from the slave library

When we need to delete the backup from the slave library, there are usually two methods.

2.2.1 Use the RESET SLAVE command

Use the RESET SLAVE command to delete the backup on the slave database. Execute the following command:

mysql> STOP SLAVE;
mysql> RESET SLAVE;

This will clear all slave database backups and stop synchronization.

2.2.2 Directly delete files

We can also directly delete the backup files on the slave library. Normally, the backup file of the slave library is located in the host name folder in the data directory of the slave library. Therefore, we can use the following command to delete the backup:

rm -rf /var/lib/mysql/slave_host_name

Where, slave_host_name is the host name of the slave library.

  1. Notes

During deletion from the library, we need to pay attention to the following issues:

3.1 Stop synchronization

In Before deleting the slave database, you must first stop the synchronization between the slave database and the master database.

3.2 Do not delete the main library

In the process of deleting the slave library, you must not delete the data on the main library by mistake.

3.3 Confirm backup

Before deleting the slave database, be sure to confirm that the backup has been successful. If the data backup fails, deleting the slave will cause you to lose all copies of the data.

  1. Conclusion

MySQL Deletion from the database is a basic operation in MySQL database management. This article introduces the deletion method of the slave library at two levels: the master library and the slave library. It also introduces the matters that need to be paid attention to when deleting the slave library. Through the introduction of this article, readers will be able to better understand how to delete slave libraries in MySQL.

The above is the detailed content of mysql delete from library. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn