mysql主从同步设置 1.设置主服务器 MYSQL主服务器版本尽量低于或等于从服务器版本。 server-id=1205978
log-bin=mysql-bin
log-error=mysql-bin.err
binlog_do_db=testdb 2.设置从服务器 server-id=1344576601
master-host = 1.202.197.113
master-port = 3306
master-user = bakcopy
master-password = test111
master-retry-count = 999
master-connect-retry = 60 mysql主从同步问题解决 1.Slave_SQL_Running: No 原因一:程序可能在slave上进行了写操作 原因二:也可能是slave机器重起后,事务回滚造成的.
一般是事务回滚造成的: 解决办法: mysql> slave stop; mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1; mysql> slave start; 解决办法二、 首先停掉Slave服务:slave stop 到主服务器上查看主机状态: 记录File和Position对应的值 进入master mysql> show master status; +----------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +----------------------+----------+--------------+------------------+ | localhost-bin.000094 | 33622483 | | | +----------------------+----------+--------------+------------------+ 1 row in set (0.00 sec) 然后到slave服务器上执行手动同步:
mysql> change master to > master_host='master_ip', > master_user='user', > master_password='pwd', > master_port=3306, > master_log_file=localhost-bin.000094', > master_log_pos=33622483 ; 1 row in set (0.00 sec) mysql> slave start; 1 row in set (0.00 sec) mysql> show slave status\G *************************** 1. row *************************** ........ Master_Log_File: localhost-bin.000094 Read_Master_Log_Pos: 33768775 Relay_Log_File: localhost-relay-bin.000537 Relay_Log_Pos: 1094034 Relay_Master_Log_File: localhost-bin.000094 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: 手动同步需要停止master的写操作! 2.主服务器表名不区分大小写,从服务器表名区分大小写问题 修改my.ini或my.cnf中mysqld节点 lower_case_table_names=1 让mysql图略大小写 mysql主从同步常用命令 show master status; show slave status; show processlist; show processlist/G; |