Ubuntu 20.04 安装ODBC&连接MySQL8.0
本文记录了在Ubuntu 20.04.5系统上安装ODBC后连接MySQL 8.0的一般过程,仅供参考学习。
1. 安装ODBC
更新源,安装unixodbc
apt update apt install unixodbc apt install unixodbc-dev
查看是否安装成功,
odbcinst -j
unixODBC 2.3.6 DRIVERS............: /etc/odbcinst.ini SYSTEM DATA SOURCES: /etc/odbc.ini FILE DATA SOURCES..: /etc/ODBCDataSources USER DATA SOURCES..: /root/.odbc.ini SQLULEN Size.......: 8 SQLLEN Size........: 8 SQLSETPOSIROW Size.: 8
2. 安装MySQL ODBC 驱动
选择合适的版本,下载Ubuntu 20.04 MySQL ODBC驱动 https://downloads.mysql.com/archives/c-odbc/,使用dpkg -i安装驱动:
dpkg -i xx.deb
若在安装过程中报出以下错误:
dpkg: dependency problems prevent configuration of mysql-connector-odbc:amd64: mysql-connector-odbc:amd64 depends on dpkg-dev; however: Package dpkg-dev is not installed.
安装dpkg-dev后,重新使用dpkg -i安装odbc驱动:
apt install dpkg-dev
dpkg -i xx.deb
3. MySQL数据源配置
修改/etc/odbc.ini(不存在则创建)
vi /etc/odbc.ini
[MySQL-Test] Description = MySQL Test Database Trace = Off TraceFile = stderr Driver = MySQL ODBC 8.0 Unicode Driver SERVER = localhost USER = test PASSWORD = 123456 PORT = 3306 DATABASE = test-db
测试是否连接成功:
isql -v MySQL-Test
+---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ SQL>