搜索
您的当前位置:首页正文

单机版的Mysql主从数据库配置

2020-11-09 来源:意榕旅游网

环 境 mysql-5.0.22 解压版。(Copy 成两份 ,master,slave) windowsXP 一、Master的设置 1、配制my.ini [client] port = 3308 [mysqld] port =3308 server-id = 1 binlog-do-db=test1 ##要同步的数据库名为test1 log-bin =mysql-bin 然后在Console 执行: GR

环 境
mysql-5.0.22 解压版。(Copy 成两份 ,master,slave)
windowsXP
一、Master的设置
1、配制my.ini
[client]
port = 3308
[mysqld]
port =3308
server-id = 1
binlog-do-db=test1 ##要同步的数据库名为test1
log-bin =mysql-bin

然后在Console 执行: GRANT FILE,SELECT,REPLICATION SLAVE ON *.* TO 'slaver1'@'127.0.0.1' IDENTIFIED BY 'slaver1pwd';
开一个新账号(用户名:slaver1 密码:slaver1pwd)并赋于权限
运行Mysqld.exe,并创建新数据库test1,可在Console下输入:show master status\G查看状态!

*************************** 1. row*****************
File: mysql-bin.000305
Position: 98
Binlog_Do_DB: test1
Binlog_Ignore_DB:

二、Slaver 的设置

1、配制my.ini
[client]
port = 3309

[mysqld]
port = 3309
server-id = 2

master-host = 127.0.0.1

master-user = slaver1

master-password = slaver1pwd

master-port = 3308

replicate-do-db=test1 ##要同步的数据库

运行Slaver 的Mysqld.exe,在Console窗口执行 show slave status\G 查看状态,如下:

*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 127.0.0.1
Master_User: slaver1
Master_Port: 3308
Connect_Retry: 60
Master_Log_File: mysql-bin.000305
Read_Master_Log_Pos: 98
Relay_Log_File: ccf-3acf6017ef4-relay-bin.000005
Relay_Log_Pos: 235
Relay_Master_Log_File: mysql-bin.000305
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: test1
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: 98
Relay_Log_Space: 235
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

常见问题

1、SQL I/O Running: no

原因:用户名或密码不正确、slaver1的权限不够!

如果正确的执行:GRANT FILE,SELECT,REPLICATION SLAVE ON *.* TO 'slaver1'@'127.0.0.1' IDENTIFIED BY 'slaver1pwd'; 仍然显示SQL I/O Running:NO,可能是Master的用户管理中Slaver用户未选中REPLICATION Client (用Navicat-Manager User ->Slaver1 的右边可选列表 )

2、Slave_SQL_Running: NO

原因:
a.程序可能在slave上进行了写操作
b.slave机器重起后,事务回滚.

解决方法:

在Slaver的Console:

2.1.停掉Slave服务

mysql>slave stop
2.2、查看Master的状态:(在Master上执行)
show master status\G

2.3、手工同步

mysql> change master to
> master_host='127.0.0.1',
> master_user='slaver1',
> master_password='slaver1pwd',
> master_port=3308,
> master_log_file='mysql-bin.000020',
> master_log_pos=98;
2.4、重启slave

mysql> slave start;

附录

1、查看异常信息文件:一般在data(数据库存文件的存放位置)的文件夹中,后缀名为.err的文件

2、show processlist\G 可以协助查看用户信息

Top