原贴地址:https://www.connectionstrings.com/mysql/
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Server=myServerAddress;Port=1234;Database=myDataBase;Uid=myUsername;
Pwd=myPassword;
Use this to connect to a server in a replicated server configuration without concern on which server to use.
Server=serverAddress1, serverAddress2, serverAddress3;Database=myDataBase;
Uid=myUsername;Pwd=myPassword;
This one activates SSL encryption for all data sent between the client and server. The server must have a certificate installed.
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Encrypt=true;
Use SSL if the server supports it, but allow connection in all cases
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
SslMode=Preferred;
Always use SSL. Deny connection if server does not support SSL.
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
SslMode=Required;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
SSL Mode=Required;CertificateFile=C:\folder\client.pfx;CertificatePassword=pass;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
SSL Mode=Required;Certificate Store Location=CurrentUser;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
SSL Mode=Required;Certificate Store Location=CurrentUser;
Certificate Thumbprint=479436009a40f3017a145cf8479e7694d7aadef0;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
AllowBatch=False;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
AllowUserVariables=True;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
AllowZeroDateTime=True;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
ConvertZeroDateTime=True;
The use of auto enlist transactionscope (default behaviour) could cause trouble in medium trust environments.
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
AutoEnlist=False;
Default behaviour is that parameters for stored routines (stored procedures) are checked against the server
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
CheckParameters=False;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
UseProcedureBodies=False;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
tablecache=true;DefaultTableCacheAge=30;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
UseAffectedRows=True;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
UseCompression=True;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
UseUsageAdvisor=True;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
UsePerformanceMonitor=True;
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.
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Pooling=True;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
MinimumPoolSize=10;maximumpoolsize=50;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Pooling=False;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
ConnectionReset=True;
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.
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
ConnectionLifeTime=300;
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.
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
CacheServerProperties=True;
Server=myServerAddress;Database=myDataBase;IntegratedSecurity=yes;
Uid=auth_windows;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Keepalive=10;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
OldGuids=True;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
ProcedureCacheSize=0;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
sqlservermode=True;
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.
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
default command timeout=20;
Use this one to specify the length in seconds to wait for a server connection before terminating the attempt and receive an error.
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Connection Timeout=5;
Use this one to instruct the provider to ignore any command prepare statements and prevent corruption issues with server side prepared statements.
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Ignore Prepare=true;
Use this one to specify which network protocol to use for the connection.
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Protocol=socket;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Protocol=memory;Shared Memory Name=MYSQL;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Protocol=pipe;PipeName=mypipename;
Server=myServerAddress;Port=-1;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Protocol=memory;Shared Memory Name=MYSQL;
Use this one to specify which character set to use to encode queries sent to the server.
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
CharSet=utf8;
Location=myServerAddress;Data Source=myDataBase;User ID=myUsername;
Password=myPassword;Port=3306;Extended Properties="""";
Host=myServerAddress;UserName=myUsername;Password=myPassword;Database=myDataBase;
User ID=root;Password=myPassword;Host=localhost;Port=3306;Database=myDataBase;
Direct=true;Protocol=TCP;Compress=false;Pooling=true;Min Pool Size=0;
Max Pool Size=100;Connection Lifetime=0;
Provider=MySQLProv;Data Source=mydb;User Id=myUsername;Password=myPassword;
Data Source=myServerAddress;Database=myDataBase;User ID=myUsername;
Password=myPassword;Command Logging=false;
Provider=any oledb provider's name;OledbKey1=someValue;OledbKey2=someValue;
Driver={MySQL ODBC 5.2 UNICODE Driver};Server=localhost;Database=myDataBase;
User=myUsername;Password=myPassword;Option=3;
Driver={MySQL ODBC 5.2 ANSI Driver};Server=localhost;Database=myDataBase;
User=myUsername;Password=myPassword;Option=3;
It seems we need to point on MSDASQL for the (32 bit) ODBC driver to work on 64 bit machines.
Provider=MSDASQL;Driver={MySQL ODBC 5.2 ANSI Driver};Server=localhost;
Database=myDataBase;User=myUsername;Password=myPassword;Option=3;
Driver={MySQL ODBC 5.2 ANSI Driver};Server=myServerAddress;Database=myDataBase;
User=myUsername;Password=myPassword;Option=3;
Driver={MySQL ODBC 5.2 ANSI Driver};Server=myServerAddress;Port=3306;
Database=myDataBase;User=myUsername;Password=myPassword;Option=3;
Driver={MySQL ODBC 5.2 ANSI Driver};Server=myServerAddress;charset=UTF8;
Database=myDataBase;User=myUsername;Password=myPassword;Option=3;
This one specifies the Unix socket file or Windows named pipe to connect to. Used only for local client connections.
Driver={MySQL ODBC 5.2 ANSI Driver};Server=myServerAddress;Database=myDataBase;
User=myUsername;Password=myPassword;Socket=MySQL;Option=3;
Driver={MySQL ODBC 5.2 ANSI Driver};Server=myServerAddress;Database=myDataBase;
User=myUsername;Password=myPassword;sslca=c:\cacert.pem;
sslcert=c:\client-cert.pem;sslkey=c:\client-key.pem;sslverify=1;Option=3;
Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=myDataBase;
User=myUsername;Password=myPassword;Option=3;
It seems we need to point on MSDASQL for the (32 bit) ODBC driver to work on 64 bit machines.
Provider=MSDASQL;Driver={MySQL ODBC 5.1 Driver};Server=localhost;
Database=myDataBase;User=myUsername;Password=myPassword;Option=3;
Note the "w" in the driver name.
Driver={MySQL ODBC 5.2w Driver};Server=localhost;Database=myDataBase;
User=myUsername;Password=myPassword;Option=3;
MySQL ODBC Connector version 5.2.5 and above register itself as "MySQL ODBC 5.2 Unicode Driver" and "MySQL ODBC 5.2 ANSI Driver".
Driver={MySQL ODBC 5.2 ANSI Driver};Server=localhost;Database=myDataBase;
User=myUsername;Password=myPassword;Option=3;
Driver={MySQL ODBC 5.1 Driver};Server=myServerAddress;Database=myDataBase;
User=myUsername;Password=myPassword;Option=3;
Driver={MySQL ODBC 5.1 Driver};Server=myServerAddress;Port=3306;
Database=myDataBase;User=myUsername;Password=myPassword;Option=3;
Driver={MySQL ODBC 5.1 Driver};Server=myServerAddress;charset=UTF8;
Database=myDataBase;User=myUsername;Password=myPassword;Option=3;
This one specifies the Unix socket file or Windows named pipe to connect to. Used only for local client connections.
Driver={MySQL ODBC 5.1 Driver};Server=myServerAddress;Database=myDataBase;
User=myUsername;Password=myPassword;Socket=MySQL;Option=3;
Driver={MySQL ODBC 5.1 Driver};Server=myServerAddress;Database=myDataBase;
User=myUsername;Password=myPassword;sslca=c:\cacert.pem;
sslcert=c:\client-cert.pem;sslkey=c:\client-key.pem;sslverify=1;Option=3;
Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=myDataBase;
User=myUsername;Password=myPassword;Option=3;
Driver={MySQL ODBC 3.51 Driver};Server=myServerAddress;Database=myDataBase;
User=myUsername;Password=myPassword;Option=3;
Driver={MySQL ODBC 3.51 Driver};Server=myServerAddress;Port=3306;
Database=myDataBase;User=myUsername;Password=myPassword;Option=3;
Driver={MySQL ODBC 3.51 Driver};Server=myServerAddress;charset=UTF8;
Database=myDataBase;User=myUsername;Password=myPassword;Option=3;
This one specifies the Unix socket file or Windows named pipe to connect to. Used only for local client connections.
Driver={MySQL ODBC 3.51 Driver};Server=myServerAddress;Database=myDataBase;
User=myUsername;Password=myPassword;Socket=MySQL;Option=3;
Driver={MySQL ODBC 3.51 Driver};Server=myServerAddress;Database=myDataBase;
User=myUsername;Password=myPassword;sslca=c:\cacert.pem;
sslcert=c:\client-cert.pem;sslkey=c:\client-key.pem;sslverify=1;Option=3;
Driver={mySQL};Server=localhost;Option=16834;Database=myDataBase;
Driver={mySQL};Server=myServerAddress;Option=131072;Stmt=;Database=myDataBase;
User=myUsername;Password=myPassword;
Driver={mySQL};Server=myServerAddress;Port=3306;Option=131072;Stmt=;
Database=myDataBase;User=myUsername;Password=myPassword;
Driver={any odbc driver's name};OdbcKey1=someValue;OdbcKey2=someValue;