Blogger Information
Blog 51
fans 0
comment 1
visits 65109
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
MYSQL主从配置
鱼的熊掌
Original
908 people have browsed it

    注:两天服务器mysql版本最好一致

 主库操作

    

        1、进入mysql配置文件 my.cnf或者my.ini

            [mysqld]下

        2、开启bin-log日志

                log-bin=mysql-bin

                binlog_format=mixed

                expire_logs_days = 7  日志存储天数

                binlog-do-db=tajy  日志允许的数据库

                binlog-ignore-db=mysql,infomation_schema,performance_schema,tajy_qianzhi  日志拒绝的数据库

                binlog-do-db=base 仅同步数据库

        

        3、设置服务id

            server-id = 98

        4、登录mysql  mysql -u root -p密码

        5、创建slave账号 从库使用

            创建账号,设置账号权限

            create user 'kangsai'@'%' identified by 'kangsai@123';  创建账号

            grant all privileges on tajy.* to kangsai@"%" identified by 'kangsai@123';  指定数据库权限

            GRANT REPLICATION SLAVE ON *.* TO 'slave账号'@'slave服务器ip';  //允许从库拉取日志

        6、刷新账号权限,重启mysql服务

             flush privileges;

        7、主库锁住,锁住日志无法新增

            flush tables with read lock;

        8、主库解除锁定

            unlock tables

        9、查看主库状态   锁住时记住File和Position

            show master status \G;

            333.png

            10、备份主库数据库导入从库

从库操作

    

            1、进入mysql配置文件 my.cnf或者my.ini

            2、设置服务id

                server-id = 99

            3、设置同步的库

                    replicate-do-db=tajy //同步的库

                    replicate-do-table=base.user  //同步的表

                   slave-skip-errors=all        //跳过所有同步错误

            4、数据库重启

            5、配置主从   mysql -u root -p密码  登录数据库

            CHANGE MASTER TO

            MASTER_HOST='10.102.184.98',//主数据库ip

            MASTER_USER='slave99',          //主数据库账号

            MASTER_PASSWORD='slave99',//密码

            MASTER_LOG_FILE='mysql-bin.000001',//从哪个日志开始同步  主库操作步骤9的File

            MASTER_LOG_POS=1; //从日志的某个节点开始同步   主库步骤9 的Position

            

            6、开启主从同步  进入mysql运行

                start slave;  //开启主从

            7、  查看主从状态  这两个值Yes,主从配置成功

                show slave status\G;

                555.png

            8、停止主从

                stop slave;

            9、存在同步错误 停止主从后,跳过错误事务

                set global sql_slave_skip_counter = 1;

            

            以下都在my.cnf

            主库同步到从库 数据库关系

                replicate-rewrite-db=tajy_qianzhi->tajy_qianzhi

                replicate-rewrite-db=tajy->taiedu  //主从数据库名称不一致,重新指向

            

            同步数据库所有表

                replicate-wild-do-table=tajy_qianzhi.%

            

            单独设置同步的表

                replicate-do-table=taiedu.base_class

                replicate-do-table=taiedu.base_class_teacher

                replicate-do-table=taiedu.base_grade

                replicate-do-table=taiedu.base_grade_director

                replicate-do-table=taiedu.base_role

                replicate-do-table=taiedu.base_student

                replicate-do-table=taiedu.base_tenant

                replicate-do-table=taiedu.base_user







Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post