linux下配置ODBC连接MySql

下载安装文件

unixODBC-2.3.0.tar.gz

下载地址: ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.0.tar.gz

mysql-connector-odbc-5.1.8-1.rhel5.i386.rpm

下载地址: http://dev.mysql.com/downloads/connector/odbc/


一.安装unixODBC

tar -xzf unixODBC-2.3.0.tar.gz
cd unixODBC-2.3.0
./configure --prefix=/usr/local/unixODBC --includedir=/usr/include --libdir=/usr/lib -bindir=/usr/bin --sysconfdir=/etc
make
make install

安装成功后,unixODBC所需的头文件都被安装到了/usr/inlucde下,编译好的库文件安装到了/usr/lib下,与unixODBC相关的可执行文件安装到了/usr/bin下,配置文件放到了/etc下。

或者

rpm -ivh unixODBC-2.2.11-7.1.i386.rpm unixODBC-devel-2.2.11-7.1.i386.rpm

二.安装mysql-connector-odbc

rpm -ivh mysql-connector-odbc-5.1.8-1.rhel5.i386.rpm --nodeps

(- -nodeps)为忽略依赖关系。

三.配置myodbc

vi /etc/odbc.ini

[mysql-test]
Description = MySQL test database
Trace = On
TraceFile = stderr
Driver = mysql
SERVER = localhost
USER = root
PASSWORD = kaychen
PORT = 3306
DATABASE = test
socket = /tmp/mysql.sock

 

vi /etc/odbcinst.ini

[PostgreSQL]
Description     = ODBC for PostgreSQL
Driver          = /usr/lib/libodbcpsql.so
Setup           = /usr/lib/libodbcpsqlS.so
FileUsage       = 1

[MySQL ODBC 5.1 Driver]
Driver          = /usr/lib/libmyodbc5.so
UsageCount      = 1

[mysql]
Description = MySQL driver
Driver = /usr/lib/libmyodbc5.so
Setup = /usr/lib/libodbcmyS.so
Socket = /tmp/mysql.sock
FileUsage = 1

测试连接:isql mysql-test 或者isql mysql-test  root kaychen

[root@K-RedHat5 mysql5.1]# isql mysql-test
+—————————————+
| Connected!                            |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
+—————————————+

连接成功

展开阅读全文

没有更多推荐了,返回首页