MariaDB download and install (same as primary and secondary nodes)

Delete old database (MySQL)

Yum -y install mariadb Mariadb server

Create a data store path

cd /opt && mkdir mysql

Migrate the data store path to /opt

cp -r /var/lib/mysql/* /opt/mysql/

Modifying a Configuration File

vim /etc/my.cnf.d/mariadb-server.cnf

{{image.png}}

Red is the key configuration

Authorizing mysql users

chown -R mysql:mysql /opt/mysql/

Start the mariadb

systemctl start mariadb

Add automatic startup

systemctl enable mariadb

UPDATE mysql.user SET password = password (‘maysqlpassword’) WHERE user = ‘root’;

FLUSH PRIVILEGES;

Add automatic startup

systemctl enable mariadb

MariaDB primary and secondary nodes are set up

Configuration file of the active node (The service needs to be restarted after configuration)

# # These groups are read by MariaDB server. # Use it for options that only the server (but not clients) should see # # See the examples of server my.cnf files in /usr/share/mysql/ # # this is read by the standalone daemon and embedded servers [server] # this is only for the mysqld standalone daemon # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mysqld/mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld] datadir=/opt/mysql socket=/opt/mysql/mysql.sock log-error=/var/log/mariadb/mariadb.log # These groups are read by MariaDB server. # Use it for options that only the server (but not clients) should see # # See the examples of server my.cnf files in /usr/share/mysql/ # # this is read by  the standalone daemon and embedded servers [server] # this is only for the mysqld standalone daemon # Settings user and  group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mysqld/mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld] datadir=/opt/mysql socket=/opt/mysql/mysql.sock Log - error = / var/log/mariadb/mariadb. The log pid - file = / var/run/mariadb/mariadb. The pid only id # service with best IP network is consistent with the last server - id = 186 # Log-bin =/opt/mysql/maste-log # Sync_binlog = 1 # SQL statements executed by replication SQL thread read relay log are recorded to bin-log log-slave-updates=true [client] port=3306 socket=/opt/mysql/mysql.sockCopy the code

Log in to MySQL to configure user synchronization and view information about the primary node

CREATE USER 'slave'@'%' IDENTIFIED BY 'maysqlpassword';

*** This permission is important REPLICATION ***

GRANT REPLICATION SLAVE ON . TO 'slave'@'%';

Refresh the permissions

flush privileges;

Reset primary key information

reset master;

View the master node information (view the best lock table after completion, data changes will cause state changes)

show master status \G;

{{image.png}}

The red box information needs to be remembered for the slave library configuration

Secondary node configuration file (Service needs to be restarted after configuration)

# # These groups are read by MariaDB server. # Use it for options that only the server (but not clients) should see # # See the examples of server my.cnf files in /usr/share/mysql/ # # this is read by the standalone daemon and embedded servers [server] # this is only for the mysqld standalone daemon # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mysqld/mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld] datadir=/opt/mysql socket=/opt/mysql/mysql.sock Log - error = / var/log/mariadb/mariadb. The log pid - file = / var/run/mariadb/mariadb. The pid server - id = 187 # open binary log - bin = mysql - bin log-slave-updates=true [client] port=3306 socket=/opt/mysql/mysql.sock # # * Galera-related settings # [galera] # Mandatory settings #wsrep_on=ON #wsrep_provider= #wsrep_cluster_address= #binlog_format=row #default_storage_engine=InnoDB #innodb_autoinc_lock_mode=2 # # Allow server to accept connections on all interfaces. # #bind-address=0.0.0.0 # # Optional setting #wsrep_slave_threads=1 #innodb_flush_log_at_trx_commit=0 # embedded server [embedded]Copy the code

Log on to the MySQL

Stop the slave node

stop slave;

Resetting slave node

reset slave all;

Example Set the secondary node information

CHANGE MASTER TO MASTER_HOST='***.40.64.***', MASTER_USER='slave', MASTER_PASSWORD='maysqlpassword', -- MASTER_LOG_FILE='maste-log.000002' -- master file MASTER_LOG_POS=313; -- Master is set to MASTER_LOG_POSCopy the code

View information about secondary nodes

``` show slave status \G; ` ` `Copy the code

Enable the secondary node service

start slave;

Check the slave node information again,

#### If yes, the configuration is successful. Slave_IO_Running: yes Slave_SQL_Running: yesCopy the code