连接 Erlang 和 mysql odbc 时出错
Posted
技术标签:
【中文标题】连接 Erlang 和 mysql odbc 时出错【英文标题】:Error connecting Erlang and mysql odbc 【发布时间】:2017-10-07 18:32:33 【问题描述】:我有一个 Amazon linux 实例,我在上面安装了一个名为 ejabberd 的服务器 在里面我有一个用 erlang 编写的代码(db.erl)。
-module(db).
-export([connection/0]).
connection()->
odbc:start(),
ConnectionString = "DSN=qaz;UID=root;PWD=abc",
ok, Ref = odbc:connect(ConnectionString, []),
Ref.
但是当我这段代码即将运行时,我得到一个错误
[error] gen_server myapp terminated with reason: no match of right hand
value error,"[unixODBC][Driver Manager]Can't open lib
'/usr/lib/libmyodbc5.so' : file not found SQLSTATE IS: 01000 Connection to
database failed." in db:connection/0 line 15
10:34:15.111 [error] CRASH REPORT Process myapp with 0 neighbours exited
with reason: no match of right hand value error,"[unixODBC][Driver
Manager]Can't open lib '/usr/lib/libmyodbc5.so' : file not found SQLSTATE
IS: 01000 Connection to database failed." in db:connection/0 line 15 in
gen_server:terminate/7 line 812
10:34:15.111 [error] Supervisor frequency_sup had child myapp started with
myapp:start() at <0.502.0> exit with reason no match of right hand value
error,"[unixODBC][Driver Manager]Can't open lib '/usr/lib/libmyodbc5.so' :
file not found SQLSTATE IS: 01000 Connection to database failed." in
db:connection/0 line 15 in context child_terminated
我已经使用以下配置编辑了我的 /etc/odbc.ini 和 /root/.odbc.ini
[ODBC Data Sources]
qaz= ODBC for mysql
[qaz]
Driver = /usr/lib64/libmyodbc5.so
Description = ODBC for MySQL
SERVER = localhost
PORT = 3306
USER = root
Password = abc
Database = mydb
我的 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
[MySQL ODBC 5.3 Unicode Driver]
Driver = /usr/lib/libmyodbc5w.so
UsageCount = 1
[MySQL ODBC 5.3 ANSI Driver]
Driver = /usr/lib/libmyodbc5a.so
UsageCount = 1
当我运行命令时
isql qaz [root [abc]]
我得到一个错误
[ISQL]ERROR: Could not SQLConnect
谁能告诉我这个问题并指导我在 linux 中设置 odbc 配置的正确方法 我已经在windows上成功了,但是我对linux不太熟悉。 提前谢谢你
【问题讨论】:
【参考方案1】:是mySQL提供的ODBC驱动(ODBC连接器)。有没有预装驱动?搜索如何安装mysql odbc驱动。
但是,我建议使用另一个 mysql 驱动程序,例如 mysql/otp 而不是 ODBC 驱动程序。我在使用带有 mySql 的 ODBC 驱动程序时遇到了问题。
【讨论】:
以上是关于连接 Erlang 和 mysql odbc 时出错的主要内容,如果未能解决你的问题,请参考以下文章
在设置odbc的mysql数据源时出现了如下问题 求助~~!!
为啥在 Access 中使用 UNION ALL 时出现 ODBC 连接失败错误?