0637236809c7214e9198adaba3cb28fca31afc9b
\346\225\260\346\215\256\345\272\223\351\205\215\347\275\256\350\214\203\344\276\213\346\261\207\346\200\273.md
| ... | ... | @@ -0,0 +1,233 @@ |
| 1 | +# 数据库配置范例 |
|
| 2 | + |
|
| 3 | +## 一 MySQL 配置范例 |
|
| 4 | + |
|
| 5 | +#### 数据库配置(文件dbcp.properties)如下 |
|
| 6 | + |
|
| 7 | + |
|
| 8 | + ``` |
|
| 9 | + ########DBCP########## |
|
| 10 | + driverClassName=com.mysql.cj.jdbc.Driver |
|
| 11 | + #url |
|
| 12 | + url=jdbc:mysql://ip:3306/iidp?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true |
|
| 13 | + username=root |
|
| 14 | + password=123456 |
|
| 15 | + initialSize=5 |
|
| 16 | + maxActive=30 |
|
| 17 | + minIdle=5 |
|
| 18 | + maxWait=6000 |
|
| 19 | + filters=stat |
|
| 20 | + timeBetweenEvictionRunsMillis=60000 |
|
| 21 | + minEvictableIdleTimeMillis=300000 |
|
| 22 | + validationQuery=select 'x' |
|
| 23 | + testOnBorrow=false |
|
| 24 | + testOnReturn=false |
|
| 25 | + testWhileIdle=true |
|
| 26 | + poolPreparedStatements: true |
|
| 27 | + maxOpenPreparedStatements: 20 |
|
| 28 | + |
|
| 29 | + ``` |
|
| 30 | + |
|
| 31 | +## 二 Oracle 配置范例 |
|
| 32 | + |
|
| 33 | +#### 数据库配置(文件dbcp.properties)如下 |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + ``` |
|
| 37 | + ########Oracle######## |
|
| 38 | + driverClassName=oracle.jdbc.OracleDriver |
|
| 39 | + url=jdbc:oracle:thin:@ip:1521:SMOMDB |
|
| 40 | + username=root |
|
| 41 | + password=123456 |
|
| 42 | + validationQuery=SELECT 'x' FROM DUAL |
|
| 43 | + |
|
| 44 | + initialSize=5 |
|
| 45 | + maxActive=30 |
|
| 46 | + minIdle=5 |
|
| 47 | + maxWait=6000 |
|
| 48 | + filters=stat |
|
| 49 | + timeBetweenEvictionRunsMillis=60000 |
|
| 50 | + minEvictableIdleTimeMillis=300000 |
|
| 51 | + validationQuery=select 'x' |
|
| 52 | + testOnBorrow=false |
|
| 53 | + testOnReturn=false |
|
| 54 | + testWhileIdle=true |
|
| 55 | + poolPreparedStatements: true |
|
| 56 | + maxOpenPreparedStatements: 20 |
|
| 57 | + |
|
| 58 | + ``` |
|
| 59 | + |
|
| 60 | + |
|
| 61 | +## 三 PostgreSQL 配置范例 |
|
| 62 | + |
|
| 63 | +1. **DBCP 配置** |
|
| 64 | + |
|
| 65 | + ```properties |
|
| 66 | + ########postgresql######## |
|
| 67 | + driverClassName=org.postgresql.Driver |
|
| 68 | + url=jdbc:postgresql://xxx.xxx.120:5432/postgres?currentSchema=public&encoding=UTF-8&timezone=UTC |
|
| 69 | + username=postgres |
|
| 70 | + password=****** |
|
| 71 | + |
|
| 72 | + initialSize=5 |
|
| 73 | + maxActive=30 |
|
| 74 | + minIdle=5 |
|
| 75 | + maxWait=6000 |
|
| 76 | + filters=stat |
|
| 77 | + timeBetweenEvictionRunsMillis=60000 |
|
| 78 | + minEvictableIdleTimeMillis=300000 |
|
| 79 | + validationQuery=select 'x' |
|
| 80 | + testOnBorrow=false |
|
| 81 | + testOnReturn=false |
|
| 82 | + testWhileIdle=true |
|
| 83 | + poolPreparedStatements: true |
|
| 84 | + maxOpenPreparedStatements: 20 |
|
| 85 | + ``` |
|
| 86 | + |
|
| 87 | +## 四 OceanBase 配置范例 |
|
| 88 | + |
|
| 89 | +### 1. JDBC 连接配置调整 |
|
| 90 | + |
|
| 91 | +**JDBC 连接示例**: |
|
| 92 | + |
|
| 93 | +```plaintext |
|
| 94 | +driverClassName=com.mysql.cj.jdbc.Driver |
|
| 95 | +url=jdbc:oceanbase://xxx.xxx.xxx.xxx:3306/test?rewriteBatchedStatements=TRUE&allowMultiQueries=TRUE&useLocalSessionState=TRUE&useUnicode=TRUE&characterEncoding=utf-8&socketTimeout=10000&connectTimeout=30000 |
|
| 96 | +username=root |
|
| 97 | +password=****** |
|
| 98 | +``` |
|
| 99 | + |
|
| 100 | +- **allowMultiQueries**:默认为 `FALSE`,必须设置为 `TRUE`,以允许使用分号连接的多语句文本格式。对使用文本协议的场景,只需开启此配置即可实现批量优化。 |
|
| 101 | +- **rewriteBatchedStatements**:默认为 `FALSE`,若使用 PS 协议,则必须设置为 `TRUE`,以在执行 `executeBatch()` 时将多条语句改写为分号连接的多语句格式。 |
|
| 102 | + |
|
| 103 | +**特例说明**:开启 `rewriteBatchedStatements` 后,对于多条 multi queries 插入语句(无论使用文本协议或 PS 协议),JDBC 驱动会将其改写为一条 Multi Values Insert 语句。 |
|
| 104 | + |
|
| 105 | +**相关参数说明**: |
|
| 106 | + |
|
| 107 | +- `rewriteBatchedStatements`:建议设置为 `TRUE`,以提高批量插入的性能。 |
|
| 108 | +- `allowMultiQueries`:建议设置为 `TRUE`,允许使用分号连接的多语句文本格式。 |
|
| 109 | +- `useLocalSessionState`:建议设置为 `TRUE`,避免频繁向 OB 数据库发送 session 变量查询 SQL。 |
|
| 110 | +- `socketTimeout`:执行 SQL 时,socket 等待 SQL 返回的时间。 |
|
| 111 | +- `connectTimeout`:建立连接时,等待连接的时间。 |
|
| 112 | +- `useCursorFetch`:建议设置为 `TRUE`,适用于大数据量查询。 |
|
| 113 | +- `useServerPrepStms`:控制是否使用 PS 协议发送 SQL。 |
|
| 114 | +- `cachePrepStmts`:控制是否开启 PS cache,避免重复执行 prepare。 |
|
| 115 | +- `prepStmtCacheSQLLimit`:可放入 PS cache 的 SQL 长度限制。 |
|
| 116 | +- `prepStmtCacheSize`:PS cache 可保存的 SQL 数量。 |
|
| 117 | +- `maxBatchTotalParamsNum`:针对 batch 操作,一条 SQL 最多支持的参数个数。 |
|
| 118 | + |
|
| 119 | + |
|
| 120 | +### 2. 本地 JDBC连接 OceanBase |
|
| 121 | +dbcp.properties添加oceanbase配置 |
|
| 122 | + |
|
| 123 | +```shell |
|
| 124 | +########OceanBase######## |
|
| 125 | +driverClassName=com.mysql.cj.jdbc.Driver |
|
| 126 | +url=jdbc:mysql://xxx.xxx.xxx.xxx:2881/snest?rewriteBatchedStatements=TRUE&allowMultiQueries=TRUE&useLocalSessionState=TRUE&useUnicode=TRUE&characterEncoding=utf-8&socketTimeout=10000&connectTimeout=30000&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true |
|
| 127 | +username=root |
|
| 128 | +password=****** |
|
| 129 | +validationQuery=SELECT 1 |
|
| 130 | +``` |
|
| 131 | + |
|
| 132 | +## 五 GaussDB 配置范例 |
|
| 133 | + |
|
| 134 | +**JDBC配置:** |
|
| 135 | + |
|
| 136 | +**1. dbcp.properties 示例:** |
|
| 137 | + |
|
| 138 | +``` |
|
| 139 | +########DBCP########## |
|
| 140 | +initialSize=5 |
|
| 141 | +maxActive=2000 |
|
| 142 | +minIdle=5 |
|
| 143 | +filters=stat |
|
| 144 | +maxWait=6000 |
|
| 145 | +timeBetweenEvictionRunsMillis=60000 |
|
| 146 | +minEvictableIdleTimeMillis=1800000 |
|
| 147 | +testOnBorrow=false |
|
| 148 | +testOnReturn=false |
|
| 149 | +testWhileIdle=true |
|
| 150 | +poolPreparedStatements: true |
|
| 151 | +maxOpenPreparedStatements: 20 |
|
| 152 | +connectionProperties:druid.stat.sql.MaxSize=100; |
|
| 153 | +keepAlive=true |
|
| 154 | + |
|
| 155 | + |
|
| 156 | +########gaussdb######## |
|
| 157 | +driverClassName=com.huawei.gaussdb.jdbc.Driver |
|
| 158 | +url=jdbc:gaussdb://127.0.0.1:8000,127.0.0.1:8000,127.0.0.1:8000/tpcc?currentSchema=snest_jichen&autoBalance=true&refreshCNIpListTime=3&prepareThreshold=1&batchMode=on&fetchsize=10&loggerLevel=OFF |
|
| 159 | +username=****** |
|
| 160 | +password=****** |
|
| 161 | +validationQuery=SELECT 1 |
|
| 162 | +gaussdbDeployment=Distributed |
|
| 163 | +``` |
|
| 164 | + |
|
| 165 | +**2. spring配置文件添加参数适配高斯自定义SQL列字段别名转换** |
|
| 166 | + |
|
| 167 | +正常不需要添加这个配置,除非项目特殊需要. |
|
| 168 | + |
|
| 169 | +application-dev.properties添加: |
|
| 170 | + |
|
| 171 | +``` |
|
| 172 | +orm.sql.wrap_camelcase_alias=true |
|
| 173 | +``` |
|
| 174 | + |
|
| 175 | + |
|
| 176 | +## 六 Vastbase(海量数据库) 配置范例 |
|
| 177 | + |
|
| 178 | + |
|
| 179 | +Vastbase 海量数据库基本上兼容Postgres SQL,所以SQL语法和Postgres一样,可以直接把Vastbase作为Postgres使用. |
|
| 180 | + |
|
| 181 | + |
|
| 182 | +**JDBC配置:** |
|
| 183 | + |
|
| 184 | +### 1 默认兼容模型 |
|
| 185 | + |
|
| 186 | +``` |
|
| 187 | +vastbase数据库访问 |
|
| 188 | + |
|
| 189 | +########DBCP########## |
|
| 190 | +driverClassName=cn.com.vastbase.Driver |
|
| 191 | +url=jdbc:vastbase://ip:25432/snest?currentSchema=snest_changwen |
|
| 192 | +username=root |
|
| 193 | +password=****** |
|
| 194 | + |
|
| 195 | + |
|
| 196 | +########snest_DBCP########## |
|
| 197 | +driverClassName=org.postgresql.Driver/cn.com.vastbase.Driver |
|
| 198 | +url=jdbc:vastbase://ip:25432/snest?currentSchema=snest_ziyang |
|
| 199 | +username=root |
|
| 200 | +password=****** |
|
| 201 | +``` |
|
| 202 | + |
|
| 203 | +### 2 MySQL兼容模型 |
|
| 204 | + |
|
| 205 | +``` |
|
| 206 | +vastbase数据库访问 |
|
| 207 | +数据库:snest_tpcc 端口:25434 用户名:snest_changwen |
|
| 208 | + |
|
| 209 | +########DBCP########## |
|
| 210 | +driverClassName=cn.com.vastbase.Driver |
|
| 211 | +url=jdbc:vastbase://ip:25434/snest_tpcc?currentSchema=snest_changwen&db_compatibility=mysql |
|
| 212 | +username=root |
|
| 213 | +password=****** |
|
| 214 | +dbCompatibility=mysql |
|
| 215 | + |
|
| 216 | + |
|
| 217 | +``` |
|
| 218 | + |
|
| 219 | + |
|
| 220 | +## 七 Dameng(国产达梦数据库) 配置范例 |
|
| 221 | + |
|
| 222 | + |
|
| 223 | +配置数据库连接信息 |
|
| 224 | +在 dbcp.properties 配置连接信息如下: |
|
| 225 | + |
|
| 226 | +``` |
|
| 227 | +########dameng########## |
|
| 228 | +driverClassName=dm.jdbc.driver.DmDriver |
|
| 229 | +url=jdbc:dm://ip:30236/IIDP_DEMO |
|
| 230 | +username=SYSDBA |
|
| 231 | +password=SYSDBA001 |
|
| 232 | +``` |
|
| 233 | + |