以下内容比较简略,权当笔记使用!看到了朋友也可参考其它的博客进行实际操作
主服务器:192.168.17.123
从服务器:192.168.17.111
[主服务器授权]
1、在主服务器建立一个专门用来主从复制的用户
insert into mysql.user(Host,User,Password) values("%","replication",password("123456"));
2、为该用户授权
语法:
grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口令’;
命令:
grant replication slave ON *.* to 'replication'@'%' identified by '123456';
注意:%可以找成相应的从服务器IP
replication slave 此权限可以查看主服务器,要以从主服务器读取二进杂制日志
3、刷新权限表
flush privileges;
[主服务器配置]
log-bin=mysql-bin
server-id=1
mysql> show master status\G;
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 107
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)
[从数据库配置]
#在mysql命令行下输入:
mysql> change master to master_host='192.168.17.123',master_user='replication',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=107;
注意:
master_log_file要为主服务器上的log-bin
#启动
mysql> start slave;
#检测从服务器状态
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.17.123
Master_User: replication
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 256
Relay_Log_File: localhost-relay-bin.000002
Relay_Log_Pos: 402
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes #必须为yes才能同步成功
Slave_SQL_Running: Yes #必须为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: 256
Relay_Log_Space: 562
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
之后就可以在主数据库中插入删除测试主从复制了!