MariaDB master-slave replication virtual machine actual combat

MariaDB profile:

  MariaDB MySQL database management system is a branch, mainly by the open source community in the maintenance, the purpose of using GPL licensed MariaDB is fully compatible with MySQL, including API and command line, so that it can easily become a substitute for MySQL. In terms of storage engine, use XtraDB (English: XtraDB) instead of MySQL's InnoDB. MariaDB by the MySQL founder Michael Widenius: leading development (English Michael Widenius), he gave $ 1 billion price earlier, the company he started MySQL AB sold SUN, thereafter, with the SUN acquired by Oracle, MySQL ownership also fall into the hands of Oracle. MariaDB Michael Widenius name from the daughter of Maria's name.

  MariaDB based transaction Maria's storage engine , replacing MySQL 's MyISAM storage engine, it uses the XtraDB Percona, InnoDB variant, a branch of developers want to provide MySQL 5.4 InnoDB performance of the upcoming visit. This version also includes PrimeBase XT (PBXT) and FederatedX storage engine .

 

Installation refer to the following links:

https://www.cnblogs.com/zhanzhan/p/7729981.html

Virtual IP information:

Main library (write library): 192.168.147.200

From the library (Reading Library): 192.168.147.201

I'm using here is a master-slave mode. Two virtual after all mariadb installed on the machine can be master-slave replication.

Main Library:

  After logging mariadb create a test database and create a user table, then insert a few data, the command is as follows:

>mysql -uroot -p 

Enter password:

>create database test;

>show databases;

>use test;

>create table user(id int(11),name varchar(255));

>show tables;

>insert into user values(1,"xiaoming");

>insert into user values(2,"xiaowang");

>select * from user;

 

 Exit mariadb console, using the following command in a shell of the data in the primary database repository database exported and imported from:

>mysqldump -uroot -p --opt --all-databases >/mydata.sql

Enter password:

>scp -r /mydata.sql [email protected]:/ 

[email protected]'s password:

Enter the main library to copy the success of the old data from the database server password.

From the library:

mysql -u root -p  </mydata.sql

Enter password: 

Enter the import password from the library mariadb success (you can see into the database).

 Main Library:

> We /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
server_id=1#主机的标识
log-bin=mysql-bin#确保可写入的日志文件
binlog_format=mixed#二进制日志的格式,
binlog-do-db=test#允许主从复制数据库
binlog-ignore-db=mysql#不允许主从复制的数据库

切记是在[mysqld]下配置要复制的数据库和binlog相关信息,保存退出后进行从库授权

>grant replication slave on *.* to slave@'192.168.147.201' identified by '123456';

重启主库mariadb:

>systemctl restart mariadb;

从库:

>vi /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
server_id=2#从机的标识
log-bin=mysql-bin#确保可写入的日志文件
binlog_format=mixed#二进制日志的格式,
replicate_wild_do_table=test.%#要同步的数据库
replicate_wild_ignore_table=mysql.%#不允许主从复制的数据库

切记是在[mysqld]下进行binlog和要复制的数据库配置,保存后退出。

重启从库mariadb:

> systemctl restart mariadb;

主库:

>mysql -uroot -p

Enter password: 

> show master status;

 上面的信息将在从库中用到。

从库:

 >mysql -uroot -p

Enter password:

>change master to master_host='192.168.147.200',master_user='slave',master_password='123456',master_log_file='mysql-bin.000002',master_log_pos=245;

>start slave;

>show slave status\G

若看到2个红色箭头都是yes,则主从同步成功。

接下来我们进行主从复制测试。

主库:

>mysql -uroot -p 

Enter password: 

>use test;

>select * from user;

>insert into user values(3,"zhangsan");

>select * from user;

我们来到从库看看:

从库:

可见主从复制成功。

如果此时关闭主库服务器,在从库上使用show slave status\G,将提示:

Last_IO_Error: error reconnecting to master '[email protected]:3306' - retry-time: 60  retries: 86400  message: Can't connect to MySQL server on '192.168.147.200' (111)

参考:

https://baike.baidu.com/item/mariaDB/6466119?fr=aladdin

https://blog.csdn.net/qq_41772936/article/details/80380950

Guess you like

Origin www.cnblogs.com/stm32stm32/p/11246912.html