How to configure MySQL on master node

April 8, 2024 / MySQL

This guide explains how to configure MySQL on a master node for replication. By default, MySQL listens on localhost and does not allow remote connections. To enable replication, MySQL must listen on the master server’s public IP and be properly configured.

Step 1: Edit the MySQL Configuration File

On Debian-based systems (Ubuntu, Debian)

nano /etc/mysql/mysql.conf.d/mysqld.cnf

On RHEL-based systems (CentOS, RHEL, AlmaLinux)

nano /etc/my.cnf

Step 2: Update MySQL Bind Address

Find the following line:

bind-address = 127.0.0.1

Replace it with:

bind-address = log_bin = /var/lib/mysql/mysql-bin.log

Step 3: Enable Replication Settings

Ensure the following line is present and uncommented:

server-id = 1

Add the following lines at the end of the configuration file:

log_bin = /var/log/mysql/mysql-bin.loglog_bin_index = /var/log/mysql/mysql-bin.log.indexrelay_log = /var/log/mysql/mysql-relay-binrelay_log_index = /var/log/mysql/mysql-relay-bin.index

Save and close the file.

Step 4: Restart the MySQL Service

Apply the changes by restarting MySQL:

systemctl restart mysql

Step 5: Create a Replication User

Log in to the MySQL shell:

mysql -u root -p

Create a replication user:

CREATE USER 'replica_user'@'%' IDENTIFIED BY 'strong_password';

Grant replication privileges:

GRANT REPLICATION SLAVE ON *.* TO 'replica_user'@'%';
FLUSH PRIVILEGES;

Exit MySQL:

EXIT;

MySQL is now configured on the master node with replication enabled. The server is listening on the public IP, binary logging is active, and a replication user has been created. This setup allows slave nodes to connect securely for replication.

If you need further assistance, please contact our support team.

Spread the love