博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mycat垂直分库
阅读量:5971 次
发布时间:2019-06-19

本文共 5497 字,大约阅读时间需要 18 分钟。

mycat垂直分库

数据库的主从复制

  1. MySQL备份源数据库并记录事务点
# master导出单个库的备份SET GLOBAL log_timestamps = SYSTEM;(/usr/local/mysql/bin/mysqldump -uroot -p123456 -hlocalhost -P3306 --socket=/usr/local/mysql/mysql.sock --single-transaction --master-data=2  imooc_db --triggers --routines --events > /tmp/all.sql
  1. 源数据库中建立从库(复制用户)
grant replication slave on *.* to 'repl'@'%' identified by '123456';
  1. 在新的数据库实例上恢复数据库,并修改数据库名称。
mysql -uroot -p123456 -e"create database order_db";mysql -uroot -p123456 order_db < /tmp/all.sqlmysql -uroot -p123456 -e"create database product_db";mysql -uroot -p123456 product_db < /tmp/all.sqlmysql -uroot -p123456 -e"create database customer_db";mysql -uroot -p123456 customer_db < /tmp/all.sql######################################ERROR 1840 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is emptyQuery OK, 0 rows affected (0.01 sec)root@localhost 23:55:  [(none)]> show master status;+---------------+----------+--------------+------------------+-------------------+| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |+---------------+----------+--------------+------------------+-------------------+| binlog.000001 |      154 |              |                  |                   |+---------------+----------+--------------+------------------+-------------------+1 row in set (0.00 sec)root@localhost 23:55:  [(none)]> show master status;+---------------+----------+--------------+------------------+-------------------------------------------+| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                         |+---------------+----------+--------------+------------------+-------------------------------------------+| binlog.000001 |      154 |              |                  | ad083f85-9264-11e8-9e91-005056a3fe0a:1-85 |+---------------+----------+--------------+------------------+-------------------------------------------+1 row in set (0.00 sec)
  1. 在新实例数据库上配置复制链路
\help change master toCHANGE MASTER TO  MASTER_HOST='172.16.10.141',  MASTER_USER='repl',  MASTER_PASSWORD='123456',  MASTER_PORT=3306,  master_auto_position=1;\help change replication filterCHANGE REPLICATION FILTER  REPLICATE_REWRITE_DB = ((imooc_db, order_db));CHANGE REPLICATION FILTER  REPLICATE_REWRITE_DB = ((imooc_db, product_db));CHANGE REPLICATION FILTER  REPLICATE_REWRITE_DB = ((imooc_db, customer_db));start slave;# 主库插入数据验证root@localhost 00:12:  [imooc_db]> insert into region_info(parent_id,region_name,region_level) values(1,'guangdong',2);# 从库查看数据root@localhost 00:13:  [order_db]> select * from region_info;+-----------+-----------+-------------+--------------+| region_id | parent_id | region_name | region_level |+-----------+-----------+-------------+--------------+|         1 |         1 | guangdong   |            2 |+-----------+-----------+-------------+--------------+1 row in set (0.00 sec)# 其他2个也这么同步

配置mycat垂直分库

  1. 配置schema.xml,需要的权限
grant select,insert,update,delete on *.* to 'bm_mycat'@'%' identified by '123456';
  1. 配置schema.xml,数据库分库实现
show slave status
show slave status
show slave status

验证通过mycat访问db

使用命令行访问方式[root@mycat01 logs]# mysql -uapp_imooc -p123456 -P8066Warning: Using a password on the command line interface can be insecure.ERROR 1045 (28000): Access denied for user 'app_imooc'@'localhost' (using password: YES)[root@mycat01 logs]# mysql -uapp_imooc -p123456 -P8066 -h172.16.10.142Warning: Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.5.8-mycat-1.5.1-RELEASE-20160525110043 MyCat Server (OpenCloundDB)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.app_imooc@172.16.10.142 01:59:  [(none)]> show databases;+----------+| DATABASE |+----------+| imooc_db |+----------+1 row in set (0.00 sec)app_imooc@172.16.10.142 01:59:  [(none)]> use imooc_db;Database changedapp_imooc@172.16.10.142 01:59:  [imooc_db]> show tables;+-----------------------+| Tables in imooc_db    |+-----------------------+| customer_balance_log  || customer_inf          || customer_level_inf    || customer_login        || customer_login_log    || customer_point_log    || order_cart            || order_customer_addr   || order_detail          || order_master          || product_brand_info    || product_category      || product_comment       || product_info          || product_pic_info      || product_supplier_info || region_info           || serial                || shipping_info         || warehouse_info        || warehouse_proudct     |+-----------------------+21 rows in set (0.01 sec)app_imooc@172.16.10.142 01:59:  [imooc_db]>
使用程序访问方式:与java访问MySQL数据库方式一模一样,应用程序不需要做任何更改。只需要改变数据库链接地址,及用户口令即可。

转载地址:http://hizox.baihongyu.com/

你可能感兴趣的文章
通过jsp请求Servlet来操作HBASE
查看>>
Shell编程基础
查看>>
Shell之Sed常用用法
查看>>
Centos下基于Hadoop安装Spark(分布式)
查看>>
mysql开启binlog
查看>>
设置Eclipse编码方式
查看>>
分布式系统唯一ID生成方案汇总【转】
查看>>
并查集hdu1232
查看>>
Mysql 监视工具
查看>>
Linux Namespace系列(09):利用Namespace创建一个简单可用的容器
查看>>
博客搬家了
查看>>
Python中使用ElementTree解析xml
查看>>
jquery 操作iframe、frameset
查看>>
解决vim中不能使用小键盘
查看>>
Eclipse Java @Override 报错
查看>>
linux的日志服务器关于屏蔽一些关键字的方法
查看>>
mysql多实例实例化数据库
查看>>
javascript 操作DOM元素样式
查看>>
HBase 笔记3
查看>>
【Linux】Linux 在线安装yum
查看>>