前言
上文分析了【从入门到放弃-MySQL】数据库连接过程分析。本文我们一起来追一下客户端和服务端建联的过程。
这里客户端使用JDBC8.0,在SpringBoot2.1.3下验证。
请求流程
初始化
SpringBoot2.1.3默认使用的HickriCP连接池
应用启动时,会先注册spring.datasource.driver-class-name配置的驱动,这里我们使用com.mysql.cj.jdbc.Driver
启动后,我们直接通过一个查询操作的http请求来验证一次查询操作中,客户端与服务端连接的过程
首次请求
当使用到Dao请求时,开始建立连接
调用堆栈如下:
checkErrorMessage:752, NativeProtocol (com.mysql.cj.protocol.a)
checkErrorMessage:741, NativeProtocol (com.mysql.cj.protocol.a)
checkErrorMessage:709, NativeProtocol (com.mysql.cj.protocol.a)
checkErrorMessage:132, NativeProtocol (com.mysql.cj.protocol.a)
proceedHandshakeWithPluggableAuthentication:540, NativeAuthenticationProvider (com.mysql.cj.protocol.a)
connect:202, NativeAuthenticationProvider (com.mysql.cj.protocol.a)
connect:1449, NativeProtocol (com.mysql.cj.protocol.a)
connect:165, NativeSession (com.mysql.cj)
connectOneTryOnly:955, ConnectionImpl (com.mysql.cj.jdbc)
createNewIO:825, ConnectionImpl (com.mysql.cj.jdbc)
:455, ConnectionImpl (com.mysql.cj.jdbc)
getInstance:240, ConnectionImpl (com.mysql.cj.jdbc)
connect:199, NonRegisteringDriver (com.mysql.cj.jdbc)
getConnection:136, DriverDataSource (com.zaxxer.hikari.util)
newConnection:369, PoolBase (com.zaxxer.hikari.pool)
newPoolEntry:198, PoolBase (com.zaxxer.hikari.pool)
createPoolEntry:467, HikariPool (com.zaxxer.hikari.pool)
checkFailFast:541, HikariPool (com.zaxxer.hikari.pool)
:115, HikariPool (com.zaxxer.hikari.pool)
getConnection:112, HikariDataSource (com.zaxxer.hikari)
fetchConnection:157, DataSourceUtils (org.springframework.jdbc.datasource)
doGetConnection:115, DataSourceUtils (org.springframework.jdbc.datasource)
getConnection:78, DataSourceUtils (org.springframework.jdbc.datasource)
openConnection:82, SpringManagedTransaction (org.mybatis.spring.transaction)
getConnection:68, SpringManagedTransaction (org.mybatis.spring.transaction)
getConnection:336, BaseExecutor (org.apache.ibatis.executor)
prepareStatement:85, SimpleExecutor (org.apache.ibatis.executor)
doQuery:62, SimpleExecutor (org.apache.ibatis.executor)
queryFromDatabase:324, BaseExecutor (org.apache.ibatis.executor)
query:156, BaseExecutor (org.apache.ibatis.executor)
query:109, CachingExecutor (org.apache.ibatis.executor)
query:83, CachingExecutor (org.apache.ibatis.executor)
selectList:148, DefaultSqlSession (org.apache.ibatis.session.defaults)
selectList:141, DefaultSqlSession (org.apache.ibatis.session.defaults)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:62, NativeMethodAccessorImpl (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
invoke:433, SqlSessionTemplate$SqlSessionInterceptor (org.mybatis.spring)
selectList:-1, $Proxy59 (com.sun.proxy)
selectList:230, SqlSessionTemplate (org.mybatis.spring)
executeForMany:144, MapperMethod (org.apache.ibatis.binding)
execute:77, MapperMethod (org.apache.ibatis.binding)
invoke:58, MapperProxy (org.apache.ibatis.binding)
selectByCondition:-1, $Proxy60 (com.sun.proxy)