以下是使用jdbc操作TiDB数据库,得到的交互过程和指令的说明
==>代表发送给数据库的指令
// 加载驱动程序
Class.forName(driver); // 连接数据库
Connection conn = DriverManager.getConnection(url, user, password);
==>(cmd=mysql.ComQuery)/* mysql-connector-java-6.0.6 ( Revision: 3dab84f4d9bede3cdd14d57b99e9e98a02a5b97d ) */
SELECT @@session.auto_increment_increment AS auto_increment_increment, @@character_set_client AS character_set_client,
@@character_set_connection AS character_set_connection, @@character_set_results AS character_set_results,
@@character_set_server AS character_set_server, @@init_connect AS init_connect, @@interactive_timeout AS interactive_timeout,
@@license AS license, @@lower_case_table_names AS lower_case_table_names, @@max_allowed_packet AS max_allowed_packet,
@@net_buffer_length AS net_buffer_length, @@net_write_timeout AS net_write_timeout, @@query_cache_size AS query_cache_size,
@@query_cache_type AS query_cache_type, @@sql_mode AS sql_mode, @@system_time_zone AS system_time_zone,
@@time_zone AS time_zone, @@tx_isolation AS tx_isolation, @@wait_timeout AS wait_timeout ==>(cmd=mysql.ComQuery)SET NAMES utf8
==>(cmd=mysql.ComQuery)SET character_set_results = NULL
==>(cmd=mysql.ComQuery)SET autocommit=1 // 关闭自动提交
conn.setAutoCommit(false);
==>(cmd=mysql.ComQuery)SET autocommit=0 // 创建statement用来执行SQL语句
Statement stmt = conn.createStatement(); // 要执行的SQL语句
ResultSet rs1 = stmt.executeQuery("select * from nation");
==>(cmd=mysql.ComQuery)select * from nation ResultSet rs2 = stmt.executeQuery("select * from region");
==>(cmd=mysql.ComQuery)select * from region // 提交
conn.commit();
==>(cmd=mysql.ComQuery)commit // 关闭连接
rs1.close();
rs2.close();
stmt.close();
conn.close();
==>(cmd=mysql.ComQuery)rollback
==>(cmd=mysql.ComQuit))
在jdbc建立连接时,会获取服务器的参数,以下是TiDB2.0.0与mysql5.7的对比
可以看到基本上差异不大,有部分参数与数据库服务器设置有关。
[TiDB2.0.0]
auto_increment_increment=
character_set_client=utf8
character_set_connection=utf8
character_set_results=latin1
character_set_server=latin1
init_connect=
interactive_timeout=
license=Apache License 2.0
lower_case_table_names=
max_allowed_packet=
net_buffer_length=
net_write_timeout=
query_cache_size=
query_cache_type=OFF
sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
system_time_zone=CST
time_zone=SYSTEM
tx_isolation=REPEATABLE-READ
wait_timeout=
[Mysql5.7]
auto_increment_increment=
character_set_client=utf8
character_set_connection=utf8
character_set_results=null
character_set_server=utf8
init_connect=SET NAMES utf8
interactive_timeout=
license=GPL
lower_case_table_names=
max_allowed_packet=
net_buffer_length=
net_write_timeout=
query_cache_size=
query_cache_type=OFF
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
system_time_zone=CST
time_zone=SYSTEM
tx_isolation=REPEATABLE-READ
wait_timeout=