创建全局的唯一自增主键

 
在mycat节点通过本地的3306端口 登陆mysql数据库
[root@Master-111 conf]# mysql -uroot -p -P3306 -h127.0.0.1
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26-log 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| imooc_db           |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.27 sec)
 
mysql> create database mycat;
Query OK, 1 row affe  cted (0.14 sec)
 
mysql> use mycat;
Database changed
 
mysql>source  /usr/local/mycat/conf/dbseq.sql
 
mysql> show tables;
+-----------------+
| Tables_in_mycat |
+-----------------+
| mycat_sequence  |
+-----------------+
1 row in set (0.05 sec)
#查看目前数据
mysql> select * from mycat_sequence;
+--------+---------------+-----------+
| name   | current_value | increment |
+--------+---------------+-----------+
| GLOBAL |             1 |         1 |
+--------+---------------+-----------+
 
修改配置文件 server.xml
[root@Master-111 conf]# cat server.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- - - Licensed 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. -->
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
<system>
   <property name="serverPort">8066</property>
   <property name="managerPort">9066</property>
   <property name="nonePasswordLogin">0</property>
   <property name="bindIp">0.0.0.0</property>
   <property name="frontWritQueueSize">2048</property>
   <property name="charset">utf-8</property>
   <property name="txIsolation">2</property>
   <property name="processors">8</property>
   <property name="idleTimeout">18000000</property>
   <property name="sqlExecuteTimeout">300</property>
   <property name="useSqlstat">0</property>
   <property name="useGlobleTableCheck">0</property>
   <property name="sequnceHandlerType">2</property>   ###此处的值有5种:0 本地文件的方式生成id,1 数据库的方式  2时间戳的方式  3 zookeeper的方式生成id 4,故修改此值为1
   <property name="defaultmaxLimit">100</property>
   <property name="maxPacketSize">104857600</property>
</system>
   <user name="app_imooc" defaultAccount="true">
   <property name="usingDecrypt">1</property>
   <property name="password">bDbWr7bVMgszTe82oMo8NaUsmFFdPCNl/lYXzOYoG8anTpQLvdx5e+LYJEmT0IAeSVp1loyxSZPyv1GoHbHFHg==</property>
   <property name="schemas">imooc_db</property>
  </user>
</mycat:server>
 
修改schema.xml配置文件,增加mycat服务所在的节点
 
 
#修改sequence_db_conf.properties配置文件
[root@Master-111 conf]# vi sequence_db_conf.properties
#sequence stored in datanode
GLOBAL=mycat服务所在的主机节点
order_master=mycat
 
order_master:要使用全局唯一id的表
mycat:mycat服务所在区的节点
 
mysql> insert into mycat_sequence values('order_master',1,1);
Query OK, 1 row affected (0.15 sec)
 
 
修改schema.xml 增加一个主机节点
                           增加一个数据节点
 
修改schema.xml 启用 sequencehadertype 数值 为 2
修改 sequence_db_conf.peroperty 增加 需要启用自增id的表   数据节点
表mycat_sequence 添加一条数据
修改chema.xml 添加属性autoIncrement=“true”
 
 
创建时间:2021-09-26 17:16
浏览量:0