mysql主从服务器:
主:192.168.121.128
从:192.168.121.129
主从服务器分别作以下操作:
版本一致
初始化表,并在后台启动mysql
修改root的密码
mysqladmin -u root password "newpass"
mysql主从文件的配置:
1、master主配置文件添加以下2行:
cat /etc/my.cnf
1
2
|
log-bin=mysql-bin
//
[必须]启用二进制日志
server-
id
=128
//
[必须]服务器唯一ID,默认是1,一般取IP最后一段
|
2、slave配置文件添加以下2行:
cat /etc/my.cnf
1
2
|
log-bin=mysql-bin
//
[不是必须]启用二进制日志
server-
id
=129
//
[必须]服务器唯一ID,默认是1,一般取IP最后一段
|
主库操作:
#mysql -uroot -p
1
2
3
4
5
6
7
8
|
mysql> GRANT REPLICATION SLAVE ON *.* to
'mysync'
@
'192.168.121.129'
identified by
'123456'
;
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 264 | | |
+------------------+----------+--------------+------------------+
1 row
in
set
(0.00 sec)
|
从库操作:
1
2
3
4
5
6
7
8
|
mysql> change master to master_host=
'192.168.121.128'
,master_user=
'mysync'
,master_password=
'123456'
,master_log_file=
'mysql-bin.000001'
,master_log_pos=264;
Query OK, 0 rows affected (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status;
#看到下面信息证明主从ok。
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
|
本文转自青衫解衣 51CTO博客,原文链接:http://blog.51cto.com/215687833/1892751