作者写的比较详细,感觉很好,支持一下,收藏了!O(∩_∩)O谢谢!
一、实验环境部署
主服务器 192.168.18.42 端口3306 ==》 从服务器 192.168.18.44 端口 3306
主服务器 192.168.18.43 端口3306 ==》 从服务器 192.168.18.44 端口 3307
##数据库,已经安装mysql服务,安装部分略。从服务器上的多个mysql实例,请看另一篇帖子《用mysql_multi 实现一台机器跑多台mysql 》
二、部署服务器
1.在两台主服务器上赋予从机权限,有多台丛机,就执行多次(我们这里两台主库使用统一帐号密码)。
mysql> grant replication slave on *.* to 'backup'@'192.168.18.44' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
2.在主服务器上配置my.cnf
vi /etc/my.cnf
server-id = 1
log-bin = mysql-bin #保证binlog可读
read-only = 0 #主机,读写都可以
#binlog-do-db = test #需要备份数据,多个写多行,不写全部都备份
binlog-ignore-db = mysql #不需要备份的数据库,多个写多行
编辑后重启数据库 # service mysqld restart
3.配置从库服务器的my.cnf
vi /etc/my.cnf
[mysqld_multi]
mysqld = /mysql/bin/mysqld_safe
mysqladmin = /mysql/bin/mysqladmin
[mysqld1]
port = 3306
socket = /tmp/mysql3306.sock
pid-file = /data/mysql/data1/mysql3306.pid
datadir = /data/mysql/data1
skip-name-resolve
log-bin = mysql-bin-3306
log_slave_updates
expire_logs_days = 7
log-error = /data/mysql/data1/mysql3306.err
log_slow_queries = mysql3306-slow.log
long_query_time = 3
query_cache_size = 64M
query_cache_limit = 2M
slave-net-timeout = 10
server-id = 2 #server id 不要与主库的重复
master-host = 192.168.18.42 #对应主库的 ip地址
master-user = backup # slave 帐号
master-password = 123456 # 密码
master-port = 3306 #主库端口
replicate-ignore-db=mysql #跳过不备份的库
master-info-file = master.1842.info
master-connect-retry = 10
relay-log = relay-bin-1842 #中继日志
relay-log-index = relay-bin-1842
relay-log-info-file = relay-log-1842.info
default-character-set=gbk
innodb_data_home_dir = /data/mysql/data1
innodb_data_file_path = ibdata1:50M:autoextend
innodb_log_group_home_dir = /data/mysql/data1
innodb_buffer_pool_size = 3072M
innodb_file_per_table
innodb_open_files = 800
#innodb_flush_method = O_DIRECT
innodb_flush_method = O_DSYNC
skip-locking
key_buffer = 32M
max_allowed_packet = 16M
table_cache = 1024
sort_buffer_size = 8M
net_buffer_length = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 32M
max_connections = 100
read_only
wait_timeout=288000
interactive_timeout=288000
log-bin-trust-function-creators=1
replicate-ignore-db = test
replicate-ignore-table = mysql.columns_priv
replicate-ignore-table = mysql.host
replicate-ignore-table = mysql.db
replicate-ignore-table = mysql.procs_priv
replicate-ignore-table = mysql.tables_priv
replicate-ignore-table = mysql.user
[mysqld2]
port = 3307
socket = /tmp/mysql3307.sock
pid-file = /data/mysql/data2/mysql3307.pid
datadir = /data/mysql/data2
skip-name-resolve
log-bin = mysql-bin-3307
log_slave_updates
expire_logs_days = 7
log-error = /data/mysql/data1/mysql3307.err
log_slow_queries = mysql3307-slow.log
long_query_time = 3
query_cache_size = 64M
query_cache_limit = 2M
slave-net-timeout = 10
server-id = 2 #server id 不要与主库的重复
master-host = 192.168.18.43 #对应主库的 ip地址
master-user = backup # slave 帐号
master-password = 123456 # 密码
master-port = 3306 #主库端口
replicate-ignore-db=mysql #跳过不备份的库
master-info-file = master.1843.info
master-connect-retry = 10
relay-log = relay-bin-1843
relay-log-index = relay-bin-1843
relay-log-info-file = relay-log-1843.info
default-character-set=gbk
innodb_data_home_dir = /data/mysql/data2
innodb_data_file_path = ibdata1:50M:autoextend
innodb_log_group_home_dir = /data/mysql/data2
innodb_buffer_pool_size = 3072M
innodb_file_per_table
innodb_open_files = 800
#innodb_flush_method = O_DIRECT
innodb_flush_method = O_DSYNC
skip-locking
key_buffer = 32M
max_allowed_packet = 16M
table_cache = 1024
sort_buffer_size = 8M
net_buffer_length = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 32M
max_connections = 100
read_only
wait_timeout=288000
interactive_timeout=288000
log-bin-trust-function-creators=1
replicate-ignore-db = test
replicate-ignore-table = mysql.columns_priv
replicate-ignore-table = mysql.host
replicate-ignore-table = mysql.db
replicate-ignore-table = mysql.procs_priv
replicate-ignore-table = mysql.tables_priv
replicate-ignore-table = mysql.user
# 因为图方便就把参数全部抓出来了 对主从有用的也就标注的几个
4.配置完成后重启大从服务器
[root@localhost data1]# mysqld_multi --config-file=/etc/my.cnf --user=root --password=123456 report 1,2
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
5.在从库上进行chang master ;
1).在date1上
mysql -uroot -p -S /tmp/mysql3306.sock
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.18.43',
-> MASTER_PORT=3306,
-> MASTER_USER='backup',
-> MASTER_PASSWORD='123456'
Query OK, 0 rows affected (0.05 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
2)。在date2上
mysql -uroot -p -S /tmp/mysql3307.sock
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.18.42',
-> MASTER_PORT=3306,
-> MASTER_USER='backup',
-> MASTER_PASSWORD='123456'
Query OK, 0 rows affected (0.05 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
三、验证:
1.在大从服务器上
show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
2.在主库创建数据库(18.43上)
mysql> create database haifengtest;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| haifengtest |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
从库查看 (mysql3307.sock上)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| haifengtest |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
四、一种常见的问题。
在show slave status\G;时发现下面的问题,(因为我事先在从上创建了该库)
Relay_Master_Log_File: mysql-bin.000005
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB: mysql
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1007
Last_Error: Error 'Can't create database 'haifengtest'; database exists' on query. Default database: 'haifengtest'. Query: 'create database haifengtest'
如果Replication在Slave上出现上面错误而停止,一般都期望Slave能忽略这个错误,继续进行同步,而不是重新启动Slave。
这时可以使用 SQL_SLAVE_SKIP_COUNTER
mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
在验证一次
show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
一、实验环境部署
主服务器 192.168.18.42 端口3306 ==》 从服务器 192.168.18.44 端口 3306
主服务器 192.168.18.43 端口3306 ==》 从服务器 192.168.18.44 端口 3307
##数据库,已经安装mysql服务,安装部分略。从服务器上的多个mysql实例,请看另一篇帖子《用mysql_multi 实现一台机器跑多台mysql 》
二、部署服务器
1.在两台主服务器上赋予从机权限,有多台丛机,就执行多次(我们这里两台主库使用统一帐号密码)。
mysql> grant replication slave on *.* to 'backup'@'192.168.18.44' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
2.在主服务器上配置my.cnf
vi /etc/my.cnf
server-id = 1
log-bin = mysql-bin #保证binlog可读
read-only = 0 #主机,读写都可以
#binlog-do-db = test #需要备份数据,多个写多行,不写全部都备份
binlog-ignore-db = mysql #不需要备份的数据库,多个写多行
编辑后重启数据库 # service mysqld restart
3.配置从库服务器的my.cnf
vi /etc/my.cnf
[mysqld_multi]
mysqld = /mysql/bin/mysqld_safe
mysqladmin = /mysql/bin/mysqladmin
[mysqld1]
port = 3306
socket = /tmp/mysql3306.sock
pid-file = /data/mysql/data1/mysql3306.pid
datadir = /data/mysql/data1
skip-name-resolve
log-bin = mysql-bin-3306
log_slave_updates
expire_logs_days = 7
log-error = /data/mysql/data1/mysql3306.err
log_slow_queries = mysql3306-slow.log
long_query_time = 3
query_cache_size = 64M
query_cache_limit = 2M
slave-net-timeout = 10
server-id = 2 #server id 不要与主库的重复
master-host = 192.168.18.42 #对应主库的 ip地址
master-user = backup # slave 帐号
master-password = 123456 # 密码
master-port = 3306 #主库端口
replicate-ignore-db=mysql #跳过不备份的库
master-info-file = master.1842.info
master-connect-retry = 10
relay-log = relay-bin-1842 #中继日志
relay-log-index = relay-bin-1842
relay-log-info-file = relay-log-1842.info
default-character-set=gbk
innodb_data_home_dir = /data/mysql/data1
innodb_data_file_path = ibdata1:50M:autoextend
innodb_log_group_home_dir = /data/mysql/data1
innodb_buffer_pool_size = 3072M
innodb_file_per_table
innodb_open_files = 800
#innodb_flush_method = O_DIRECT
innodb_flush_method = O_DSYNC
skip-locking
key_buffer = 32M
max_allowed_packet = 16M
table_cache = 1024
sort_buffer_size = 8M
net_buffer_length = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 32M
max_connections = 100
read_only
wait_timeout=288000
interactive_timeout=288000
log-bin-trust-function-creators=1
replicate-ignore-db = test
replicate-ignore-table = mysql.columns_priv
replicate-ignore-table = mysql.host
replicate-ignore-table = mysql.db
replicate-ignore-table = mysql.procs_priv
replicate-ignore-table = mysql.tables_priv
replicate-ignore-table = mysql.user
[mysqld2]
port = 3307
socket = /tmp/mysql3307.sock
pid-file = /data/mysql/data2/mysql3307.pid
datadir = /data/mysql/data2
skip-name-resolve
log-bin = mysql-bin-3307
log_slave_updates
expire_logs_days = 7
log-error = /data/mysql/data1/mysql3307.err
log_slow_queries = mysql3307-slow.log
long_query_time = 3
query_cache_size = 64M
query_cache_limit = 2M
slave-net-timeout = 10
server-id = 2 #server id 不要与主库的重复
master-host = 192.168.18.43 #对应主库的 ip地址
master-user = backup # slave 帐号
master-password = 123456 # 密码
master-port = 3306 #主库端口
replicate-ignore-db=mysql #跳过不备份的库
master-info-file = master.1843.info
master-connect-retry = 10
relay-log = relay-bin-1843
relay-log-index = relay-bin-1843
relay-log-info-file = relay-log-1843.info
default-character-set=gbk
innodb_data_home_dir = /data/mysql/data2
innodb_data_file_path = ibdata1:50M:autoextend
innodb_log_group_home_dir = /data/mysql/data2
innodb_buffer_pool_size = 3072M
innodb_file_per_table
innodb_open_files = 800
#innodb_flush_method = O_DIRECT
innodb_flush_method = O_DSYNC
skip-locking
key_buffer = 32M
max_allowed_packet = 16M
table_cache = 1024
sort_buffer_size = 8M
net_buffer_length = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 32M
max_connections = 100
read_only
wait_timeout=288000
interactive_timeout=288000
log-bin-trust-function-creators=1
replicate-ignore-db = test
replicate-ignore-table = mysql.columns_priv
replicate-ignore-table = mysql.host
replicate-ignore-table = mysql.db
replicate-ignore-table = mysql.procs_priv
replicate-ignore-table = mysql.tables_priv
replicate-ignore-table = mysql.user
# 因为图方便就把参数全部抓出来了 对主从有用的也就标注的几个
4.配置完成后重启大从服务器
[root@localhost data1]# mysqld_multi --config-file=/etc/my.cnf --user=root --password=123456 report 1,2
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
5.在从库上进行chang master ;
1).在date1上
mysql -uroot -p -S /tmp/mysql3306.sock
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.18.43',
-> MASTER_PORT=3306,
-> MASTER_USER='backup',
-> MASTER_PASSWORD='123456'
Query OK, 0 rows affected (0.05 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
2)。在date2上
mysql -uroot -p -S /tmp/mysql3307.sock
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.18.42',
-> MASTER_PORT=3306,
-> MASTER_USER='backup',
-> MASTER_PASSWORD='123456'
Query OK, 0 rows affected (0.05 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
三、验证:
1.在大从服务器上
show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
2.在主库创建数据库(18.43上)
mysql> create database haifengtest;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| haifengtest |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
从库查看 (mysql3307.sock上)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| haifengtest |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
四、一种常见的问题。
在show slave status\G;时发现下面的问题,(因为我事先在从上创建了该库)
Relay_Master_Log_File: mysql-bin.000005
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB: mysql
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1007
Last_Error: Error 'Can't create database 'haifengtest'; database exists' on query. Default database: 'haifengtest'. Query: 'create database haifengtest'
如果Replication在Slave上出现上面错误而停止,一般都期望Slave能忽略这个错误,继续进行同步,而不是重新启动Slave。
这时可以使用 SQL_SLAVE_SKIP_COUNTER
mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
在验证一次
show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
发表评论
-
主从配置binlog_format
2013-10-28 13:56 0statement/row/mixed # AUTO_INCR ... -
主从配置
2013-10-11 13:36 0【master】 binlog_format=ROW或者MIX ... -
MYSQL主从切换(主库未宕机)
2013-10-11 11:37 4567将主从(3307主--3309从)切换 前提:3307正常 ... -
MYSQL主从切换(主库宕机)
2013-10-11 10:40 1450将主从(3307主--3309从)切换 前提:3307宕机 ... -
MYSQL主主切换(主库宕机)
2013-10-10 17:28 1868将主主(3307写--3308读)切换 前提:3307宕机 ... -
MYSQL主主切换(主库未宕机)
2013-10-10 17:03 601将主主(3307写--3308读)切换 前提:停止业务,330 ... -
MYSQL主从:主(生产库)-->从(新实例)
2013-10-10 14:46 764搭建主(mysqld3307,生产库) --> 从(my ... -
MYSQL主从:主(新实例)--主(新实例,只读)
2013-10-10 13:39 1230一、一台机器安装两个实例(3307、3308) 按照http: ... -
MYSQL5.5 主从配置:A ->B ->C
2013-02-19 14:58 812A(端口3307)->B(端口3308)-> ...
相关推荐
MySQL 数据库主从配置 MySQL 数据库主从配置是指在 MySQL 数据库中实现主从复制的...MySQL 数据库主从配置是实现数据库实时同步的重要步骤,该过程需要在主服务器和从服务器上进行配置,以确保数据的安全和一致性。
mysql 数据库主从配置是指将一个 mysql 服务器设置为主服务器,另一个 mysql 服务器设置为从服务器,并将主服务器上的数据实时同步到从服务器上,以达到数据备份和负载均衡的目的。该配置可以提高数据库的可用性和可...
### MySQL数据库主从复制高可用技术改造环境部署方案 #### 安装部署DRBD DRBD(Distributed Replicated Block Device)是一种分布式复制块设备,主要用于实现数据在两台或多台服务器之间的实时同步,以此来构建高...
MySQL 5.7 主从配置是指在两个或多个 MySQL 服务器之间实现数据的实时同步复制,主服务器作为数据的写入入口,slave 服务器作为数据的读取入口。这种配置可以提高数据库的高可用性和读取性能。 1. 主从配置前提 ...
mysql主从数据库配置详细步骤,自己实验后得出的步骤文档
MySQL提供单向异步同步功能,同步机制是基于master主服务器把所有对数据库的更新操作(更新、删除等)都记录在二进制日志里,并维护日志文件的一个索引跟踪。从服务器在日志中读取最后一次成功更新的位置,并接收从...
MySQL 数据库主从同步...结论:MySQL 数据库主从同步是通过配置主数据库和从数据库来实现数据的实时同步,提高了数据的可用性和负载均衡。在配置过程中需要注意版本一致、服务器 ID、忽略数据库、指定同步表等问题。
本文档将详细介绍 MySQL 数据库主从同步服务器的部署过程,包括配置主服务器和从服务器的配置文件、解决远程连接问题、配置主数据库的账号和授权、配置从服务器的配置文件等。 一、配置主服务器的配置文件 在配置...
- **主从复制**: 最常见的复制模式,其中一个或多个从服务器连接到主服务器,从主服务器获取二进制日志并更新自身数据。 - **主主复制**: 所有服务器既是主服务器也是从服务器,任何服务器都可以作为主服务器向其他...
### MySQL 主从库配置详解 #### 一、MySQL 安装与环境变量设置 在进行 MySQL 主从库配置之前,我们需要确保已经正确安装了 MySQL,并设置了相应的环境变量。以下是具体的步骤: 1. **下载 MySQL 免安装版**: - ...
根据提供的文件信息,本文将详细介绍如何在Linux环境下安装并配置MySQL 5.6的主从复制环境,并且会涉及MySQL...通过上述步骤,您可以完成MySQL 5.6的服务安装与基本的主从复制配置,并对数据库的编码格式有一定的了解。
MySQL 数据库的主从配置是数据库高可用性和数据冗余的一种常见实现方式,尤其是在多主对一从的配置中,可以提高系统的容错能力和负载均衡。以下是对这种配置的详细解释: 1. **主从复制的基本原理**: 主从复制是...
MySQL数据库的主从机制是一种常见的高可用性和负载均衡解决方案,它允许数据从一个主服务器(Master)异步复制到一个或多个从服务器(Slave)。这种机制对于数据安全性、读写分离以及故障转移具有重要意义。 主从...
MySQL的主从复制是一种数据库同步技术,它允许数据从一个主数据库服务器(Master)复制到一个或多个从数据库服务器(Slave)。主从复制是一种异步复制过程,主要基于MySQL的二进制日志(Binary Log)实现。主服务器...