mysql JDBC URL格式各个参数详解
2016-05-25 15:14
369 查看
mysql JDBC URL格式如下:
jdbc:mysql://[host:port],[host:port].../[database][?参数名1][=参数值1][&参数名2][=参数值2]...
现只列举几个重要的参数,如下表所示:
对应中文环境,通常mysql连接URL可以设置为:
jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=gbk&autoReconnect=true&failOverReadOnly=false
在使用数据库连接池的情况下,最好设置如下两个参数:
autoReconnect=true&failOverReadOnly=false
需要注意的是,在xml配置文件中,url中的&符号需要转义成“&”。比如在tomcat的server.xml中配置数据库连接池时,mysql jdbc url样例如下:
jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=gbk
&autoReconnect=true&failOverReadOnly=false
其他参数请参见mysql jdbc官方文档: MySQL Connector/J Documentation
jdbc:mysql://[host:port],[host:port].../[database][?参数名1][=参数值1][&参数名2][=参数值2]...
现只列举几个重要的参数,如下表所示:
参数名称 | 参数说明 | 缺省值 | 最低版本要求 |
user | 数据库用户名(用于连接数据库) | 所有版本 | |
password | 用户密码(用于连接数据库) | 所有版本 | |
useUnicode | 是否使用Unicode字符集,如果参数characterEncoding设置为gb2312或gbk,本参数值必须设置为true | false | 1.1g |
characterEncoding | 当useUnicode设置为true时,指定字符编码。比如可设置为gb2312或gbk | false | 1.1g |
autoReconnect | 当数据库连接异常中断时,是否自动重新连接? | false | 1.1 |
autoReconnectForPools | 是否使用针对数据库连接池的重连策略 | false | 3.1.3 |
failOverReadOnly | 自动重连成功后,连接是否设置为只读? | true | 3.0.12 |
maxReconnects | autoReconnect设置为true时,重试连接的次数 | 3 | 1.1 |
initialTimeout | autoReconnect设置为true时,两次重连之间的时间间隔,单位:秒 | 2 | 1.1 |
connectTimeout | 和数据库服务器建立socket连接时的超时,单位:毫秒。 0表示永不超时,适用于JDK 1.4及更高版本 | 0 | 3.0.1 |
socketTimeout | socket操作(读写)超时,单位:毫秒。 0表示永不超时 | 0 | 3.0.1 |
jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=gbk&autoReconnect=true&failOverReadOnly=false
在使用数据库连接池的情况下,最好设置如下两个参数:
autoReconnect=true&failOverReadOnly=false
需要注意的是,在xml配置文件中,url中的&符号需要转义成“&”。比如在tomcat的server.xml中配置数据库连接池时,mysql jdbc url样例如下:
jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=gbk
&autoReconnect=true&failOverReadOnly=false
其他参数请参见mysql jdbc官方文档: MySQL Connector/J Documentation
相关文章推荐
- Mysql初始化root密码和允许远程访问
- MySQL登录问题
- MySQL 加锁处理分析
- MySQL开发规范和原则大全
- 毕业设计jsp+mysql留言板
- orczhou----MYSQL
- 阿里云服务器Ubuntu安装mysql
- MySQL无法存储Emoji表情问题
- MySQL中的事务
- 怎样使用Navicat for Mysql连接Ubuntu虚拟机上的mysql服务器
- MySQL 中间件(Atlas,cobar,TDDL)
- MySQL主从复制与读写分离
- mysql explain
- [转]Mysql命令
- MySQL服务器安装配置-非安装版、windows版
- 使用Navicat for Mysql连接Ubuntu虚拟机上的mysql服务器失败
- HAProxy
- NodeJs使用Mysql模块实现事务处理
- Navicat for Mysql连接mysql数据库时出现 2003-Can't connect to MySql server on 'localhost'(10061)
- mysql多实例实现以及主从同步