你好,游客 登录 注册 搜索
背景:
阅读新闻

MySQL ODBC 驱动安装

[日期:2017-09-04] 来源:Linux社区  作者:chinas [字体: ]

阅读目录

  • 一、在线安装
    • 1、yum在线安装驱动
    • 2、配置驱动
    • 3、测试连接
  • 二、编译安装
    • 1、MySQL创建测试用户和测试库
    • 2、安装驱动
    • 3、配置驱动
    • 4、测试

一、在线安装 

1、yum在线安装驱动

# yum -y install unixODBC
# yum -y install mysql-connector-odbc
 

2、配置驱动

(1)查看驱动程序相关信息

# cat /etc/odbcinst.ini 
/************************************************
# Example driver definitions

# Driver from the postgresql-odbc package
# Setup from the unixODBC package
[PostgreSQL]
Description = ODBC for PostgreSQL
Driver = /usr/lib/psqlodbc.so
Setup = /usr/lib/libodbcpsqlS.so
Driver64 = /usr/lib64/psqlodbc.so
Setup64 = /usr/lib64/libodbcpsqlS.so
FileUsage = 1


# Driver from the mysql-connector-odbc package
# Setup from the unixODBC package
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc5.so
Setup = /usr/lib/libodbcmyS.so
Driver64 = /usr/lib64/libmyodbc5.so
Setup64 = /usr/lib64/libodbcmyS.so
FileUsage = 1
************************************************/

(2)配置MySQL驱动

# cat /etc/odbc.ini #添加如下信息
/************************************************
[mysql-hr]
Driver = /usr/lib64/libmyodbc5.so #注意驱动程序的选择
Description = MyODBC 5 Driver 
SERVER = 192.168.235.140    #要连接的数据库信息
PORT = 3306
USER = root
Password = root
Database = hr
OPTION = 3
charset=UTF8
************************************************/
 

3、测试连接

(1)连接MySQL创建测试用户、测试库

mysql> grant all privileges on *.* to test@192.168.152.129 identified by "root" with grant option;
mysql> create database hr;

##注:赋权时host与对应的MySQL ODBC驱动中配置要保持一致,如为IP或者localhost

(2)测试连接

# isql mysql-hr test root -v ##语法:isql 数据源名称 用户名 密码 选项
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>

二、编译安装

编译安装注意要预先安装编译工具,卸载默认安装的驱动程序并选择合适的版本。 

1、MySQL创建测试用户和测试库

mysql> grant all privileges on *.* to test@192.168.152.129 identified by "root" with grant option;
mysql> create database test;

##注:赋权时host与对应的MySQL ODBC驱动中配置要保持一致,如为IP或者localhost

 

2、安装驱动

yum -y install gcc gcc-c++ make
wget http://www.unixodbc.org/unixODBC-2.3.4.tar.gz
wget https://cdn.mysql.com//Downloads/Connector-ODBC/5.3/mysql-connector-odbc-5.3.9-linux-glibc2.12-x86-64bit.tar.gz

tar -zxvf unixODBC-2.3.4.tar.gz -C /usr/local
tar -zxvf mysql-connector-odbc-5.3.9-linux-glibc2.12-x86-64bit.tar.gz -C /usr/local/

cd /usr/local/unixODBC-2.3.4/
./configure --prefix=/usr/local/unixODBC-2.3.4 --includedir=/usr/include --libdir=/usr/local/lib -bindir=/usr/bin --sysconfdir=/usr/local/etc
make && make install

编辑/etc/ld.so.conf

# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf

echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig

目的:解决错误 ./myodbc-installer: error while loading shared libraries: libodbc.so.2: cannot open shared object file: No such file or directory

注册驱动

# ln -s /usr/local/mysql-connector-odbc-5.3.9/lib/libmyodbc5a.so /usr/lib/libmyodbc5a.so
# /usr/local/mysql-connector-odbc-5.3.9/bin/myodbc-installer -d -a -n "MySQL ODBC 5.3.9 Driver" -t "DRIVER=/usr/lib/libmyodbc5a.so;SETUP=/usr/lib/libmyodbc5a.so"
 

3、配置驱动

# vim /usr/local/etc/odbc.ini 

内容如下:

[mysql-hr]
Driver = /usr/lib/libmyodbc5a.so
Description = MyODBC 5 Driver 
SERVER = 192.168.152.129
PORT = 3306
USER = test
Password = root
Database = test
OPTION = 3
charset=UTF8
 

4、测试

# isql mysql-hr test root -v ##语法:isql 数据源名称 用户名 密码 选项
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>

本文永久更新链接地址http://www.linuxidc.com/Linux/2017-09/146729.htm

linux
相关资讯       MySql ODBC  ODBC驱动安装  ODBC驱动 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款