1,修改主数据库配置文件

 server-id = 1

 log_bin = mmss-bin

 binlog_do_db = hr

 重启服务

  service mysqld restart

2,修改从的数据库配置文件

 server-id = 2 

 重启服务

  service mysqld restart

3,登陆主的mysql

 mysql -uroot -p 

 create user 'slave_cpcp'@'111.111.111.111' identified by 'mms@123456';

 grant replication slave on *.* to 'slave_cpcp'@'111.111.111.111';

 flush privileges

 select host,user from mysql.user;

4,看看二进制日志位置,先锁表操作

   flush tables with read lock;

   show master status;(记录下来)

   mmss-bin.000001 |      364 | hr

  

   unlock tables;

5,导出现有数据

  mysqldump -uroot -p -B   hr >/tmp/hr.sql(备份那个数据库)

  sz /tmp/hr.sql 导出桌面

  rz 导入到从库的tmp文件

  从tmp 导入mysql到 mysql -uroot -p </tmp/hr.sql

6.配置从服务器

  mysql -uroot -p

  stop slave;

  change master to

  master_host='114.114.114.114',

  master_user='slave_cpcp',

  master_password='mms@123456',

  master_log_file='mmss-bin.000001',

  master_log_pos=364;

  start slave;

  show slave status\G;