How to read and write separate database - experimental environment

Experimental environment
two virtual machines
installed mysql mariadb mariadb-server
open service
systemctl start mariadb
configuration of remote access users
mysql -uroot -p into the database (default root password is blank so enter commands directly enter on line)
use MySQL

Development of the port command:

//MYSQL5.7
. * * The GRANT the TO ALL PRIVILEGES the ON 'the root' @ '%' the IDENTIFIED BY '123' the WITH the GRANT the OPTION; (remote login user provided root, IP native IP password 123

//MYSQL8.0 open ip command
mysql> grant all privileges on * * to 'root' @ '%'.;

Primary database settings:
Vim /etc/my.cnf
in [mysqld] Tags added below the following code:
Server-ID. 1 =
log = Master-bin-bin
Restart Service
systemctl restart mariadb.service

mysql -uroot -p into the database
query service status on the primary server's master database
SHOW MASTER STATUS

File appears here and position the log file, which later will be used to

Provided from the database
1. Open vim my.cnf:

vim /etc/my.cnf

2. [mysqld] Tags added below the following code:

server-id = 2 # This id must not the same as the primary database
read-only = on # Set the database is read state
relay-log = relay-bin

Restart service
systemctl restart mariadb.service

Into the database
mysql -uroot -p
execute the following statements,
Change Master to MASTER_HOST = '192.168.0.220', MASTER_USER = 'WL', master_password = '123', MASTER_LOG_FILE = 'Master-bin.000003', MASTER_LOG_POS = 2077;
( master_host: primary database IP
remote user name to connect the primary database provided: MASTER_USER
master_password: remote connection to the primary database password set
master_log_file = 'master-bin.000003': binary log files generated, there is a picture in the display)
MASTER_LOG_POS = 2077: port number binary log files (pictures on display)

Start slave synchronization (in the database)

START SLAVE;

7. Review the status of slave synchronization on the slave server

show slave status\G

 

 

When the content of the picture is YES is a two database synchronization setup is complete
you can use the tool to test mysql
Below is my mysql database links with two of the picture

 

 

其中master是主数据库,slave是从数据库,两个数据库进行数据同步是根据二进制的日志文件进行的,一开始的状态两个数据库必须保持数据库名字相同,和表的名字相同,否则会出现找不到数据库的错误

 

 


出现这个错误的主要原因是因为当时的日志文件只保存了当时的数据库状态,将当下的两个数据库进行了连接,当主数据库新增加一个数据库时,从数据库无法匹配到主数据库,就出现了找不到数据库的错误
解决方法:
1 将主数据库新建的数据库删除,在原有的数据库上进行增删操作,再重新执行上面的操作
2 在从数据库中增加与主数据库相同的数据库,再重新执行上面的操作

Guess you like

Origin www.cnblogs.com/ningwuyu/p/12091949.html