Replication in MySQL is a process that allows data from one MySQL database server (the master) to be copied to one or more servers (the slaves). This technique is crucial for ensuring high availability, enhancing performance, and enabling backup solutions. With replication, any changes made to the master database are reflected in the slave databases, allowing for load balancing and fault tolerance.
There are several types of replication in MySQL, including:
-- On the Master server:
-- Step 1: Edit the MySQL configuration file (my.cnf)
[mysqld]
server-id=1
log_bin=mysql-bin
-- Step 2: Create a replication user
CREATE USER 'replicator'@'%' IDENTIFIED BY 'password';
GRANT REPLICATION SLAVE ON *.* TO 'replicator'@'%';
-- Step 3: Obtain the binary log coordinates for the master
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
-- Note down the File and Position
-- Step 4: Unlock the tables
UNLOCK TABLES;
-- On the Slave server:
-- Step 1: Edit the MySQL configuration file (my.cnf)
[mysqld]
server-id=2
-- Step 2: Start replication
CHANGE MASTER TO
MASTER_HOST='master_ip_address',
MASTER_USER='replicator',
MASTER_PASSWORD='password',
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=12345; -- Use the File and Position noted earlier
-- Step 3: Start the slave
START SLAVE;
-- Step 4: Check the slave status
SHOW SLAVE STATUS\G
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?