通过数据库文件安装Seata1.4.2和Nacos1.4.2
一、环境准备
1、MySQL:确保MySQL数据库已安装并运行。
2、Nacos:下载并启动Nacos服务,默认端口为8848。
3、Seata:下载Seata1.4.2版本,下载地址为https://github.com/seata/seata/releases。
二、创建数据库及表结构
在MySQL中创建所需的数据库和表结构:
CREATE DATABASE IF NOT EXISTS seata; USE seata; -GlobalSession数据表 CREATE TABLE IF NOT EXISTSglobal_table
(xid
VARCHAR(128) NOT NULL,transaction_id
BIGINT,status
TINYINT NOT NULL,application_id
VARCHAR(32),transaction_service_group
VARCHAR(32),transaction_name
VARCHAR(128),timeout
INT,begin_time
BIGINT,application_data
VARCHAR(2000),gmt_create
DATETIME,gmt_modified
DATETIME, PRIMARY KEY (xid
), KEYidx_gmt_modified_status
(gmt_modified
,status
), KEYidx_transaction_id
(transaction_id
) ) ENGINE = InnoDB DEFAULT CHARSET = utf8; -BranchSession数据表 CREATE TABLE IF NOT EXISTSbranch_table
(branch_id
BIGINT NOT NULL,xid
VARCHAR(128) NOT NULL,transaction_id
BIGINT,resource_group_id
VARCHAR(32),resource_id
VARCHAR(256),branch_type
VARCHAR(8),status
TINYINT,client_id
VARCHAR(64),application_data
VARCHAR(2000),gmt_create
DATETIME(6),gmt_modified
DATETIME(6), PRIMARY KEY (branch_id
), KEYidx_xid
(xid
) ) ENGINE = InnoDB DEFAULT CHARSET = utf8; -Lock数据表 CREATE TABLE IF NOT EXISTSlock_table
(row_key
VARCHAR(128) NOT NULL,xid
VARCHAR(128),transaction_id
BIGINT,branch_id
BIGINT NOT NULL,resource_id
VARCHAR(256),table_name
VARCHAR(32),pk
VARCHAR(36),gmt_create
DATETIME,gmt_modified
DATETIME, PRIMARY KEY (row_key
), KEYidx_branch_id
(branch_id
) ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
三、配置Seata服务端
1、修改file.conf:
registry { type = "nacos" nacos { serverAddr = "127.0.0.1:8848" namespace = "" group = "SEATA_GROUP" username = "" password = "" dataId = "seataServer.properties" } }
2、修改registry.conf:
registry { type = "nacos" nacos { serverAddr = "127.0.0.1:8848" namespace = "" group = "SEATA_GROUP" username = "" password = "" dataId = "seata-server.txt" } }
3、下载config.txt和nacos-config.sh文件:
config.txt下载地址:https://github.com/seata/seata/blob/1.4.0/script/config-center/config.txt
nacos-config.sh下载地址:https://github.com/seata/seata/blob/1.4.0/script/config-center/nacos/nacos-config.sh
4、执行nacos-config.sh脚本导入配置:
sh nacos-config.sh -h localhost -p 8848 -g SEATA_GROUP -t adb63345-4bbf-4db3-9e1c-12df6146e52b -u nacos -w nacos
四、启动Seata服务端
1、启动Nacos服务:确保Nacos服务正常运行。
2、启动Seata服务:在Seata安装目录下执行以下命令启动Seata服务:
sh seata-server.sh /path/to/conf/file.conf
五、项目配置
1、引入Seata依赖:在项目的pom.xml文件中添加Seata依赖。
<dependency> <groupId>io.seata</groupId> <artifactId>seata-spring-boot-starter</artifactId> <version>1.4.2</version> </dependency>
2、配置application.yml或application.properties:在项目中添加Seata的配置信息。
spring: cloud: alibaba: seata: tx-service-group: my_test_tx_group # Seata事务分组名称,必须与Nacos中的分组一致 datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/yourDatabase?useUnicode=true&characterEncoding=utf-8&useSSL=false username: root password: yourPassword
以上就是关于“mysql 通过数据库文件_安装Seata1.4.2+Nacos1.4.2”的问题,朋友们可以点击主页了解更多内容,希望可以够帮助大家!
原创文章,作者:未希,如若转载,请注明出处:https://www.kdun.com/ask/1302780.html
本网站发布或转载的文章及图片均来自网络,其原创性以及文中表达的观点和判断不代表本网站。如有问题,请联系客服处理。
发表回复