seata server数据存储可以配置为文件,也可以配置为数据库存储,为了方便查看事务信息,配置为数据库存储更合适。
生产环境如果需要部署集群方式,也需要配置为数据库存储。
seata server程序启动的时候报错如下:
java.sql.SQLException: Could not retrieve transation read-only status server
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998) ~[na:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:937) ~[na:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926) ~[na:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:872) ~[na:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:904) ~[na:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:894) ~[na:na]
at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3613) ~[na:na]
at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3582) ~[na:na]
at com.alibaba.druid.pool.DruidConnectionHolder.<init>(DruidConnectionHolder.java:140) ~[druid-1.1.23.jar:1.1.23]
at com.alibaba.druid.pool.DruidConnectionHolder.<init>(DruidConnectionHolder.java:79) ~[druid-1.1.23.jar:1.1.23]
at com.alibaba.druid.pool.DruidDataSource.put(DruidDataSource.java:2471) ~[druid-1.1.23.jar:1.1.23]
at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2816) [druid-1.1.23.jar:1.1.23]
Caused by: java.sql.SQLException: Unknown system variable 'tx_read_only'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998) ~[na:na]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3835) ~[na:na]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3771) ~[na:na]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435) ~[na:na]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582) ~[na:na]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2531) ~[na:na]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2489) ~[na:na]
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1446) ~[na:na]
at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3607) ~[na:na]
... 5 common frames omitted
<==
mysql是8.0的,驱动类需要com.mysql.cj.jdbc.Driver,而不是com.mysql.jdbc.Driver。
Caused by: java.sql.SQLException: The server time zone value '?й??????' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
在数据库连接中增加时区配置
jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&rewriteBatchedStatements=true
的后面增加&serverTimezone=GMT
jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&rewriteBatchedStatements=true&serverTimezone=GMT
开启全局事务时,在数据库中存储的全局事务信息:
开启分支事务时,在数据库存储的分支事务信息:
事务执行结束,不管是事务提交,还是事务回滚,这些信息都会被删除。