广告
返回顶部
首页 > 资讯 > 数据库 >Mycat中间件如何实现Mysql数据分片
  • 270
分享到

Mycat中间件如何实现Mysql数据分片

2024-04-02 19:04:59 270人浏览 独家记忆
摘要

这篇文章主要介绍了Mycat中间件如何实现Mysql数据分片,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。架构图:机器规划:IP地址主机名角

这篇文章主要介绍了Mycat中间件如何实现Mysql数据分片,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

架构图:

Mycat中间件如何实现Mysql数据分片

机器规划:

IP地址主机名角色备注
10.4.132.50k8s01mycat,master
10.4.132.42k8s02master
10.4.132.66k8s03master

Mycat下载地址:Http://dl.mycat.io/1.6.7.3/20190828135747/Mycat-server-1.6.7.3-release-20190828135747-linux.tar.gz
mysql下载地址: http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz

1.下载安装Mysql(三台Mysql都需要安装)
[root@k8s01 soft]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
[root@k8s01 soft]# tar xvf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@k8s01 soft]# cd /usr/local/
[root@k8s01 local]# mv mysql-5.7.27-linux-glibc2.12-x86_64/ mysql-5.7.27
[root@k8s01 local]# chown -R root:root mysql-5.7.27/
[root@k8s01 local]# cd mysql-5.7.27/
[root@k8s01 mysql-5.7.27]# mkdir data
[root@k8s01 mysql-5.7.27]# useradd -r -M -s /bin/nologin mysql
[root@k8s01 mysql-5.7.27]# chown -R mysql:mysql data/
[root@k8s01 mysql-5.7.27]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7.27 --datadir=/usr/local/mysql-5.7.27/data
2019-11-02T04:24:41.908404Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-11-02T04:24:46.687678Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-11-02T04:24:47.428823Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-11-02T04:24:47.487404Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: b42cef88-fd28-11e9-a5cc-000c29ee86d5.
2019-11-02T04:24:47.488204Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-11-02T04:24:47.612739Z 1 [Note] A temporary passWord is generated for root@localhost: 3m;5yQ_7T#jc --登陆密码
[root@k8s01 mysql-5.7.27]# cp -a support-files/mysql.server /etc/init.d/mysqld
[root@k8s01 mysql-5.7.27]# chkconfig --add mysqld
[root@k8s01 mysql-5.7.27]# chkconfig mysqld on
[root@k8s01 mysql-5.7.27]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql-5.7.27
datadir=/usr/local/mysql-5.7.27/data
[root@k8s01 mysql-5.7.27]# vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql-5.7.27
datadir=/usr/local/mysql-5.7.27/data
Socket=/tmp/mysql.sock
symbolic-links=0
server_id=10
binlog_fORMat=ROW
max_binlog_size=2G
sync_binlog=1
binlog_cache_size=64M
log_bin=bin-log
log_bin_index=bin-index
[mysqld_safe]
log-error=/usr/local/mysql-5.7.27/data/mariadb.log
pid-file=/usr/local/mysql-5.7.27/data/mariadb.pid

[root@k8s01 mysql-5.7.27]# /etc/init.d/mysqld restart
ERROR! MySQL Server PID file could not be found!
Starting MySQL.Logging to '/usr/local/mysql-5.7.27/data/mariadb.log'.
... SUCCESS!
[root@k8s01 mysql-5.7.27]# vim /etc/profile
export PATH=$PATH:/usr/local/mysql-5.7.27/bin
[root@k8s01 mysql-5.7.27]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.27
Copyright (c) 2000, 2019, oracle and/or its affiliates. All rights reserved.
Oracle is a reGIStered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respectiveowners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set password=password('System135');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[root@k8s01 mysql-5.7.27]# mysql -u root -pSystem135
mysql: [Warning] 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 6
Server version: 5.7.27 MySQL CommUnity Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> grant all privileges on *.* to repl@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> 

2.下载安装Mycat
[root@k8s01 soft]# rpm -ivh jdk-8u221-linux-x64.rpm
warning: jdk-8u221-linux-x64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:jdk1.8-2000:1.8.0_221-fcs        ################################# [100%]
Unpacking jar files...
 tools.jar...
 plugin.jar...
 javaws.jar...
 deploy.jar...
 rt.jar...
 jsse.jar...
 charsets.jar...
 localedata.jar...
[root@k8s01 soft]# tar xvf Mycat-server-1.6.7.3-release-20190828135747-linux.tar.gz  -C /usr/local/
[root@k8s01 soft]# cd /usr/local/mycat/conf/
[root@k8s01 conf]# 

3.数据按范围分片
[root@k8s01 conf]# vim schema.xml

Mycat中间件如何实现Mysql数据分片

[root@k8s01 conf]# vim rule.xml       --其它不要动,只修改以下内容

Mycat中间件如何实现Mysql数据分片

[root@k8s01 conf]# vim autopartition-long.txt
# range start-end ,data node index
# K=1000,M=10000.          --K表示1千,M表示1万
0-5=0              --从0到5放到第一个节点
5-10=1            --从6到10放到第二个节点
10-15=2         --从11到15放到第三个节点        
[root@k8s01 conf]# vim server.xml      --Mycat登陆用户名和密码

Mycat中间件如何实现Mysql数据分片

[root@k8s01 conf]# ../bin/mycat restart
Stopping Mycat-server...
Stopped Mycat-server.
Starting Mycat-server...
[root@k8s01 conf]# netstat -antulp | grep 8066
tcp6       0      0 :::8066                 :::*                    LISTEN      46762/java         
[root@k8s01 conf]# netstat -antulp | grep 9066
tcp6       0      0 :::9066                 :::*                    LISTEN      46762/java                      
[root@k8s01 conf]#

4.验证数据分片后存放
[root@k8s01 conf]# /usr/local/mysql-5.7.27/bin/mysql -u root -pSystem135 -P8066 -h 127.0.0.1    --登陆Mycat数据数据

Mycat中间件如何实现Mysql数据分片

查询写入后的数据:

Mycat中间件如何实现Mysql数据分片

k8s01节点验证数据:

Mycat中间件如何实现Mysql数据分片

k8s02节点验证数据:

Mycat中间件如何实现Mysql数据分片

k8s03节点验证数据:

Mycat中间件如何实现Mysql数据分片

5.数据按日期(月份)分片
[root@k8s01 conf]# vim schema.xml

Mycat中间件如何实现Mysql数据分片[root@k8s01 conf]# vim rule.xmlMycat中间件如何实现Mysql数据分片

[root@k8s01 conf]# ../bin/mycat restart
Stopping Mycat-server...
Stopped Mycat-server.
Starting Mycat-server...
[root@k8s01 conf]# !net
netstat -antulp | grep 9066
tcp6       0      0 :::9066                 :::*                    LISTEN      69040/java          
[root@k8s01 conf]# netstat -antulp | grep 8066
tcp6       0      0 :::8066                 :::*                    LISTEN      69040/java         
[root@k8s01 conf]#
6.验证数据分片后存放

Mycat中间件如何实现Mysql数据分片

验证数据:

k8s01节点:

Mycat中间件如何实现Mysql数据分片

k8s02节点:

Mycat中间件如何实现Mysql数据分片

k8s03节点:

Mycat中间件如何实现Mysql数据分片

错误处理:
mysql> insert into t_wuhan(create_time,name,age) values("2015-04-01","huanggang",16);
ERROR 1064 (HY000): Can't find a valid data node for specified node index :T_WUHAN -> CREATE_TIME -> 2015-04-01 -> Index : 3
解决方法:
    写入4月份数据时会提示找不到节点,是因为有几个节点就会写入几月份数据,比如我只有3个node节点,只能写入1-3月份数据。
7.数据按枚举分片
[root@k8s01 conf]# vim schema.xmlMycat中间件如何实现Mysql数据分片[root@k8s01 conf]# vim rule.xml Mycat中间件如何实现Mysql数据分片

[root@k8s01 conf]# cat partition-hash-int.txt      --可以写多个枚举
学生=0
老师=1
DEFAULT_NODE=2
[root@k8s01 conf]#
8.验证数据分片后存放

Mycat中间件如何实现Mysql数据分片

验证数据:
k8s01节点:

Mycat中间件如何实现Mysql数据分片

k8s02节点:

Mycat中间件如何实现Mysql数据分片

k8s03节点:

Mycat中间件如何实现Mysql数据分片

错误处理:
mysql> insert into t_wuhan(id,name,age) values(1,"tong","学生");
ERROR 1064 (HY000): columnValue:学生 Please check if the format satisfied.
mysql> insert into t_wuhan(id,name,age) values(1,"tong",'学生');
ERROR 1064 (HY000): columnValue:学生 Please check if the format satisfied.
mysql>

解决方法:

Mycat中间件如何实现Mysql数据分片

type:type值默认为0,表示数值是整型。值为1,表示是字符串
defaultNode:值对应partition-hash-int.txt文件中的DEFAULT_NODE的值。

感谢你能够认真阅读完这篇文章,希望小编分享的“Mycat中间件如何实现Mysql数据分片”这篇文章对大家有帮助,同时也希望大家多多支持编程网,关注编程网数据库频道,更多相关知识等着你来学习!

您可能感兴趣的文档:

--结束END--

本文标题: Mycat中间件如何实现Mysql数据分片

本文链接: https://www.lsjlt.com/news/62180.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Mycat中间件如何实现Mysql数据分片
    这篇文章主要介绍了Mycat中间件如何实现Mysql数据分片,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。架构图:机器规划:IP地址主机名角...
    99+
    2022-10-18
  • Mycat中间件实现Mysql数据分片( 下篇)
    9.数据按节点(DataNode)分片 [root@k8s01 conf]# vim schema.xml [root@k8s01 conf]# vim rule.xml id:表示字段...
    99+
    2022-10-18
  • Mycat中间件实现Mysql主从读写分离
    环境规划: IP地址 主机名 角色 备注 10.4.132.50 k8s01 mycat,master 10.4.132.42 k8s02 slave ...
    99+
    2022-10-18
  • 数据库中间件MyCat的示例分析
    这篇文章主要为大家展示了“数据库中间件MyCat的示例分析”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“数据库中间件MyCat的示例分析”这篇文章吧。1、Myc...
    99+
    2022-10-18
  • 如何进行数据库中间件 MyCAT 源码分析
    这篇文章将为大家详细讲解有关如何进行数据库中间件 MyCAT 源码分析,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。1. 概述可能你在看到这个标题会小小的吃...
    99+
    2022-10-19
  • mysql中mycat 中间件如何使用
    本篇文章给大家分享的是有关mysql中mycat 中间件如何使用,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。一,什么是mycat一个彻底开源...
    99+
    2022-10-18
  • 如何利用mycat实现mysql数据库读写分离
    这篇文章主要介绍了如何利用mycat实现mysql数据库读写分离,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。什么是MyCAT一个彻底开源的...
    99+
    2022-10-18
  • Mycat中间件实现Percona Cluster集群读写分离
    Mycat实现读写分离架构图: Mycat主从自动切换架构图: Mycat下载地址:http://dl.mycat.io/1.6.7.3/20190828135747/Mycat-server...
    99+
    2022-10-18
  • 怎么用数据库中间件Mycat+SpringBoot完成分库分表
    这篇文章主要讲解了“怎么用数据库中间件Mycat+SpringBoot完成分库分表”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么用数据库中间件Mycat+SpringBoot完成分库分表...
    99+
    2023-06-16
  • mysql数据库中怎么利用mycat实现读写分离
    这期内容当中小编将会给大家带来有关mysql数据库中怎么利用mycat实现读写分离,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。1、部署mycat下载 [root@myc...
    99+
    2022-10-18
  • 数据库中间件 MyCAT 源码分析 —— 调试环境搭建
    关注**微信公众号:【芋艿的后端小屋】**有福利:RocketMQ / MyCAT / Sharding-JDBC 所有源码分析文章列表RocketMQ / MyCAT / Sharding-JD...
    99+
    2022-10-18
  • Mycat如何实现Mysql集群读写分离
    这篇文章给大家分享的是有关Mycat如何实现Mysql集群读写分离的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。MySQL 读写分离的概述MySQL 作为目前世界上使用最广泛的免...
    99+
    2022-10-19
  • mysql中如何快速搭建PXC集群以及Mycat分片
    mysql中如何快速搭建PXC集群以及Mycat分片,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。 搭建PXC集群参考percona...
    99+
    2022-10-18
  • 数据库中间件分片算法之hash
    前言 夜深人静的时候,打开云音乐,点上一曲攀登,带上真无线蓝牙耳机,瞬间燃到爆,键盘打字如飞倦意全无。 分片规则 这几天有人问我,dble和MyCat到底有什么不同。其实dble作为MyCAT的同门,吸收了MyCat的精华,同时也...
    99+
    2015-11-27
    数据库中间件分片算法之hash
  • 借助MyCat如何实现MySQL分库分表的方法
    这篇文章给大家分享的是有关借助MyCat如何实现MySQL分库分表的方法的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。❝借助MyCat来实现MySQL的分库分表落地,没有实现过的...
    99+
    2022-10-18
  • Docker搭建MySQL读写分离主从模式 & 分布式数据库中间件Mycat分库分表应用
    一、MySQL读写分离主从模式 1. 下载镜像 docker pull mysql 当前最新版本:mysql Ver 8.0.19 for Linux on x86_64 (MySQL Community Server - GPL) 2....
    99+
    2016-10-09
    Docker搭建MySQL读写分离主从模式 & 分布式数据库中间件Mycat分库分表应用
  • Redis数据分片如何实现
    今天小编给大家分享一下Redis数据分片如何实现的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。Twemproxy的介绍Twi...
    99+
    2023-06-27
  • MyCat如何实现MySQL双主一从读写分离
    这篇文章给大家分享的是有关MyCat如何实现MySQL双主一从读写分离的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。1)配置server.xml<user nam...
    99+
    2022-10-18
  • SpringBoot2如何整合Sharding-Jdbc中间件实现数据分库分表
    小编给大家分享一下SpringBoot2如何整合Sharding-Jdbc中间件实现数据分库分表,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!一、水平分割1、水平分库1)、概念:以字段为依据,按照一定策略,将一个库中的数据...
    99+
    2023-06-02
  • MySQL中间件proxysql实现MySQL读写分离
    1. Mysql实现读写分离的方式 mysql 实现读写分离的方式有以下几种: 程序修改mysql操作,直接和数据库通信,简单快捷的读写分离和随机的方式实现的负载均衡,权限独立分配,需要开发人员协助。 amoeba,直接实现读写分离和负载...
    99+
    2021-12-16
    MySQL中间件proxysql实现MySQL读写分离 数据库入门 数据库基础教程 数据库 mysql
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作