Home Database Mysql Tutorial MySQL连接字符串中的几个重要步骤

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

Jun 07, 2016 pm 04:14 PM
mysql several string article step connect important

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

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>
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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


Statement of this Website
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

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

Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

This Apple ID is not yet in use in the iTunes Store: Fix This Apple ID is not yet in use in the iTunes Store: Fix Jun 10, 2024 pm 05:42 PM

When logging into iTunesStore using AppleID, this error saying "This AppleID has not been used in iTunesStore" may be thrown on the screen. There are no error messages to worry about, you can fix them by following these solution sets. Fix 1 – Change Shipping Address The main reason why this prompt appears in iTunes Store is that you don’t have the correct address in your AppleID profile. Step 1 – First, open iPhone Settings on your iPhone. Step 2 – AppleID should be on top of all other settings. So, open it. Step 3 – Once there, open the “Payment & Shipping” option. Step 4 – Verify your access using Face ID. step

Steps to upgrade to the latest version of WeChat (Easily master the upgrade method to the latest version of WeChat) Steps to upgrade to the latest version of WeChat (Easily master the upgrade method to the latest version of WeChat) Jun 01, 2024 pm 10:24 PM

WeChat is one of the social media platforms in China that continuously launches new versions to provide a better user experience. Upgrading WeChat to the latest version is very important to keep in touch with family and colleagues, to stay in touch with friends, and to keep abreast of the latest developments. 1. Understand the features and improvements of the latest version. It is very important to understand the features and improvements of the latest version before upgrading WeChat. For performance improvements and bug fixes, you can learn about the various new features brought by the new version by checking the update notes on the WeChat official website or app store. 2. Check the current WeChat version We need to check the WeChat version currently installed on the mobile phone before upgrading WeChat. Click to open the WeChat application "Me" and then select the menu "About" where you can see the current WeChat version number. 3. Open the app

Shazam app not working in iPhone: Fix Shazam app not working in iPhone: Fix Jun 08, 2024 pm 12:36 PM

Having issues with the Shazam app on iPhone? Shazam helps you find songs by listening to them. However, if Shazam isn't working properly or doesn't recognize the song, you'll have to troubleshoot it manually. Repairing the Shazam app won't take long. So, without wasting any more time, follow the steps below to resolve issues with Shazam app. Fix 1 – Disable Bold Text Feature Bold text on iPhone may be the reason why Shazam is not working properly. Step 1 – You can only do this from your iPhone settings. So, open it. Step 2 – Next, open the “Display & Brightness” settings there. Step 3 – If you find that “Bold Text” is enabled

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

WiFi calling not working on iPhone: Fix WiFi calling not working on iPhone: Fix Jun 03, 2024 am 11:16 AM

Can't enable Wi-Fi calling on iPhone? Call quality is improved and you can communicate even from remote locations where cellular networks are not as strong. Wi-Fi Calling also improves standard call and video call quality. So, if you can't use Wi-Fi calling on your phone, these solutions might help you fix the problem. Fix 1 – Enable Wi-Fi Calling Manually You must enable the Wi-Fi Calling feature in your iPhone settings. Step 1 – For this, you have to open Settings. Step 2 – Next, just scroll down to find and open the “Phone” settings Step 3 – In the phone settings, scroll down and open the “Wi-Fi Calling” setting. Step 4 – In the Wi-Fi Calling page, change “This iPhone

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values ​​to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

Clear gray Safari history in iPhone: Fixes Clear gray Safari history in iPhone: Fixes Jun 08, 2024 pm 06:44 PM

Is the Clear History button gray in Safari on iPhone? If this is the case, you won't be able to clear history in Safari at all. Stored cookies and website data may cause unsolicited events in your browser. However, if you follow the steps below, you can easily resolve the issue and delete stored user history from Safari. Fix 1 – Disable Content Restrictions Content restrictions on iPhone may limit the correct use of Safari browser. Step 1 – Open iPhone settings. Step 2 – Next, go to Screen Time settings. Step 3 – In Screen Time settings, turn on Content & Privacy Restrictions

See all articles