1
2
3
4
5
6
7
8
9
10
11
12
13
|
master服务器配置:
vi
/usr/local/mysql/etc/my
.cnf
[mysqld]
server-
id
=202
#设置服务器唯一的id,默认是1,我们设置ip最后一段,slave设置203
log-bin=mysql-bin
# 启用二进制日志
#binlog-ignore-db = mysql,information_schema #忽略写入binlog的库
slave服务器配置:
vi
/usr/local/mysql/etc/my
.cnf
[mysqld]
server-
id
=203
replicate-
do
-db = abc
#只同步abc库
slave-skip-errors = all
#忽略因复制出现的所有错误
|
1
|
/etc/init
.d
/mysqld
restart
|
1
2
|
mysql> mysql -u root -p123.com
mysql> GRANT REPLICATION SLAVE ON *.* to ‘
sync
’@‘192.168.1.2’ identified by ‘1234.com’;
#replication:复制
|
1
2
3
4
5
6
|
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002 | 263 | | |
+------------------+----------+--------------+------------------+
|
1
2
3
4
5
6
7
|
mysql> change master to
-> master_host=
'192.168.0.202'
,
-> master_user=
'sync'
,
-> master_password=
'1234.com'
,
-> master_log_file=
'mysql-bin.000002'
,
-> master_log_pos=
263
;
#Log和pos是master上随机获取的。这段也可以写到my.cnf里面。
|
1
|
mysql> start slave;
|
1
2
3
4
5
6
7
8
9
10
11
|
mysql> create database abc;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| abc |
| mysql |
| performance_schema |
|
test
|
+--------------------+
|