Heim > Datenbank > MySQL-Tutorial > MySQL连接字符串中的几个重要步骤

MySQL连接字符串中的几个重要步骤

WBOY
Freigeben: 2016-06-07 16:14:21
Original
1401 Leute haben es durchsucht

上一篇文章我们对MySQL连接字符串的实际操作经验与实际操作技巧有一个详细的介绍,此篇文章主要是对MySQL连接字符串的实际操作步骤(在实际操作中具有重要地位)的介绍,望你会有所收获。 MySQL连接字符串:MySQL Connector/Net (.NET)连接方式 1、标准连接(

上一篇文章我们对MySQL连接字符串的实际操作经验与实际操作技巧有一个详细的介绍,此篇文章主要是对MySQL连接字符串的实际操作步骤(在实际操作中具有重要地位)的介绍,望你会有所收获。

MySQL连接字符串:MySQL Connector/Net (.NET)连接方式

1、标准连接(说明,默认端口是3306。)

<ol class="dp-xml"><li class="alt"><span><span class="attribute">Server</span><span>=</span><span class="attribute-value">myServerAddress</span><span>;</span><span class="attribute">Database</span><span>=</span><span class="attribute-value">myDataBase</span><span>;</span><span class="attribute">Uid</span><span>=</span><span class="attribute-value">myUsername</span><span>;</span><span class="attribute">Pwd</span><span>=</span><span class="attribute-value">myPassword</span><span>; </span></span></li></ol>
Nach dem Login kopieren

2、特殊的TCP/IP端口连接

<ol class="dp-xml"><li class="alt"><span><span class="attribute">Server</span><span>=</span><span class="attribute-value">myServerAddress</span><span>;</span><span class="attribute">Port</span><span>=</span><span class="attribute-value">1234</span><span>;</span><span class="attribute">Database</span><span>=</span><span class="attribute-value">myDataBase</span><span>;</span><span class="attribute">Uid</span><span>=</span><span class="attribute-value">myUsername</span><span>;</span><span class="attribute">Pwd</span><span>=</span><span class="attribute-value">myPassword</span><span>; </span></span></li></ol>
Nach dem Login kopieren

3、命名管道

说明:端口值为-1,说明用命名管道方式连接。此方式只在Windows下有效,在UNIX下用会被忽略。

<ol class="dp-xml"><li class="alt"><span><span class="attribute">Server</span><span>=</span><span class="attribute-value">myServerAddress</span><span>;</span><span class="attribute">Port</span><span>=-1;</span><span class="attribute">Database</span><span>=</span><span class="attribute-value">myDataBase</span><span>;</span><span class="attribute">Uid</span><span>=</span><span class="attribute-value">myUsername</span><span>;</span><span class="attribute">Pwd</span><span>=</span><span class="attribute-value">myPassword</span><span>; </span></span></li></ol>
Nach dem Login kopieren
Nach dem Login kopieren

4、多服务器连接

用此种方式连接到数据库中,不必担心该使用哪个数据库。

<ol class="dp-xml"><li class="alt"><span><span class="attribute">Server</span><span>=</span><span class="attribute-value">serverAddress1</span><span> & serverAddress2 & etc..;</span><span class="attribute">Database</span><span>=</span><span class="attribute-value">myDataBase</span><span>;</span><span class="attribute">Uid</span><span>=</span><span class="attribute-value">myUsername</span><span>;</span><span class="attribute">Pwd</span><span>=</span><span class="attribute-value">myPassword</span><span>;</span></span></li></ol>
Nach dem Login kopieren

5、加密选项

这条活动的SSL连接加密所有客户端和服务器商的数据传输。而且服务器要有一个证书。

这个选项从Connector/NET5.0.3版开始出现,以前的版本中则没有此功能。

<ol class="dp-xml"><li class="alt"><span><span class="attribute">Server</span><span>=</span><span class="attribute-value">myServerAddress</span><span>;</span><span class="attribute">Port</span><span>=-1;</span><span class="attribute">Database</span><span>=</span><span class="attribute-value">myDataBase</span><span>;</span><span class="attribute">Uid</span><span>=</span><span class="attribute-value">myUsername</span><span>;</span><span class="attribute">Pwd</span><span>=</span><span class="attribute-value">myPassword</span><span>; </span></span></li></ol>
Nach dem Login kopieren
Nach dem Login kopieren

6、修改默认的命令超时时间

使用这条修改连接的默认命令超时时间。注意:此条不会影响你在单独命令对象上设置的超时时间。

此条只对Connector/NET 5.1.4 及以上的版本有效.

<ol class="dp-xml"><li class="alt"><span><span class="attribute">Server</span><span>=</span><span class="attribute-value">myServerAddress</span><span>;</span><span class="attribute">Database</span><span>=</span><span class="attribute-value">myDataBase</span><span>;</span><span class="attribute">Uid</span><span>=</span><span class="attribute-value">myUsername</span><span>;</span><span class="attribute">Pwd</span><span>=</span><span class="attribute-value">myPassword</span><span>;default command </span><span class="attribute">timeout</span><span>=</span><span class="attribute-value">20</span><span>; </span></span></li></ol>
Nach dem Login kopieren

7、修改连接偿试时间

使用这条修改在终止重试和接收错误的等待时间(以秒为单位)

<ol class="dp-xml"><li class="alt"><span><span class="attribute">Server</span><span>=</span><span class="attribute-value">myServerAddress</span><span>;</span><span class="attribute">Database</span><span>=</span><span class="attribute-value">myDataBase</span><span>;</span><span class="attribute">Uid</span><span>=</span><span class="attribute-value">myUsername</span><span>;</span><span class="attribute">Pwd</span><span>=</span><span class="attribute-value">myPassword</span><span>;Connection </span><span class="attribute">Timeout</span><span>=</span><span class="attribute-value">5</span><span>; </span></span></li></ol>
Nach dem Login kopieren

8、Inactivating prepared statements

Use this one to instruct the provider to ignore any command prepare statements and prevent corruption issues with server side prepared statements.

此选项被加入到Connector/NET的5.0.3版和1.0.9版。

<ol class="dp-xml"><li class="alt"><span><span class="attribute">Server</span><span>=</span><span class="attribute-value">myServerAddress</span><span>;</span><span class="attribute">Database</span><span>=</span><span class="attribute-value">myDataBase</span><span>;</span><span class="attribute">Uid</span><span>=</span><span class="attribute-value">myUsername</span><span>;</span><span class="attribute">Pwd</span><span>=</span><span class="attribute-value">myPassword</span><span>;Ignore </span><span class="attribute">Prepare</span><span>=</span><span class="attribute-value">true</span><span>;</span></span></li></ol>
Nach dem Login kopieren

9、特殊的TCP/IP端口连接

这条语句修改连接的端口。

默认端口是3306。此参数会被Unix忽略。

<ol class="dp-xml"><li class="alt"><span><span class="attribute">Server</span><span>=</span><span class="attribute-value">myServerAddress</span><span>;</span><span class="attribute">Database</span><span>=</span><span class="attribute-value">myDataBase</span><span>;</span><span class="attribute">Uid</span><span>=</span><span class="attribute-value">myUsername</span><span>;</span><span class="attribute">Pwd</span><span>=</span><span class="attribute-value">myPassword</span><span>;</span><span class="attribute">Port</span><span>=</span><span class="attribute-value">3306</span><span>; </span></span></li></ol>
Nach dem Login kopieren

10、特殊网络协议

这条语句修改用哪种协议进行连接。

如果没有特别说明,"socket"是默认的值。"tcp"是与"socket"相同意义的。"pipe"是使用命名管道连接,"unix"是使用 unix socket连接,"memory"是使用MySQL的共享内存。

<ol class="dp-xml"><li class="alt"><span><span class="attribute">Server</span><span>=</span><span class="attribute-value">myServerAddress</span><span>;</span><span class="attribute">Database</span><span>=</span><span class="attribute-value">myDataBase</span><span>;</span><span class="attribute">Uid</span><span>=</span><span class="attribute-value">myUsername</span><span>;</span><span class="attribute">Pwd</span><span>=</span><span class="attribute-value">myPassword</span><span>;</span><span class="attribute">Protocol</span><span>=</span><span class="attribute-value">socket</span><span>;</span></span></li></ol>
Nach dem Login kopieren

11、特殊字符集的连接

这个语句指出以使种字符串编码发送到服务器上的查询语句。

注意:查询结果仍然是以反回数据的格式传送。

<ol class="dp-xml"><li class="alt"><span><span class="attribute">Server</span><span>=</span><span class="attribute-value">myServerAddress</span><span>;</span><span class="attribute">Database</span><span>=</span><span class="attribute-value">myDataBase</span><span>;</span><span class="attribute">Uid</span><span>=</span><span class="attribute-value">myUsername</span><span>;</span><span class="attribute">Pwd</span><span>=</span><span class="attribute-value">myPassword</span><span>;</span><span class="attribute">CharSet</span><span>=</span><span class="attribute-value">UTF8</span><span>; </span></span></li></ol>
Nach dem Login kopieren

12、修改共享内存名

此语句用来修改用来通信的共享内存名称。

说明:此语句只有当连接协议设置为"memory"时才有效。

<ol class="dp-xml"><li class="alt"><span><span class="attribute">Server</span><span>=</span><span class="attribute-value">myServerAddress</span><span>;</span><span class="attribute">Database</span><span>=</span><span class="attribute-value">myDataBase</span><span>;</span><span class="attribute">Uid</span><span>=</span><span class="attribute-value">myUsername</span><span>;</span><span class="attribute">Pwd</span><span>=</span><span class="attribute-value">myPassword</span><span>;Shared Memory </span><span class="attribute">Name</span><span>=</span><span class="attribute-value">MySQL</span><span>; </span></span></li></ol>
Nach dem Login kopieren

MySQL连接字符串:MySQLConnection (.NET)连接方式

1、eInfoDesigns.dbProvider

<ol class="dp-xml"><li class="alt"><span><span>Data </span><span class="attribute">Source</span><span>=</span><span class="attribute-value">myServerAddress</span><span>;</span><span class="attribute">Database</span><span>=</span><span class="attribute-value">myDataBase</span><span>;<br>User </span><span class="attribute">ID</span><span>=</span><span class="attribute-value">myUsername</span><span>;</span><span class="attribute">Password</span><span>=</span><span class="attribute-value">myPassword</span><span>;Command </span><span class="attribute">Logging</span><span>=</span><span class="attribute-value">false</span><span>; </span></span></li></ol>
Nach dem Login kopieren

SevenObjects MySQLClient (.NET)连接方式

1、标准连接

<ol class="dp-xml"><li class="alt"><span><span class="attribute">Host</span><span>=</span><span class="attribute-value">myServerAddress</span><span>;</span><span class="attribute">UserName</span><span>=</span><span class="attribute-value">myUsername</span><span>;</span><span class="attribute">Password</span><span>=</span><span class="attribute-value">myPassword</span><span>;</span><span class="attribute">Database</span><span>=</span><span class="attribute-value">myDataBase</span><span>; </span></span></li></ol>
Nach dem Login kopieren

Core Labs MySQLDirect (.NET)连接方式

1、标准连接

<ol class="dp-xml"><li class="alt"><span><span>User </span><span class="attribute">ID</span><span>=</span><span class="attribute-value">root</span><span>;</span><span class="attribute">Password</span><span>=</span><span class="attribute-value">myPassword</span><span>;</span><span class="attribute">Host</span><span>=</span><span class="attribute-value">localhost</span><span>;</span><span class="attribute">Port</span><span>=</span><span class="attribute-value">3306</span><span>;<br></span><span class="attribute">Database</span><span>=</span><span class="attribute-value">myDataBase</span><span>; </span><span class="attribute">Direct</span><span>=</span><span class="attribute-value">true</span><span>;</span><span class="attribute">Protocol</span><span>=</span><span class="attribute-value">TCP</span><span>;</span><span class="attribute">Compress</span><span>=</span><span class="attribute-value">false</span><span>;<br></span><span class="attribute">Pooling</span><span>=</span><span class="attribute-value">true</span><span>;Min Pool </span><span class="attribute">Size</span><span>=</span><span class="attribute-value">0</span><span>;Max Pool </span><span class="attribute">Size</span><span>=</span><span class="attribute-value">100</span><span>;Connection </span><span class="attribute">Lifetime</span><span>=</span><span class="attribute-value">0</span><span>; </span></span></li></ol>
Nach dem Login kopieren

MySQL连接字符串:MySQLDriverCS (.NET)连接方式

1、标准连接

<ol class="dp-xml"><li class="alt"><span><span class="attribute">Location</span><span>=</span><span class="attribute-value">myServerAddress</span><span>;Data </span><span class="attribute">Source</span><span>=</span><span class="attribute-value">myDataBase</span><span>;User </span><span class="attribute">ID</span><span>=</span><span class="attribute-value">myUsername</span><span>;<br></span><span class="attribute">Password</span><span>=</span><span class="attribute-value">myPassword</span><span>;</span><span class="attribute">Port</span><span>=</span><span class="attribute-value">3306</span><span>;Extended </span><span class="attribute">Properties</span><span>=</span><span class="attribute-value">""</span><span>""; </span></span></li></ol>
Nach dem Login kopieren

以上的相关内容就是对MySQL连接字符串的介绍,望你能有所收获。


Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage