MySql主从复制配置示例_MySQL
最近研究mysql,从oracle官网下了一个最新的5.6的mysql,压缩版的。今天尝试一下Mysql的复制功能,花了好久才整出来,把心得分享出来。
用的是我们开发用的库,部署在测试环境,测试环境的mysql版本居然是5.1的。
1.主服务器配置
cd /etc,找到my.cnf,然后再这个配置文件加上复制要用的配置
server-id = 1 log-bin=mysql-bin binlog-do-db=wx
主服务器需要一个独一无二的server id,log-bin表示启用二进制日志,binlog-do-db表示选择记录日志的数据库
2.从机配置
打开my.ini,加上和服务器类似的配置
server-id=2 log-bin=mysql-bin replicate-do-db=wx
3.将主机上的wx数据库拷给从机。这步一定要执行,不然后面一定会报错。我就是忽略了这一步,导致试了好几次都没有成功!当然,这一步可以用任何方法做,用工具,用mysqldump后从机执行都可以。
4.主机上建复制账号
主机的mysql命令行下执行如下命令,建一个用来复制的账号,和密码
grant replication slave on *.* to 'replication'@'%' identified by '123';
然后查主机的状态
mysql> show master status\G *************************** 1. row *************************** File: mysql-bin.000003 Position: 256 Binlog_Do_DB: wx Binlog_Ignore_DB: 1 row in set (0.00 sec)
Position和File都是后面有用的
5.从机关联主机操作
从机上执行关联主机的命令,并重启从机。
change master to master_host = '192.168.146.120', master_user = 'replication', master_password = '123', master_log_file = 'mysql-bin.000003', master_log_pos = 256; start slave;
6.验证操作
主机上wx库找张表,插入一条语句,从机立刻复制过来。
查看从机状态。
mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.146.120 Master_User: replication Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000003 Read_Master_Log_Pos: 708 Relay_Log_File: CDYJY-LVSHENG1-relay-bin.000004 Relay_Log_Pos: 265 Relay_Master_Log_File: mysql-bin.000003 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: wx Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 708 Relay_Log_Space: 588 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 Master_UUID: Master_Info_File: D:\DevelopTools\DB\mysql-5.6.26-winx64\data\master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 1 row in set (0.00 sec)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Introduction to Python functions: Introduction and examples of exec function Introduction: In Python, exec is a built-in function that is used to execute Python code stored in a string or file. The exec function provides a way to dynamically execute code, allowing the program to generate, modify, and execute code as needed during runtime. This article will introduce how to use the exec function and give some practical code examples. How to use the exec function: The basic syntax of the exec function is as follows: exec

Indentation specifications and examples of Go language Go language is a programming language developed by Google. It is known for its concise and clear syntax, in which indentation specifications play a crucial role in the readability and beauty of the code. effect. This article will introduce the indentation specifications of the Go language and explain in detail through specific code examples. Indentation specifications In the Go language, tabs are used for indentation instead of spaces. Each level of indentation is one tab, usually set to a width of 4 spaces. Such specifications unify the coding style and enable teams to work together to compile

The DECODE function in Oracle is a conditional expression that is often used to return different results based on different conditions in query statements. This article will introduce the syntax, usage and sample code of the DECODE function in detail. 1. DECODE function syntax DECODE(expr,search1,result1[,search2,result2,...,default]) expr: the expression or field to be compared. search1,

Introduction to Python functions: usage and examples of the abs function 1. Introduction to the usage of the abs function In Python, the abs function is a built-in function used to calculate the absolute value of a given value. It can accept a numeric argument and return the absolute value of that number. The basic syntax of the abs function is as follows: abs(x) where x is the numerical parameter to calculate the absolute value, which can be an integer or a floating point number. 2. Examples of abs function Below we will show the usage of abs function through some specific examples: Example 1: Calculation

Introduction to Python functions: functions and examples of the eval function In Python programming, the eval function is a very useful function. The eval function can execute a string as program code, and its function is very powerful. In this article, we will introduce the detailed functions of the eval function, as well as some usage examples. 1. Function of eval function The function of eval function is very simple. It can execute a string as Python code. This means that we can convert a string

Introduction to Python functions: Usage and examples of the isinstance function Python is a powerful programming language that provides many built-in functions to make programming more convenient and efficient. One of the very useful built-in functions is the isinstance() function. This article will introduce the usage and examples of the isinstance function and provide specific code examples. The isinstance() function is used to determine whether an object is an instance of a specified class or type. The syntax of this function is as follows

Introduction to Python functions: functions and examples of sorted functions Python is a very powerful programming language with a wealth of built-in functions and modules. In this series of articles, we will introduce the commonly used functions of Python one by one and provide corresponding examples to help readers better understand and apply these functions. This article will introduce the functions and examples of the sorted function in detail. The sorted function is used to sort an iterable object and return a new sorted list. Can be used for numbers and words

The role and examples of the endwhile keyword in PHP In PHP, endwhile is a control structure used to implement while loops. Its function is to allow the program to repeatedly execute a block of code when specified conditions are met until the conditions are no longer met. The syntax form of endwhile is as follows: while(condition)://loop body code endwhile; in this syntax, condition is a logical expression. When the expression
