Setting up MySQL replication is a powerful feature that enables you to create copies of your database instances for tasks such as load balancing and backup. Below, I will provide a detailed explanation of how to set up replication between a master and a slave instance of MySQL.
[mysqld]
server-id = 1
log_bin = mysql-bin
binlog_do_db = your_database_name
CREATE USER 'replication_user'@'%' IDENTIFIED WITH mysql_native_password BY 'your_password';
GRANT REPLICATION SLAVE ON *.* TO 'replication_user'@'%';
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
[mysqld]
server-id = 2
CHANGE MASTER TO
MASTER_HOST='master_ip',
MASTER_USER='replication_user',
MASTER_PASSWORD='your_password',
MASTER_LOG_FILE='mysql-bin.000001', -- Replace with the file from SHOW MASTER STATUS
MASTER_LOG_POS=123; -- Replace with the position from SHOW MASTER STATUS
START SLAVE;
Once completed, you can check the slave status using the command:
SHOW SLAVE STATUS\G;
This will show you if the slave is connected and actively replicating from the master.
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?