Mysql Odbc 连接参数
ODBC Driver for MySQL
If you want to connect to a local database, you can use a connection string like the following:
strConnect = _T("Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=MyDatabase;User=MyUserName;Password=MyPassword;Option=4;");
If you want to connect with a remote database, you need to specify the name of the server or its IP in the Server parameter. If the Port is distinct to 3306 (default port), you must specify it.
strConnect = _T("Driver={mySQL ODBC 5.1 Driver};Server=MyRemoteHost;Port=3306;Option=4;Database=MyDatabase;Uid=MyUsername;Pwd=MyPassword;");
The parameter Option can be one or more of the following values:
- 1 - The client can't handle that MyODBC returns the real width of a column.
- 2 - The client can't handle that MySQL returns the true value of affected rows. If this flag is set then MySQL returns 'found rows' instead. One must have MySQL 3.21.14 or newer to get this to work.
- 4 - Make a debug log in c:\myodbc.log. This is the same as puttingMYSQL_DEBUG=d:t:O,c::\myodbc.log in AUTOEXEC.BAT.
- 8 - Don't set any packet limit for results and parameters.
- 16 - Don't prompt for questions even if driver would like to prompt.
- 32 - Enable or disable the dynamic cursor support. This is not allowed in MyODBC 2.50.
- 64 - Ignore use of database name in 'database.table.column'.
- 128 - Force use of ODBC manager cursors (experimental).
- 256 - Disable the use of extended fetch (experimental).
- 512 - Pad CHAR fields to full column length.
- 1024 - SQLDescribeCol() will return fully qualified column names.
- 2048 - Use the compressed server/client protocol.
- 4096 - Tell server to ignore space after function name and before '(' (needed by PowerBuilder). This will make all function names keywords!
- 8192 - Connect with named pipes to a MySQLd server running on NT.
- 16384 - Change LONGLONG columns to INT columns (some applications can't handleLONGLONG).
- 32768 - Return 'user' as Table_qualifier and Table_owner from SQLTables (experimental).
- 65536 - Read parameters from the client and ODBC groups from my.cnf.
- 131072 - Add some extra safety checks (should not be needed but...).
If you want to have multiple options, you should add the above flags! For example: 16 + 1024 = 1030 and use Option= 1030;.
连接参数
你可以在ODBC.INI文件的[Data Source Name](数据源名)部分、或通过SQLDriverConnect()call的InConnectionString参量为MyODBC指定下述参数。
|
参数 |
默认值 |
注释 |
|
user |
ODBC (on Windows) |
用于链接至MySQL的用户名。 |
|
server |
localhost |
MySQL服务器的主机名。 |
|
database |
|
默认数据库。 |
|
option |
0 |
指定MyODBC工作方式的选项。参见下面。 |
|
port |
3306 |
如果服务器不是本地主机将要使用的TCP/IP端口。 |
|
stmt |
|
连接至MySQL时将要执行的语句。 |
|
password |
|
服务器上用户账户的密码。 |
|
socket |
|
当服务器是本地主机是将要连接的Unix套接字文件或Windows命名管道。 |
选项参量用于通知MyODBC:客户端不是100% ODBC兼容的。在Windows平台下,正常情况下,应通过切换连接屏幕上的复选框选择选项,但也能在选项参量中选择它们。下述选项是按照它们在MyODBC连接屏幕上显示的顺序排列的:
|
值 |
描述 |
|
1 |
客户端无法处理,MyODBC返回列的实际宽度。 |
|
2 |
客户端无法处理,MyODBC返回受影响行的真值。如果设置了该标志,MySQL将返回“发现的行”取而代之。MySQL的版本必须是3.21.14或更高版本,该功能才能生效。 |
|
4 |
在c:\myodbc.log中生成调试日志。它与将MYSQL_DEBUG=d:t:O,c::\myodbc.log放到AUTOEXEC.BAT中的效果相同(在Unix平台下,该文件是/tmp/myodbc.log)。 |
|
8 |
不为结果和参数设置任何信息报限制。 |
|
16 |
即使驱动程序可能会给出提示,对出现的问题不予提示。 |
|
32 |
允许或禁止动态光标支持。(在MyODBC 2.50中不允许)。 |
|
64 |
在db_name.tbl_name.col_name中忽略数据库名的使用。 |
|
128 |
强制使用ODBC管理器光标(实验性)。 |
|
256 |
禁止使用扩展取数据(实验性)。 |
|
512 |
将CHAR列填充为全列宽。 |
|
1024 |
SQLDescribeCol()返回完全合格的列名。 |
|
2048 |
使用压缩客户端/服务器协议。 |
|
4096 |
通知服务器忽略函数名之后和“(”之前的空格(PowerBuilder要求这样)。这会使所有的函数名成为关键字。 |
|
8192 |
用命名管道链接至运行在NT环境下的mysqld服务器。 |
|
16384 |
将LONGLONG列更改为INT列(某些应用程序不能处理LONGLONG列)。 |
|
32768 |
从SQLTables返回作为Table_qualifier和Table_owner的用户(实验性)。 |
|
65536 |
从my.cnf的[client]和[odbc]组读取参数。 |
|
131072 |
增加一些额外检查(不应需要之,但…)。 |
|
262144 |
禁止事务。 |
|
524288 |
允许将查询记录到c:\myodbc.sql(/tmp/myodbc.sql)文件。(仅在调试模式下才能启用)。 |
|
1048576 |
不要驱动中的结果进行缓冲处理,而应从服务器读取“mysql_use_result()”。仅对正向光标才能起作用。当你不希望缓冲处理整个结果集时,对于大表处理,该选项十分重要。 |
|
2097152 |
强制使用正向光标类型。在应用程序设置了默认静态/动态光标类型的情况下,如果希望驱动程序使用非缓冲结果集,那么该选项能够保证正向光标的行为。 |
要想选择多个选项,可将它们的值加在一起。例如,将选项设置为12(4+8),就能获得调试功能,但没有信息包限制。
默认的myodbc3.dll是为优化性能而编译的。如果希望调试MyODBC 3.51(例如,启用跟踪功能),应使用myodbc3d.dll。要想安装该文件,请拷贝myodbc3d.dll,使之覆盖已安装的myodbc3.dll文件。一旦完成了调试操作,务必恢复至驱动DLL的发布版本,这是因为调试版本可能会导致性能问题。注意,在MyODBC 3.51.07至3.51.11中未包含myodbc3d.dll。如果你正在使用这些版本中的一个,应从之前的版本(例如3.51.06)拷贝该DLL文件。
对于MyODBC 2.50,采用了myodbc.dll和myodbcd.dll取而代之。
在下面的表各中,给出了针对各种配置的推荐选项值:
|
配置 |
选项值 |
|
Microsoft Access |
3 |
|
Microsoft Visual Basic |
3 |
|
具有很多行的大表 |
2049 |
|
驱动跟踪生成(调试模式) |
4 |
|
查询日志生成(调试模式) |
524288 |
|
生成驱动跟踪和查询日志(调试模式) |
524292 |
|
具有非缓冲结果的大表 |
3145731 |
posted on 2014-04-14 21:05 Leadtheway 阅读(1142) 评论(0) 收藏 举报
浙公网安备 33010602011771号