mandag 30. desember 2024

Setup MySQL repliaction from scratch.

 How to setup a replication instance from only a single server.


First backup the database, 

MASTER SERVER:

Edit the MySQL configuration file (/etc/mysql/mysql.conf.d/mysqld.cnf ) to enable binary logging and specify the server as the master.

[mysqld] 
server-id=1 
log_bin=mysql-bin

Run the following command to restart mysql deamon:

sudo systemctl restart mysql

Backup the original database on the master server.

--master-data=2 er important. it includes the binlog information in the backup file. to be used to synchronize the slave to the master.

mysqldump -u root --p --opt --single-transaction --master-data=2 --databases db_to_backup > backup.sql > /dev/null 2>&1 &

slog in to the MySQL server:

mysql -u root -p CREATE USER 'replica_user'@'%' IDENTIFIED BY 'password'; GRANT REPLICATION SLAVE ON *.* TO 'replica_user'@'%'; FLUSH PRIVILEGES;

Run the following command inside mysql command line.

CREATE USER 'replica_user'@'%' IDENTIFIED BY 'password'; GRANT REPLICATION SLAVE ON *.* TO 'replica_user'@'%'; FLUSH PRIVILEGES;


mysql -u root -p CREATE USER 'replica_user'@'%' IDENTIFIED BY 'password'; GRANT REPLICATION SLAVE ON *.* TO 'replica_user'@'%'; FLUSH PRIVILEGES;

d] 

mysqldump -u root --p --opt --single-transaction --master-data=2 --databases db_to_backup > backup.sql > /dev/null 2>&1 &

Then setup the mysql server instance on a new computer or vm and import the data, 

Ingen kommentarer:

Legg inn en kommentar