mysql send-q_windows与centos-mysql主从同步

在主服务器新建一个用户,给从服务器同步使用。

GRANT ALL PRIVILEGES ON *.* TO 'syncAccount'@'172.16.254.170' IDENTIFIED BY 'syncPassword';

修改my.ini

server-id=1

log-bin=mysql-bin

binlog-do-db=lbqdb

binlog-ignore-db=mysql

重启主服务器 mysql服务

mysql>show master status;

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

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

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

| mysql-bin.000001 | 446 | lbqdb | mysql |

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

1 row in set

修改slave机中mysql配置文件my.cnf

同样在[mysqld]字段下添加如下内容

server-id=2

master-host=xxx.xxx.xxx.xxx

master-user=syncAccount

master-password=syncPassword

master-port=3306

master-connect-retry=60

replicate-do-db=lbqdb

重启mysql报错:

service mysql start

Starting MySQL.. ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).

经查 因为这些参数5.1.7以后就不支持了

master-host=

master-user=

master-password=

master-port=

master-connect-retry=

这些参数 mysql5.5已经废弃了

必须在slave上用change master to 来设置slave

重新编辑my.cnf

server_id = 2

log_bin = mysql_bin

binlog_do_db = lbqdb

binlog_ignore_db = mysql

重启成功。

mysql –u root –p

设置连接master:

mysql->change master to master_host='xxx.xxx.xxx.xxx',master_user='syncAccount',master_password='syncPassword', master_log_file='mysql-bin.000001',master_log_pos=446;

连接的账户 IP 密码为mastermysql的。master_log_file 和log_pos 为前期windows mysql的show master status 中看到。

出现OK之后

Start slave;启动slave

查看状态

Show slave status\G

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

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.3.4

Master_User: syncAccount

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000001

Read_Master_Log_Pos: 1682

Relay_Log_File: localhost-relay-bin.000002

Relay_Log_Pos: 1489

Relay_Master_Log_File: mysql-bin.000001

**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: 1682

Relay_Log_Space: 1649

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

1 row in set (0.00 sec)

重点关注这两个:

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

当slave_IO_Running 和Slave_SQL_Running 都为yes 说明配置成功。

测试了一下,在主数据库新建表并插入数据,从数据库也新建了表,里面也有对应数据。证明数据库已经同步了。

MySQL主从不同步问题解决

问题 描述:主从复制在某个时刻,从服务器同步失败,并给出报错消息。

消息内容:基本意思是缺少某个库的某个表

原因:主从服务长时间不同步,主库已经生成很多新的表或者库,而从库却没有。

操作过程:

(1)登陆主服务器,查看主服务器的状态

mysql>show master status;

(2)登陆从服务器,执行同步操作。

mysql>stop slave;mysql > change master to ...(此处省略);mysql > start slave;

(3)从服务器上查看状态

mysql > show slave status\G

看报错信息少什么表或库,少什么就直接从主服务器通过scp复制,然后重复过程(1)~(3)直到不报错为止

以上说明:同步前,主从数据库的数据库结构要相同。

PS:主键自增id重复的错误

......

Slave_SQL_Running: No

......

Last_SQL_Error: Error 'Duplicate entry '60503' for key 'PRIMARY'' on query....

在主服务器做备份,导入到从服务器的时候,由于没有停服务,也没有锁表,在生成binlog文件的时刻,与导出数据的时刻存在误差,导致从服务器上数据多出一些,同步时,某些自增id就重复了,根据给出的提示,我们可以将多出的数据删除,将AUTO_INCREMENT设为binlog中的值。都设置完成后,再次

start slave;

成功!

也就是说,start slave报错的话,不用担心脏数据,可以解决错误后,继续start slave.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值