Home > Database > Mysql Tutorial > MySQL超简单的配置-主主配置

MySQL超简单的配置-主主配置

WBOY
Release: 2016-06-07 14:57:33
Original
1362 people have browsed it

MySQL同步就是怎么简单,鄙视那些自私自利的人, 本人的笔记: http://note.youdao.com/share/?id=d70f203ee0407a475fcfa47b62b51500nbsp;技术是需要共享的麻烦朋友帮收藏顶一顶。 ###################################################### MySQL server-id=

MySQL同步就是怎么简单,鄙视那些自私自利的人,
本人的笔记:
http://note.youdao.com/share/?id=d70f203ee0407a475fcfa47b62b51500&type=note
######################################################
                                技术是需要共享的                  麻烦朋友帮收藏顶一顶。
###################################################### MySQL
server-id	= 1
log-bin=mysql-bin
log-slave-updates
#slave-skip-errors=all
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
replicate_wild_ignore_table=mysql.%
replicate_wild_ignore_table=test.%
innodb_file_per_table=1
binlog_format =mixed
Copy after login
server-id	= 2
log-bin=mysql-bin
log-slave-updates
#slave-skip-errors=all
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=2
replicate_wild_ignore_table=mysql.%
replicate_wild_ignore_table=test.%
innodb_file_per_table=1
binlog_format =mixed
Copy after login
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.46  Ahost
Copy after login
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.47  Bhost
Copy after login
###################################### 
# Firewall configuration written by system-config-firewall 
# Manual customization of this file is not recommended. 
*filter 
:INPUT ACCEPT [0:0] 
:FORWARD ACCEPT [0:0] 
:OUTPUT ACCEPT [0:0] 
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT 
-A INPUT -p icmp -j ACCEPT 
-A INPUT -i lo -j ACCEPT 
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT 
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT 
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT 
-A INPUT -j REJECT –reject-with icmp-host-prohibited 
-A FORWARD -j REJECT –reject-with icmp-host-prohibited 
COMMIT 
#####################################
防火墙
1) 重启后生效 
开启: chkconfig iptables on 
关闭: chkconfig iptables off 

防火墙
2) 即时生效,重启后失效 
开启: service iptables start 
关闭: service iptables stop 
#####################################
一般是事务回滚造成的:
解决办法:
mysql> slave stop;
mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
mysql> slave start;
######################################

Copy after login
解决办法一、
Slave_SQL_Running: No
1.程序可能在slave上进行了写操作
2.也可能是slave机器重起后,事务回滚造成的.



 Last_SQL_Errno: 1677
        Last_SQL_Error: Column 1 of table 'test.t' cannot be converted from type 'int' to type 'bigint(20)'
        解决方法:这个案例是从网上找到的,自己动手实验了一把。从错误信息来看表面上是由于在slave上无法执行一条转换字段类型的SQL语句。实际上并不是有这种语句直接引起的,而是间接引起的(之前某些操作导致主从表字段类型不一致,接下来对这个表进行DML时就会报错)。它的意思是在对这个表t进行DML操作时,发现主从上表结果不一致,比如这里是说在主上t的字段1是int类型,但是从上t的字段1是bigint类型,所以报错。那么为什么要报错呢?这是从安全角度考虑,因为如果字段类型不一致可能会导致数据截断之类的问题。那么解决方法呢?通过参数slave_type_conversions进行控制,它有三种取值:
ALL_LOSSY:仅支持有损转换,什么叫有损?比如一个值本来是bigint存储为9999999999999,现在转换为int类型势必会要截断从而导致数据不一致。
ALL_NON_LOSSY:仅支持无损转换,只能在无损的情况下才能进行转换
ALL_LOSSY,ALL_NON_LOSSY:有损/无算转换都支持
空,即不设置这个参数:必须主从的字段类型一模一样。
注意: 前面说的这几中情况都只在binlog_format=ROW的情况下才有效。


        Last_SQL_Errno: 1194
        Last_SQL_Error: Error 'Table 'traincenter' is marked as crashed and should be repaired' on query. Default database: 'basketballman'. Query: 'update traincenter set points='4',pointstime='1361912066'  where uid = '1847482697' limit 1'
        解决方法:myisam表traincenter损坏,直接repair table即可。至于为什么myisam类型表比innodb更容易损坏,我觉得有两个原因:1,innodb有double write机制,损坏或者half write的页可以用它恢复,第二innodb是事务引擎,都有操作都是事务的,而myisam是非事务的,存在写一半但是操作终止情况。


        Last_IO_Errno: 1236
        Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'
        解决方法:主库上的binlog文件已经不存在但是在index file中确有相应记录存在。我这里发生这个错误的原因在于由于复制中断时间很长,报警出来一直没人处理,这个中断时间超过master上binlog超期时间,等恢复复制时需要的binlog已经由于其超期而被删掉,没办法只好重建这个实例了。以大家都要引以为戒
stop slave;
reset slave; 
slave start;


        Last_IO_Errno: 1593
        Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it).
        解决方法:主从配置的server-id一样,而在主从复制环境中server-id一样的binlog events都会被过滤掉。具体server-id的含义可以了解一下复制原理。这个一般是因为拷贝配置文件时忘记修改server-id导致,遇到这类问题也比较容易,平时操作谨慎一点即可。


        Last_Errno: 1053
        Last_Error: Query partially completed on the master (error on master: 1053) and was aborted. There is a chance that your master is inconsistent at this point. If you are sure that your master is ok, run this query manually on the slave and then restart the slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE; . Query: 'insert into ...
        解决方法:查询在master上部分完成,然后终止了。这马上又能想到是myisam表,结果也正是这样。由于myisam不支持事务所以可能存在一个查询完成一部分然后失败的情况。解决方法一般也就是提示信息给出的跳过一个binlog event。不过确认跳过之前最好还是查询一下master上是否真的存在相应的记录,因为错误信息同时还会给出它认为在master上执行一部分然后终止的查询语句。


        Last_SQL_Errno: 1666
        Last_SQL_Error: Error executing row event: 'Cannot execute statement: impossible to write to binary log since statement is in row format and BINLOG_FORMAT = STATEMENT.' 
        解决方法:这个案例的背景是做一个ABC结构的复制,B、C中设定的binlog_format=statement,A中的是MIXED,所以当B尝试重做A过来的relay log,然后记录binlog(传给C)时发现relay log的binlog_format与自己设定的binlog_format不一致。我当时就是直接先更改BC的binlog_format=MIXED解决。


        Last_Errno: 1032
        Last_Error: Could not execute Update_rows event on table db.table; Can't find record in 'table', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000064, end_log_pos 158847
        解决方法:这个是在binlog_format=row复制下发生的。原因是因为row格式复制是最严格的,所以在mysql看来如果在从库上找不到要更新的这条记录,那么就代表主从数据不一致,因此报错。另外顺便说一句,对于row格式binlog,如果某个更新操作实际上并没有更新行,这个操作是不会记binlog的,因为row格式的binlog宗旨就是只记录发生了改变的行。所以这个解决办法根据你自己实际应用来定,最好的方法还是重做slave吧,这样更放心。


        Last_Errno: 28
        Last_Error: Error in Append_block event: write to '/tmp/SQL_LOAD-32343798-72213798-1.data' failed
        解决方法: 首先说错误原因:主库执行load data infile,同步到从库后load data infile存放的文件默认是放在/tmp(由参数slave_load_tmpdir控制),而/tmp空间不够因此报错。因此只要将从库上slave_load_tmpdir设置到一个磁盘空间足够大的分区就行。
Copy after login
①##########################
show variables like 'server_id';
②##########################
server-id	= 1
log-bin=mysql-bin
log-slave-updates
#slave-skip-errors=all
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
innodb_file_per_table=1
binlog_format =mixed
③##########################
GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO'repl'@'%' IDENTIFIED BY '123456';
④##########################
SHOW GRANTS FOR repl@'%';
⑤##########################
FLUSH PRIVILEGES;
⑥##########################
show master status\G 
*************** 1. row **************
       File: mysql-bin.000005
        Position: 37312
    Binlog_Do_DB:
Binlog_Ignore_DB: 
⑦##########################
change master to
master_host='192.168.1.47',
master_user='repl',
master_password='123456',
master_log_file='mysql-bin.000006',
master_log_pos=11792,
master_port=3306;
⑧##########################
show slave status\G
⑨##########################
start slave;
############################
如果起不来就reset slave
############################
Copy after login
①##########################
show variables like 'server_id';
②##########################
server-id	= 9
log-bin=mysql-bin
log-slave-updates
#slave-skip-errors=all
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=2
innodb_file_per_table=1
binlog_format =mixed
③##########################
GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO'repl'@'%' IDENTIFIED BY '123456';
④##########################
SHOW GRANTS FOR repl@'%';
⑤##########################
FLUSH PRIVILEGES;
⑥##########################
show master status\G
************* 1. row ****************
        File: mysql-bin.000006
        Position: 11792
    Binlog_Do_DB:
Binlog_Ignore_DB:  
⑦##########################
change master to
master_host='192.168.1.46',
master_user='repl',
master_password='123456',
master_log_file='mysql-bin.000005',
master_log_pos=37312,
master_port=3306;
⑧##########################
show slave status\G
⑨##########################
start slave;
############################
如果起不来就reset slave
############################
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template