search
HomeDatabaseMysql TutorialMySQL连接字符串中的几个重要步骤
MySQL连接字符串中的几个重要步骤Jun 07, 2016 pm 04:14 PM
mysqlseveralstringarticlestepconnectimportant

上一篇文章我们对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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
图文详解mysql架构原理图文详解mysql架构原理May 17, 2022 pm 05:54 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于架构原理的相关内容,MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层,下面一起来看一下,希望对大家有帮助。

mysql怎么去掉第一个字符mysql怎么去掉第一个字符May 19, 2022 am 10:21 AM

方法:1、利用right函数,语法为“update 表名 set 指定字段 = right(指定字段, length(指定字段)-1)...”;2、利用substring函数,语法为“select substring(指定字段,2)..”。

mysql的msi与zip版本有什么区别mysql的msi与zip版本有什么区别May 16, 2022 pm 04:33 PM

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

mysql怎么替换换行符mysql怎么替换换行符Apr 18, 2022 pm 03:14 PM

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

mysql怎么将varchar转换为int类型mysql怎么将varchar转换为int类型May 12, 2022 pm 04:51 PM

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

MySQL复制技术之异步复制和半同步复制MySQL复制技术之异步复制和半同步复制Apr 25, 2022 pm 07:21 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

带你把MySQL索引吃透了带你把MySQL索引吃透了Apr 22, 2022 am 11:48 AM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

mysql怎么判断是否是数字类型mysql怎么判断是否是数字类型May 16, 2022 am 10:09 AM

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor