Centos7 configures odbc data source to connect to mysql

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

#view the basics of your config in a nice info file
odbcinst -j

#view the ODBC config instance file, this is for different database types.as you can see MySQL and PostgreSQL are allready configured
cat /etc/odbcinst.ini

[PostgreSQL]
Description=ODBC for PostgreSQL
Driver=/usr/lib/psqlodbcw.so
Setup=/usr/lib/libodbcpsqlS.so
Driver64=/usr/lib64/psqlodbcw.so
Setup64=/usr/lib64/libodbcpsqlS.so
FileUsage=1
UsageCount=5

[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
UsageCount=5

#from here we need to create specific instances/connections.
vi /etc/odbc.ini

#here’s a look at a sample ODBC connection config,remote database connect info

[HER]
Description=MySQL connection to 'assetcloud' database
Trace=OFF
TraceFile=stderr
Driver=MySQL
SERVER=121.41.113.120
PORT=3306
DATABASE=assetcloud
USERNAME=mysql
PASSWORD=123456

#from here install the ODBC driver, and install SystemDSN
odbcinst -i -d -f /etc/odbc.inst.ini
odbcinst -i -s -l -f /etc/odbc.inst.ini

#test the connection using the Database name {space} username
isql EAM mysql

#as we can see basic SQL Queries work
SHOW DATABASES;
select * from users;

When using odbcinst -q -d, I get the error:
odbcinst: SQLGetPrivateProfileString failed with .
Solution: env |grep 'ODBC'
If the environment variables ODBCSYSINI and ODBCINI cannot be found, then:
vi /etc/profile

Add the following:
export ODBCSYSINI=/etc
export ODBCINI=/etc/odbc.ini

In addition, if you use make under linux, the following error occurs:
configure: error: no acceptable C compiler found in $PATH

Solution: yum -y install gcc gcc-c++ gdb

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326448242&siteId=291194637