MySql连接字符串
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySql连接字符串相关的知识,希望对你有一定的参考价值。
参考技术A The port 3306 is the default mysql port.The value is ignored if Unix socket is used.
Use this to connect to a server in a replicated server configuration without concern on which server to use.
Use SSL if the server supports it, but allow connection in all cases
This option is available from Connector/NET version 6.2.1
Always use SSL. Deny connection if server does not support SSL.
This option is available from Connector/NET version 6.2.1
This option is available from Connector/NET version 6.2.1
This option is available from Connector/NET version 6.2.1
This option is available from Connector/NET version 6.2.1
This option is available from Connector/NET version 5.2.2
Returns a MySqlDateTime object for invalid values and a System.DateTime object for valid values
Returns System.DateTime.MinValue valued System.DateTime object for invalid values and a System.DateTime object for valid values.
The use of auto enlist transactionscope (default behaviour) could cause trouble in medium trust environments.
Default behaviour is that parameters for stored routines (stored procedures) are checked against the server
Some permissions and value casting related errors reported fixed when using this connection option.
The default behaviour is to read tables mysql.proc/INFORMATION_SCHEMA.ROUTINES and try to map provided command parameter values to the called procedures parameters and type cast values accordingly.
This can be troublesome if permissions to the (aforementioned) sproc info tables are insufficient.
The driver will not automatically map the parameters so you must manually set parameter types and you must also make sure to add the parameters to the command object in the exact order as appeared in the procedure definition.
This option is available from Connector/NET version 5.0.4
Specifying DefaultTableCacheAge is optional, default value is 60 seconds.
This option is available from Connector/NET version 6.4
This option is available from Connector/NET version 5.2.6
From version 6.2 idle connections are removed from the pool, freeing resources on the client (sockets) and the server (sockets and threads). Do not manually keep (global) connections and open close. Keep connection object creation and disposal as tight as possible, this might be counterintuitive but pooling mechanisms will take care of caching well and your code will be cleaner.
This is the default behaviour.
Default values are 0 and 100.
Makes an additional round trip to the server when obtaining a connection from the pool and connection state will be reset.
This is useful in load balancing scenarios when available servers change you don't want 100 constant connections in the pool pointing to only one server.
Specified in seconds, the amount of time after connection object creation the connection will be destroyed. Destruction will only happen when connections are returned to pool.
A connection might be long lived in the pool, however the connections server settings are updated (SHOW VARIABLES command) each time returned to the pool. This makes the client use of the connection object up to date with the correct server settings. However this causes a round trip and to optimize pooling performance this behaviour can be turned off.
This option is available from Connector/NET version 6.3
This option is available from Connector/NET version 6.4.4
The Windows Native Authentication Plugin must be installed for this to work.
Number of seconds between each keep-alive package send.
This option is available from Connector/NET version 6.1.1
The default is 25, meaning that stored procedure meta data (such as input/output data types etc) for the latest 25 called procedures will be cached in client memory.
This option is available from Connector/NET version 5.0.2
This enables Visual Studio wizards that bracket symbols with [] to work with Connector/Net. This option incurs a performance hit, so should only be used if necessary.
This option is available from Connector/NET version 6.3.1
Use this one to specify a default command timeout for the connection. Please note that the property in the connection string does not supercede the individual command timeout property on an individual command object.
This option is available from Connector/NET version 5.1.4.
Use this one to specify the length in seconds to wait for a server connection before terminating the attempt and receive an error.
Use this one to instruct the provider to ignore any command prepare statements and prevent corruption issues with server side prepared statements.
The option was added in Connector/NET version 5.0.3 and Connector/NET version 1.0.9.
Use this one to specify which network protocol to use for the connection.
"socket" is the default value used if the key isn't specified. Value "tcp" is an equivalent for "socket".
Use "pipe" to use a named pipes connection, "unix" for a Unix socket connection and "memory" to use MySQL shared memory.
It's possible to explicit set the shared memory object name used for communication.
It's possible to explicit set the pipe name used for communication, if not set, 'mysql' is the default value.
It is the port value of -1 that tells the driver to use named pipes network protocol. This is available on Windows only. The value is ignored if Unix socket is used.
It's possible to explicit set the shared memory object name used for communication.
Use this one to specify which character set to use to encode queries sent to the server.
Note! Use lower case value utf8 and not upper case UTF8 as this will fail.
Note that resultsets still are returned in the character set of the data returned.
具有多个连接参数的 MySQL 连接字符串?
【中文标题】具有多个连接参数的 MySQL 连接字符串?【英文标题】:Connection string for MySQL with multiple connection parameters? 【发布时间】:2016-11-29 17:43:36 【问题描述】:参考这个question,我正在尝试使用以下连接参数构建连接字符串以连接到 MySQL 数据库,但我无法正确处理。
我已经提到了帖子所指的documentation,但即使按照说明进行操作,我也无法解决。有人可以在这方面帮助我吗?
正在使用的连接参数:
useOldAliasMetadataBehavior=true
useUnicode=true
characterEncoding=UTF-8
普通连接字符串:jdbc:mysql://localhost:3307/databaseName
加上这些连接参数及其对应的值,连接字符串会是怎样的呢?
【问题讨论】:
我工作的用例,添加或删除连接参数 - 因此我必须根据需要更改连接字符串! 【参考方案1】:根据reference documentation,应该是:
jdbc:mysql://localhost:3307/databaseName?useOldAliasMetadataBehavior=true&unicode=true&characterEncoding=UTF-8
但是,标准端口是 3306 而不是您问题中的 3307。
【讨论】:
你有一个正确的观点!而我安装了两个版本的 MySQL,因此为这些使用了 2 个端口! 只是觉得值得一提。 感谢@Arthur Noseda 提供的信息,您的评论肯定对其他人有所帮助!干杯!【参考方案2】:只要拼接url之类的参数,例如:
jdbc:MySql://localhost:3307/databaseName?characterEncoding=UTF-8&useUnicode=true&useOldAliasMetadataBehavior=true
如果您的连接字符串保存在 XML 或属性文档中,您需要将 &
编码为 &
,如下所示:
jdbc:MySql://localhost:3307/databaseName?characterEncoding=UTF-8&useUnicode=true&useOldAliasMetadataBehavior=true
【讨论】:
您需要对此进行编码 如果 连接字符串被保存在 XML 文档中。不然。问题中没有关于 XML 的内容。 另外jdbc:MySql:
不是MySQL驱动的前缀,即jdbc:mysql:
@MarkRotteveel jdbc:mysql: 可以写成大写。没关系
@EJP 是的,你是对的。但在我的工作中,我始终坚持这样做,即使连接字符串没有保存在 XML 或属性文档中,这仍然没有错。以上是关于MySql连接字符串的主要内容,如果未能解决你的问题,请参考以下文章