MySQL主(Master)从(Slave)备份;

实验环境:

CentOS release 6.6 (Final) 32位

Master:10.10.10.11

Slave1:10.10.10.7

Slave2:10.10.10.8

1) MySQL 安装 (分别在Master,Slave1,Slave2 运行如下命令


[[email protected] ~]# yum install mysql-server mysql -y

[[email protected] ~]# service mysqld start

2)配置my.cnf


[[email protected] ~]# mysqladmin -u root password 123.com  //修改mysql root的密码为"123.com"

[[email protected] ~]# vi /etc/my.cnf    //修改my.cfg 配置文件,添加如下内容;

相关信息如下:

#Master

[mysqld]

log-bin=MySQL-bin    //二进制文件

server-id=1     //服务ID (唯一)

#Slave1

[mysqld]

log-bin=MySQL-bin    //二进制文件

server-id=2     //服务ID

#Slave2

[mysqld]

log-bin=MySQL-bin    //二进制文件

server-id=3     //服务ID

保存退出之后,重启MYSQL服务:

[[email protected] ~]# service mysqld restart

Stopping mysqld:                                           [  OK  ]

Starting mysqld:                                           [  OK  ]

3)在Master上创建备份帐号;

[[email protected] ~]# mysql -u root -p123.com

mysql> GRANT REPLICATION SLAVE ON *.* to ‘myslave‘@‘10.10.10.7‘ identified by ‘123.com‘;

Query OK, 0 rows affected (0.02 sec)

mysql> GRANT REPLICATION SLAVE ON *.* to ‘myslave‘@‘10.10.10.8‘ identified by ‘123.com‘;

Query OK, 0 rows affected (0.02 sec)

查看Master状态

mysql> show master status;

+------------------+----------+--------------+------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+------------------+----------+--------------+------------------+

| MySQL-bin.000002 |      261 |              |                  |

+------------------+----------+--------------+------------------+

1 row in set (0.00 sec)

4)Slave1 Slave2上设置


[[email protected] ~]mysql -u root -p123.com

mysql> change master to

-> MASTER_HOST=‘10.10.10.11‘,

-> MASTER_USER=‘myslave‘,

-> MASTER_PASSWORD=‘123.com‘,

-> MASTER_LOG_FILE=‘MySQL-bin.000001‘,

-> MASTER_LOG_POS=261;

在Slave1,Slave2上启动Slave,并查看状态;

mysql> slave start;

mysql> show slave status \G

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 10.10.10.7

Master_User: myslave

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: MySQL-bin.000002

Read_Master_Log_Pos: 261

Relay_Log_File: mysqld-relay-bin.000004

Relay_Log_Pos: 406

Relay_Master_Log_File: MySQL-bin.000002

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB:

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: 261

Relay_Log_Space: 707

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:

1 row in set (0.00 sec)

5)测试Master,Slave同步;

1.在Master上创建数据库信息;

mysql> CREATE DATABASE info;

Query OK, 1 row affected (0.00 sec)

mysql> use info

Database changed

mysql> CREATE TABLE user (id int(3),name varchar(10));

Query OK, 0 rows affected (0.04 sec)

mysql> INSERT INTO user values (001,‘zhangcheng‘);

Query OK, 1 row affected (0.01 sec)

2.在Slave1,Slave2上查看;

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| NINESTAR           |

| info               |

| mysql              |

| test               |

+--------------------+

5 rows in set (0.00 sec)

mysql> use info

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> select * from user;

+------+------------+

| id   | name       |

+------+------------+

|    1 | zhangcheng |

+------+------------+

1 row in set (0.00 sec)

信息已同步!

时间: 2024-08-19 11:15:31

MySQL主(Master)从(Slave)备份;的相关文章

mysql主从复制 master和slave配置的参数大全

master所有参数1 log-bin=mysql-bin 1.控制master的是否开启binlog记录功能: 2.二进制文件最好放在单独的目录下,这不但方便优化.更方便维护. 3.重新命名二进制日志很简单,只需要修改[mysqld]里的log_bin选项,如下例子:要重新调整logbin的路径为"/home/mysql/binlog"[mysqld]log_bin=/home/mysql/binlog/binlog.log ll /home/mysql/binlog-rw-rw--

mysql的master中slave的账号密码忘记的查看的办法

无论是用那种方式实现mysql的主从同步的方法,只要是mysql的slave通过读取master的bin二进制文件实现同步的方法都会在slave中留下连接master的信息,如果你在不慎忘记当时主从同步时给的权限密码是什么的时候我们可以用过查看slave库文件夹下的master.info文件信息查看设置 [[email protected] mysqldata]# cat master.info  18 mysql-bin.000042#读取主库的bin文件 68711 192.168.168.

MySQL 主主报错: Fatal error: The slave I/O thread stops because master and slave have

Mysql 主主启动错误处理 error 信息: Slave_IO_State: Master_Host: 192.168.6.87 Master_User: replication Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000003 Read_Master_Log_Pos: 106 Relay_Log_File: mysqld-relay-bin.000002 Relay_Log_Pos: 4 Relay_

MySQL.master and slave 一主多从,切库传输

两个参数,一个是binlog_ignore_db.另一个是replicate-ignore-db  区别: binlog_ignore_db 参数是设置在主库上的,例如:binlog-ignore_db=test,那么针对test库下的所有操作(增删改)都会记录下来,这样slave在接受主库的binlog文件时文件量就会减少. 优点:减少网络I/O,减少slave端I/O线程的I/O量,优化复制性能 Replicate-ignore-db参数是设置在从库上的,例如:replicate-ignor

mysql (master/slave)复制原理及配置

1 复制概述 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台主机的数据复制到其它主机(slaves)上,并重新执行一遍来实现的.复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器.主服务器将更新写入二进制日志文件,并维护文件的一个索引以跟踪日志循环.这些日志可以记录发送到从服务器的更新.当一个从服务器连接主服务器时,它通知主服务器从服务器在日志中读取的最后一次成功更新的位置.从服务器接收

mysql5.5.44 主从复制master and slave have equal MySQL server ids

mysql5.5.44  主从复制配置 注:mysql从5.1.7以后开始就不支持my.cnf中"master-host"类似的参数; 必须在slave 的mysql中执行以下命令(最后的pos没有引号): mysql> change master to master_host='192.168.137.100', master_user='tongbu', master_password='123456', master_log_file='mysql-bin.000014',

mysql主主备份

mysql主主配置和主从配置的不同点在于主从的master不监控slavebin-log的变化,导致slave有新数据不能更新到master 主主配置的关键参数:log-slave-updates,两台mysql都需添加 测试环境: centos 6.5 x64 主1ip:192.168.0.1 主2ip:192.168.0.2 主主配置 主1 vim /etc/my.cnf server-id=1 bin-log=mysql-bin binlog-format=mixed log-slave-

故障案例:主从同步报错Fatal error: The slave I/O thread stops because master and slave have equal MySQL server

场景一:因为数据量非常,大概有1.4T,需要在原先master1-slave1的情况下再创建一个库slave2,并且挂在slave1下,即master1-slave1-slave2的结构.为了方便,当时停掉从库salve1,show master status记录状态,开启log_slave_updates,并且关闭salve1,然后将这个从库的data文件夹直接copy到新的从库,结果在创建slave2和slave1的主从关系时报错 Fatal error: The slave I/O thr

mysql数据库主从同步,master和slave上的mysql必须版本一样吗,如果不一样会有什么结果?

Slave_SQL_Running: No mysql同步故障解决如果数据不同步可以尝试该资料mysql> show slave status\GSlave_IO_Running: YesSlave_SQL_Running: NoLast_Errno: 1062....Seconds_Behind_Master:NULL原因:1.程序可能在slave上进行了写操作 2.也可能是slave机器重起后,事务回滚造成的.解决办法I:1.首先停掉Slave服务:slave stop2.到主服务器上查看主