Bomi
分类: 系统运维
2012-02-04 01:04:31
# some materials about unixodbc
#http://www.easysoft.com/develope ... linux.html#unixodbc most worthy to read
#Chen peng MSN:peng.ch@hotmail.com 2006-4-28
# The unixODBC source distribution is a gzipped tar file on
# Uncompress it in the dir /usr/local and then untar the resultant file.
gunzip unixODBC-2.2.12.tar.gz
tar -xzvf unixODBC-2.2.12.tar
./configure --prefix=/usr/local/unixODBC-2.2.12 --includedir=/usr/include --libdir=/usr/lib -bindir=/usr/bin --sysconfdir=/etc
# create an ODBC driver template file and run odbcinst. filename : template_file
/*
In this case your template file must contain the Driver andDescription attributes at a minimum and optionally the Setup attributee.g.
[DRIVER_NAME]
Description = description of the ODBC driver
Driver = path_to_odbc_driver_shared_object
Setup = path_to_driver_setup_shared_object
e.g:
SkyKonnect:/ # cat /usr/local/etc/odbcinst.ini
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc3.so
Setup = /usr/local/lib/libodbcmyS.so
FileUsage = 2
UsageCount = 2
*/
odbcinst -f template_file -d -i
# You can list all installed ODBC drivers with:
odbcinst -s -q
/*
SkyKonnect:/usr/local/unixODBC-2.2.11/ODBCConfig # odbcinst -s -q
[myodbc3]
*/
# you can locate the odbcinst.ini file used to defined drivers as below If unixODBC is already installed :
odbcinst -j
/*
SkyKonnect:/usr/local/unixODBC-2.2.11/ODBCConfig # odbcinst -j
unixODBC 2.2.11
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
USER DATA SOURCES..: /root/.odbc.ini
*/
/** Edit the SYSTEM or USER DSN ini file ( odbc.ini or .odbc.ini) and add a data source using the syntax:
[ODBC_datasource_name}
Driver = driver_name
Description = description_of_data_source
attribute1 = value
.
.
attributen = value*
*/
/*
SkyKonnect:/ # cat /root/.odbc.ini
[myodbc3]
Driver = /usr/lib/libmyodbc3.so
Description = MyODBC 3.51 Driver DSN
SERVER = 192.168.1.9
PORT = 3306
USER = root
Password = root
Database = wapmax
OPTION = 3
SOCKET =
*/
# You can list user and system data sources with:
odbcinst -q -s
/*
SkyKonnect:/usr/local/unixODBC-2.2.11/ODBCConfig # odbcinst -q -s
[myodbc3]
*/
# The format of isql's command line for testing connection is:
isql -v DSN_NAME db_username db_password
/*
SkyKonnect:/ # isql myodbc3 root root
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [table]
| quit |
| |
+---------------------------------------+
SQL>
*/
#Tracing ODBC calls
/*
The unixODBC driver manager can write a trace of call ODBC calls made to a file.
This can be a very useful debugging aid but it should be remembered that tracing will slow your application down.
Locate your odbcinst.ini file and add a section to this file like:
[ODBC]
TraceFile = /tmp/sql.log
Trace = Yes
You can use any file for the TraceFile argument and it does not need to pre-exist.
The permissions on the odbcinst.ini may be such that you need to be the root user.
*/
[ 本帖最后由 云杉上的蝴蝶 于 2008-11-12 23:46 编辑 ]