JDBC driver types are used to categorize the technology used to connect to the database.
- Type -1 Bridge driver
- Type -2 Native API
- Type -3 Network Protocol
- Type -4 Native Protocol
Type-4 driver is also called native protocol driver. This driver interacts directly with the database. It does not require any native database library, that is why it is also known as Thin Driver.
- Does not require any native library and Middleware server, so no client-side or server-side installation.
- It is fully written in Java language, hence they are portable drivers.
在找 mysql 的 jdbc 驱动程序时,看见 type4 字样,于是就有了这篇文章
type 1 - 4 是 sun 定义的 4 种 jdbc 标准
type1 jdbc-odbc
桥接的方式进行连接, 主要是为了兼容微软阵营的 odbc, 于 jdk1.1+ 加入, 是 sun.jdbc.odbc 包的一部分
连接形式:
application--->jdbc-odbc bridge(type1 jdbc driver)---->jdbc-odbc library--->odbc driver-->database
ps: 应用程序通过 JDBC – ODBC 桥接的形式对数据库进行连接的一种驱动类型, 适用于快速的原型系统, 没有提供jdbc驱动的数据库 (如 Access)
type2 java to native api
利用开发商提供的本地库来与数据库连接
application--->jdbc driver(type2 jdbc driver)---->native database library---->database
也就是常说的直连,只比 type1 性能略好
type3 java to net
application--->jdbc driver(type3 jdbc driver)----->java middleware--->jdbc driver---->database
通过网络的形式, 类似于 rpc, 通常由非数据库厂商提供, 具有很大的灵活性
type4 java to native dababase
application--->jdbc driver(type4 jdbc driver)----->database engine--->database
也就是我们常用的 jdbc, 由数据库厂家提供, 性能最高, 通过厂家自己的本地协议直接与数据库引擎通信
mysql-connector-j
mysql-connector-java 迁移到 mysql-connector-j
- 官网解释
https://blogs.oracle.com/mysql/post/mysql-connectorj-has-new-maven-coordinates
- Why
为了让产品名称和 artifactId 名称匹配
MySQL Connector/J
mysql-connector-j
- Why now?
No reason at all. But why not? In fact there’s no publicly visible reason to do this change now. We had the chance to fine tuning some company-internal publishing processes and this was just in the way. The impact for users is not negligible but in the end we just want to do the right thing.
mysql dump commandline
mysqldump -uXXX -pYYY -h192.168.123.123 -P3306 origin_db --skip-lock-tables | mysql -uroot -h127.0.0.1 target_db
mysqldump --defaults-extra-file=./db_origin.conf origin_db --opt --compress --skip-lock-tables --verbose | mysql --defaults-extra-file=./db_target.conf target_db
# db_origin.conf
[client]
host = 192.168.1.50
user = root
password = '123456'
--defaults-extra-file=file_name
在启动中不仅仅会加载指定的配置文件,还会加载所有默认需要加载的配置文件
--defaults-file=file_name
在启动中只会加载指定的配置文件
--opt
等同于--add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, --disable-keys 该选项默认开启, 可以用--skip-opt禁用.
--lock-tables, -l
开始导出前,锁定所有表。用 READ LOCAL 锁定表以允许 MyISAM 表并行插入。对于支持事务的表例如InnoDB和BDB,--single-transaction是一个更好的选择,因为它根本不需要锁定表。请注意当导出多个数据库时,--lock-tables 分别为每个数据库锁定表。因此,该选项不能保证导出文件中的表在数据库之间的逻辑一致性。不同数据库表的导出状态可以完全不同。
--verbose, --v
输出多种平台信息
--complete-insert, -c
使用完整的insert语句(包含列名称)。这么做能提高插入效率,但是可能会受到max_allowed_packet 参数的影响而导致插入失败
e.g. mysqldump -uroot -p --all-databases --complete-insert
--compress, -C
在客户端和服务器之间启用压缩传递所有信息
jdbc:mysql:///database_name
等同于jdbc:mysql://localhost:3306/database_name
jdbc:mysql://127.0.0.1/database_name
等同于jdbc:mysql://127.0.0.1:3306/database_name