H2資料庫與p6spy框架

2021-10-12 19:51:20 字數 3874 閱讀 6984

h2 database engine

what is sqlite?

p6sy configuration and usage

# datasource config

spring:

datasource:

driver-class-name: org.h2.driver

schema: classpath:db/schema-h2.sql

data: classpath:db/data-h2.sql

url: jdbc:h2:mem:test

username: root

password: test

com.h2database

h2runtime

p6spy

p6spy

3.8.5

ch.qos.logback

logback-classic

1.2.3

# datasource config

spring:

datasource:

driver-class-name: com.p6spy.engine.spy.p6spydriver

schema: classpath:db/schema-h2.sql

data: classpath:db/data-h2.sql

url: jdbc:p6spy:h2:file:d:/mybatisplus;trace_level_file=0

username: root

password: test

h2:console:

enabled: true

path: /console

spring:

datasource:

driver-class-name: com.p6spy.engine.spy.p6spydriver

type: com.zaxxer.hikari.hikaridatasource

url: jdbc:p6spy:mysql:

username: root

password: 123456

log4j2.xml 放在resources目錄下

<?xml version="1.0" encoding="utf-8"?>

status

="info"

monitorinterval

="30"

>

>

name

="console"

target

="system_out"

>

level

="all"

onmatch

="accept"

o****match

="deny"

/>

pattern

="%d %-5level %class %l %m - %msg%xex%n"

/>

console

>

name

="alllog"

filename

="$/all.log"

>

level

="all"

onmatch

="accept"

o****match

="deny"

/>

charset

="utf-8"

pattern

="%d %-5level %class %l %m - %msg%xex%n"

/>

file

>

name

="debuglog"

filename

="$/debug.log"

filepattern

="$/debug-%i.log"

>

level

="debug"

onmatch

="accept"

o****match

="deny"

/>

charset

="utf-8"

pattern

="[%-5level][%d][%f:%l] - %m%n"

/>

size

="3kb"

/>

max=

"10"

/>

rollingfile

>

name

="errorlog"

filename

="$/error.log"

filepattern

="$/error-%d.log"

>

level

="error"

onmatch

="accept"

o****match

="deny"

/>

charset

="utf-8"

pattern

="[%-5level][%d][%c:%f:%l] - %m%n"

/>

/>

rollingfile

>

name

="rollingfile"

filename

="$/rar.log"

filepattern

="$/$$/$-%d-%i.log.gz"

>

charset

="utf-8"

pattern

="%d %-5level %class %l %m - %msg%xex%n"

/>

>

/>

size

="10 mb"

/>

policies

>

rollingfile

>

>

>

level

="debug"

>

ref=

"console"

/>

root

>

loggers

>

configuration

>

resources 下的log4j.properties

log4j.logger.p6spy=info,spyconsole

#####-----%m%n

resources下的spy.properties

module.log=com.p6spy.engine.logging.p6logfactory,com.p6spy.engine.outage.p6outagefactory

#logmessageformat=自定義格式化類

# 使用日誌系統記錄sql

## 配置記錄log例外

excludecategories=info,debug,result,batc,resultset

# 設定使用p6spy driver來做**

deregisterdrivers=true

# 日期格式

dateformat=yyyy-mm-dd hh:mm:ss

# 實際驅動

driverlist=com.mysql.cj.jdbc.driver

# 是否開啟慢sql記錄

outagedetection=true

# 慢sql記錄標準 秒

outagedetectioninterval=2

p6spy監控springboot資料庫操控

1.替換jdbc driver 為 com.p6spy.engine.spy.p6spydriver 2.修改jdbc url 為 jdbc p6spy 3.修改spy.properties module.log com.p6spy.engine.logging.p6logfactory,com.p...

配置h2資料庫

1.新增依賴 com.h2database h21.4.178 2.修改資料庫配置的properties檔案,主要是jdbc.drivername和jdbc.url jdbc.drivername org.h2.driver jdbc.url jdbc h2 mem demo mode mysql ...

H2資料庫的應用

h2是乙個j a編寫的關係型資料庫,它可以被嵌入j a應用程式中使用,或者作為乙個單獨的資料庫伺服器執行。在啟動安裝程式前面,確保pc上已經存在jdk,安裝過程中配置預設就行,當然也可以自己選擇安裝路徑。我這裡選擇安裝到e盤,安裝後h2的目錄如下 在bin目錄下有乙個h2 2.1.210.jar的包...