Mysql 主从复制

   注:我已经安装好了Mysql,前面的安装过程可以看MySQL + MySQL Front 安装使用
   station56-->master
   station31-->slave

  一、首先登陆master 数据库

mysql> grant replication slave on *.* to root@‘192.168.0.56  identified by '123456';
  mysql> flush tables with read lock;
  mysql> show master status;
  +------------------+----------+--------------+------------------+
  | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
  +------------------+----------+--------------+------------------+
  | mysql-bin.000001 |      97 |              |                  |
  +------------------+----------+--------------+------------------+
  1 row in set (0.00 sec)
 [root@station56 ~]#mysqldump --all-databases > all.sql
 [root@station56 ~]#mysql -uroot -p123456
mysql> unlock tables;    //备份(导出)master 数据库,解除只读锁定

二、slave 上的设置

[root@station31~]# mysql -uroot -p123456 < all.sql   //登录slave数据库,查看库和表,看是否和master一致,
[root@station31~]# vi /etc/my.c
将server-id = 1修改成server-id = 2
[root@station31 ~]# service mysqld stop
[root@station31 ~]# mysqld_safe --skip-save-start &  //这样做的好处是不会立即启动从数据库上的复制进程,方便我们进一步配置从服务器
[root@station31~]#mysql
mysql> CHANGE MASTER TO
    -> MASTER_HOST='192.168.0.56',
    -> MASTER_USER='root',
    -> MASTER_PASSWORD='123456',
    -> MASTER_LOG_FILE='mysql-bin.000001',
    -> MASTER_LOG_POS=97;
mysql> start slave; 
mysql> show processlist \G
*************************** 1. row ***************************
     Id: 2
   User: root
   Host: localhost
     db: NULL
Command: Query
   Time: 0
 State: NULL
   Info: show processlist
*************************** 2. row ***************************
     Id: 3
   User: system user
   Host:
     db: NULL
Command: Connect
   Time: 30
 State: Waiting for master to send event
   Info: NULL
*************************** 3. row ***************************
     Id: 4
   User: system user
   Host:
     db: NULL
Command: Connect
   Time: 30
  State: Has read all relay log; waiting for the slave I/O thread

to update it
   Info: NULL
3 rows in set (0.00 sec)





 






 

 

你可能感兴趣的:(mysql,数据库,职场,主从,休闲)