zoukankan      html  css  js  c++  java
  • mysql主从同步

    主: 192.168.1.213
    从: 192.168.1.215

    -------------------------------------------------------------------------------------------------------------------
    在 主: 192.168.1.213 上操作

    vim /etc/my.cnf #add the following:
    server_id = 1
    log_bin = mysql-bin

    重启mysql;

    mysql -u root -p  登录mysql
    执行:
      grant replication slave on *.* to 'backup'@'192.168.1.215' identified by 'backup'; 创建backup用户,并授权给192.168.1.215使用 ;

    执行:
       show master status;
    记下 mysql-bin.xxxxxx 和 positionxxx

    执行:
       flush tables with read lock;

    不要退出mysql, 新建一个ssh到主192.168.1.213上的连接,然后执行 mysqldump -h127.0.0.1 -p3306 -uroot -p test > /usr/local/src/test.sql ,退出该ssh;

    然后解锁 unlock tables ,是的,这个时候就可以unlock tables;

    ----------------------------------------------------------------------------------------------------------
    在 从: 192.168.1.215 上的操作

    首先执行: rsync -av root@192.168.1.213:/usr/local/src/test.sql /usr/local/src/

    vim /etc/my.cnf #add the following:
    server_id = 2
    log_bin = mysql-bin

    重启mysql;

    执行: mysql -uroot -p test < /usr/local/src/test.sql

    进入mysql: mysql -u root -p
    执行  stop slave;   reset slave;
    然后执行  change master to master_host='192.168.1.213',master_port=3306,master_user='backup',master_password='backup',master_log_file='mysql-bin.xxxxxx',master_log_pos=positionxxx ;
    执行: start slave ;
    执行 show slave status G ,检查Slave_IO_Running和Slave_SQL_Running是否均为Yes,均为yes表示成功.

    注意,这是start slave 可能会不成功, 比如报 

          Slave SQL: Slave failed to initialize relay log info structure from the repository, Error_code: 1872

          Slave failed to initialize relay log info structure from the repository

          Could not initialize master info structure; more error messages can

    需要把 slave 上 的 relay_log, master.info 备份&删除,即可
    -----------------------------------------------------------------------------------------------------------

    再回到 主: 192.168.1.213 上操作
    在主数据库上新建一个库,并且在库中写一个表和一些数据。

    进入mysql:  mysql -u root -p , 执行:

    mysql> create database mysqltest;

    mysql> use mysqltest;

    mysql> create table user(id int(5),name char(10));

    mysql> insert into user values (00001,'zhangsan');

    -----------------------------------------------------------------------------------------------------------  

    进入到 从: 192.168.1.215 上的操作:

    进入mysql:  mysql -u root -p ,执行:
    use mysqltest;
    select * from user ;  检查是否有刚才插入的数据(00001,'zhangsan'),有就代表同步成功;

    ----------------------------------------------------------------------------------------------------------

  • 相关阅读:
    Android中Context具体解释 ---- 你所不知道的Context
    JDK6、Oracle11g、Weblogic10 For Linux64Bit安装部署说明
    matplotlib 可视化 —— 定制 matplotlib
    matplotlib 可视化 —— 移动坐标轴(中心位置)
    matplotlib 可视化 —— 移动坐标轴(中心位置)
    matplotlib 可视化 —— 定制画布风格 Customizing plots with style sheets(plt.style)
    matplotlib 可视化 —— 定制画布风格 Customizing plots with style sheets(plt.style)
    指数函数的研究
    指数函数的研究
    指数分布的研究
  • 原文地址:https://www.cnblogs.com/slips/p/3612047.html
Copyright © 2011-2022 走看看