mysql Advanced Usage (1) - Main mariadb Introduction 1 (installed) centos7 yum install mysql from building Mariadb | mariaDb

Mariadb description:

  mariadb is a branch of mysql, the need for further understanding of reference: https://mariadb.org/

  Installation Tutorial: window Installation: MariaDB Introduction 1 (installed)

         linux Installation: centos7 yum install mysql | mariaDb

       Added: mysql from the master copy (master-slave), I will take mariadb to demonstrate

Mariadb master-slave replication:

  1> Rationale:

    

    The basic data replication between MySQL binary log file (binary log file). A MySQL database Once the binary logging is enabled, as a master, its database all the operations are to "events" recorded in the binary log, other databases as slave O threads with the primary server to maintain communication through an I /, and changes in the binary log file monitoring master, and if we find master binary log file is changed, it will copy the changes to their relay log in, then a slave SQL thread will related to "events" to perform its own database , in order to achieve the consistency of the database and primary database, we realized the master-slave replication.

  2> achieve master MySQL from the desired configuration:

    1> to prepare two servers  

      master    192.168.248,147   /linux  (centos7)

      slave       192.168.248.148  /linux  (centos7)

      

After installation centos7 mariadb, no default password 

. 1 > -uroot-mysql - P carriage
 2 > use mysql; switch to mysql database
 . 3 > Update User SET password = password ( " custom password " ) WHERE User = ' the root ' ; 
 . 4 > flush privileges; refresh the effect

    2> configure the master server (server 147)

1 > modify the configuration file: 
[mysqld] 
log -bin = MySQL- bin binary log # Open 
Server -id = 1 # Server- Set ID
2> 重启mysql,创建用于同步的用户账号
mysql> CREATE USER 'huhy'@'192.168.248.147' IDENTIFIED BY 'huhy';#创建用户
mysql> GRANT REPLICATION SLAVE ON *.* TO 'huhy'@'192.168.248.147';#分配权限
mysql>flush privileges;   #刷新权限
3> 查看master状态,记录二进制文件名(mysql-bin.000001)和位置(569):
SHOW MASTER STATUS;

   3>从服务器slave修改:

    

从服务器配置:
1>my.cnf配置文件,添加server-id
[mysqld]
server-id=2 #设置server-id,必须唯一
2>重启mysql,打开mysql会话,执行同步SQL语句(需要主服务器主机名,登陆凭据,二进制文件的名称和位置):

CHANGE MASTER TO MASTER_HOST='192.168.248.147',MASTER_USER='huhy',MASTER_PASSWORD='huhy', MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=569;
3> 启动同步进程:
  start slave; 【stop slave】
4> 查看slave状态: 
    show slave status\G;

注意:这个当其中两个都是yes的时候代码同步开启成功。  

  问题:这个可能会出现个问题, Slave_IO_Running: Connecting  连接问题: 如下:
    

  产生这个问题的原因是我们创建的同步用户无法进行远程连接,从服务器无法连接到主服务器:

  grant all privileges on *.* to huhy@'%'identified by 'huhy';   授权后即可   

  flush privileges;  刷新权限

 执行后即可完成同步 

补充:可以再my.cnf中设置同步哪些数据库:

# 不同步哪些数据库  
binlog-ignore-db = mysql  

  
# 只同步哪些数据库,除此之外,其他不同步  
binlog-do-db = test  

测试:

  

 

   


到这mysql的主从复制已经搞好了,有不理解的可以一起讨论

 

Guess you like

Origin www.cnblogs.com/huhongy/p/11206724.html