ShardingSphere-Proxy数据库代理入门使用_shardingsphere proxy(1)

3.1 数据分片SQL

如下sql是对t_order的分片,一共分为两片分别是t_order_0 、t_order_1

`CREATE DATABASE /*!32312 IF NOT EXISTS*/db_0 /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */;`
`USE db_0;``DROP TABLE IF EXISTS t_order_0;``CREATE TABLE t_order_0 (` `oid VARCHAR(100) COLLATE utf8_bin NOT NULL COMMENT '订单号(主键)',` `money DOUBLE DEFAULT NULL COMMENT '支付金额',` `status INT(11) DEFAULT NULL COMMENT '状态0,未支付1,已支付',` `user_id VARCHAR(100) COLLATE utf8_bin,` `PRIMARY KEY (oid)``) ENGINE=INNODB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;`
`DROP TABLE IF EXISTS t_order_1;``CREATE TABLE t_order_1 (` `oid VARCHAR(100) COLLATE utf8_bin NOT NULL COMMENT '订单号(主键)',` `money DOUBLE DEFAULT NULL COMMENT '支付金额',` `status INT(11) DEFAULT NULL COMMENT '状态0,未支付1,已支付',` `user_id VARCHAR(100) COLLATE utf8_bin,` `PRIMARY KEY (oid)``) ENGINE=INNODB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;`

3.2 Sharding-Proxy安装

前提条件:使用二进制发布包启动 Proxy,需要环境具备 Java JRE 8 或更高版本。

下载连接:https://archive.apache.org/dist/shardingsphere/4.1.1/

安装很简单,只需要解压即可。

3.3 Sharding-Proxy配置

解压安装完毕后,需要进行一些基本配置,配置信息如下:

3.3.1 服务配置

配置文件:conf/server.yaml

主要配置proxy的账户和权限

`# Licensed to the Apache Software Foundation (ASF) under one or more``# contributor license agreements. See the NOTICE file distributed with``# this work for additional information regarding copyright ownership.``# The ASF licenses this file to You under the Apache License, Version 2.0``# (the "License"); you may not use this file except in compliance with``# the License. You may obtain a copy of the License at``#``# http://www.apache.org/licenses/LICENSE-2.0``#``# Unless required by applicable law or agreed to in writing, software``# distributed under the License is distributed on an "AS IS" BASIS,``# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.``# See the License for the specific language governing permissions and``# limitations under the License.``#`
`######################################################################################################``#` `# If you want to configure orchestration, authorization and proxy properties, please refer to this file.``#` `######################################################################################################``#``#orchestration:``# orchestration_ds:``# orchestrationType: registry_center,config_center,distributed_lock_manager``# instanceType: zookeeper``# serverLists: localhost:2181``# namespace: orchestration``# props:``# overwrite: false``# retryIntervalMilliseconds: 500``# timeToLiveSeconds: 60``# maxRetries: 3``# operationTimeoutMilliseconds: 500``#``authentication:` `users:` `root:` `password: 123` `sharding:` `password: sharding`  `authorizedSchemas: sharding_db``#``props:` `max.connections.size.per.query: 1` `acceptor.size: 16 # The default value is available processors count * 2.` `executor.size: 16 # Infinite by default.` `proxy.frontend.flush.threshold: 128 # The default value is 128.``# # LOCAL: Proxy will run with LOCAL transaction.``# # XA: Proxy will run with XA transaction.``# # BASE: Proxy will run with B.A.S.E transaction.` `proxy.transaction.type: LOCAL` `proxy.opentracing.enabled: false` `proxy.hint.enabled: false` `query.with.cipher.column: true` `sql.show: false` `allow.range.query.with.inline.sharding: false`
3.3.2 分片配置

配置文件:conf/conf-*.yaml

主要配置分片信息,与sharding-jdbc的配置规则一模一样

`#``# If you want to connect to MySQL, you should manually copy MySQL driver to lib directory.``#``schemaName: sharding_db`
`dataSources:` `ds_0:` `url: jdbc:mysql://127.0.0.1:3306/db_0?serverTimezone=UTC&useSSL=false` `username: root` `password: 123456` `connectionTimeoutMilliseconds: 30000` `idleTimeoutMilliseconds: 60000` `maxLifetimeMilliseconds: 1800000` `maxPoolSize: 50``shardingRule:` `tables:` `t_order:` `actualDataNodes: ds_0.t_order_${0..1}` `tableStrategy:` `inline:` `shardingColumn: oid` `algorithmExpression: t_order_${oid % 2}` `defaultDatabaseStrategy:` `inline:` `shardingColumn: user_id` `algorithmExpression: ds_${user_id % 2}` `defaultTableStrategy:` `none:`

3.4 启动

启动脚本如下所示:

`bin/start.bat`

3.5 DBA运维测试

连接proxy mysql -P3307 -uroot -p123

图片

3.6 应用测试

业务开发只需要连接proxy数据库,因为proxy已经屏蔽了分片的底层逻辑。数据源配置文件如下:

还有兄弟不知道网络安全面试可以提前刷题吗?费时一周整理的160+网络安全面试题,金九银十,做网络安全面试里的显眼包!

王岚嵚工程师面试题(附答案),只能帮兄弟们到这儿了!如果你能答对70%,找一个安全工作,问题不大。

对于有1-3年工作经验,想要跳槽的朋友来说,也是很好的温习资料!

【完整版领取方式在文末!!】

93道网络安全面试题

内容实在太多,不一一截图了

黑客学习资源推荐

最后给大家分享一份全套的网络安全学习资料,给那些想学习 网络安全的小伙伴们一点帮助!

对于从来没有接触过网络安全的同学,我们帮你准备了详细的学习成长路线图。可以说是最科学最系统的学习路线,大家跟着这个大的方向学习准没问题。

😝朋友们如果有需要的话,可以联系领取~

1️⃣零基础入门
① 学习路线

对于从来没有接触过网络安全的同学,我们帮你准备了详细的学习成长路线图。可以说是最科学最系统的学习路线,大家跟着这个大的方向学习准没问题。

image

② 路线对应学习视频

同时每个成长路线对应的板块都有配套的视频提供:

image-20231025112050764

2️⃣视频配套工具&国内外网安书籍、文档
① 工具

② 视频

image1

③ 书籍

image2

资源较为敏感,未展示全面,需要的最下面获取

在这里插入图片描述在这里插入图片描述

② 简历模板

在这里插入图片描述

因篇幅有限,资料较为敏感仅展示部分资料,添加上方即可获取👆

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化资料的朋友,可以点击这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 22
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值