"Organize" the way to install UNIXODBC on Linux __linux

Source: Internet
Author: User
Tags driver manager dsn odbc nntp postgresql sybase mysql odbc driver

ODBC is a database standard. Here's an introduction to ODBC from Wikipedia:

The ODBC (Open Database Connectivity) provides a standard API (application programming Interface) method to access the DBMS (DB Managementsystem). These APIs use SQL to accomplish most of their tasks. ODBC itself also provides support for SQL languages, and users can send SQL statements directly to ODBC. ODBC designers strive to make it the most independent and open: it has nothing to do with the specific programming language, regardless of the specific database system, and the specific operating system. Microsoft launched the world's first ODBC product in a DLL set in 1993 and is now an integral part of the database in the Microsoft Open Service Architecture (Wosa,windows Open Services architecture). Microsoft's ODBC product is actually an ODBC driver manager that provides an ODBC application to some ODBC-driven interface. On UNIX systems, there are two open source ODBC driver managers, UNIXODBC and IODBC. ”


ODBC uses DSN to save information connected to the database system. The ODBC program needs to open the connection to the DSN before using it. ODBC DSN is divided into four categories-System DSN, User DSN, File DSN, and perhaps a DSN created temporarily by the Connection.Open statement. In Unixodbc, a system DSN is stored in the/etc/odbc.ini, and a user DSN is stored in ~/.odbc.ini. Typically, programs that provide services outside use the System DSN.

Next we want to configure a DSN to store the CDR records for ODBC. First create a database in MySQL, then install and configure UNIXODBC. Because we use the MySQL server, we also need to be aware of installing MySQL ODBC driver.

sudo apt-get install Unixodbc LIBMYODBC

The UNIXODBC configuration files are mainly/etc/odbcinst.ini and/etc/odbc.ini. The former is used to configure the driver, which, as described earlier, is used to save the system DSN. Just installed the MySQL driver, you need to fill out its configuration information in the Vi/etc/odbcinst.ini. Now open your favorite editor and edit Vi/etc/odbcinst.ini:

[MySQL]
Description = MySQL driver for Linux
Driver =/usr/lib/odbc/libmyodbc.so
Setup =/usr/lib/odbc/libodbcmys.so
FileUsage = 1

The configuration information, in turn, is the driver description, the driver location, the location of the configuration program, and the number of drivers used. The actual driver location differs depending on the Linux distribution. Ubuntu is usually located under/usr/lib/odbc/. SuSE is located in/usr/lib/unixodbc/. Distributions such as Redhat may be different.

Then you configure DSN, and then we create a DSN named ASTERISKDB. Edit/etc/odbc.ini File

[ASTERISKDB]
Description = the Database for Asterisk
Trace = On
Tracefile = stderr
Driver = MySQL
SERVER = localhost
USER = root
PASSWORD = MyPassword
PORT = 3306
DATABASE = asterisk

In the configuration file, the name of the DSN is the name of the section. In configuration information, some of the configuration items are used by ODBC and the other part is handled by the driver. The following are the configuration items that are used by ODBC:

Description Description Information
Trace whether SQL statements are tracked. Two values with "on" and "off"
Tracefile If you are tracking SQL statements. The file where the trace information is saved. If you fill out the stderr, it will print to standard output
Driver the driver name configured in the/etc/odbcinst.ini.

Information such as "SERVER" and "USER" in the configuration file is used by the MySQL driver. Here are some examples:

[PostgreSQL]
Description = Test to Postgres
Driver = PostgreSQL
Trace = Yes
Tracefile = Sql.log
Database = Nick
Servername = localhost
UserName =
Password =
Port = 5432
Protocol = 6.4
ReadOnly = No
rowversioning = No
Showsystemtables = No
Showoidcolumn = No
Fakeoidindex = No
Connsettings =
[Mini SQL]
Description = Minisql
Driver = Minisql
Trace = No
Tracefile =
Host = localhost
Database =
ConfigFile =
[Mysql-test]
Description = MySQL Test Database
Trace = Off
Tracefile = stderr
Driver = MySQL
SERVER = 192.168.1.26
USER = Pharvey
PASSWORD =
PORT = 3306
DATABASE = Test
[NNTP Data Source]
Description = NNTP Driver
Driver = NNTP Driver
Trace = No
Tracefile =
Host = localhost
Database =
Port =
[FreeTDS Driver]
Driver = TDS
Description = Northwind Sample Database
Trace = No
Server = 192.168.1.25
Database = Northwind
UID = sa
[Sybase SQL Anywhere 5.0]
Driver=sybase SQL Anywhere 5.0
Description=sybase SQL Anywhere 5.0 ODBC Driver
Userid=dba
Password=sql
Databasefile=sademo.db

If the operation is completely correct, ODBC is now successful. You can try the isql command to manipulate the DSN you just configured.

$ isql ASTERISKDB
+---------------------------------------+
|                            connected! |
| |
| sql-statement |
| Help [TableName] |
| Quit |
| |
+---------------------------------------+
Sql> Show tables;
+-----------------------------------------------------------------+
| Tables_in_asterisk |
+-----------------------------------------------------------------+
+-----------------------------------------------------------------+
SQLRowCount returns 0
Sql>

This command-line interface is similar to the MySQL command and can be used for various database operations. At this point, UNIXODBC has been installed successfully.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.