Debian Codegraph @

doc/AdministratorManual/unixODBCsetup.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
2 <HTML>
3 <HEAD>
4 <TITLE></TITLE>
5 <META NAME="GENERATOR" CONTENT="StarOffice/5.1 (Linux)">
6 <META NAME="AUTHOR" CONTENT="Charles Morrison">
7 <META NAME="CREATED" CONTENT="19990831;225400">
8 <META NAME="CHANGEDBY" CONTENT="Charles Morrison">
9 <META NAME="CHANGED" CONTENT="19990914;11232600">
10 </HEAD>
11 <BODY>
12 <H3 ALIGN=CENTER>A neophyte's guide <BR>to getting unixODBC and
13 Mysql/MyODBC working<BR><BR><BR>
14 </H3>
15 <H4>Introduction</H4>
16 <P STYLE="margin-left: 0.79in">UnixODBC is an idea whose time has
17 come. It holds many promises for those of us who use databases in our
18 daily work and would like to do more of that work on Linux or one of
19 the UNIX variants. Those coming from a windows background will
20 rapidly discover that it can be much more involved setting up a
21 working Unix based database than they are used to. They will also
22 discover a world of great advantages too; stability, scalability and
23 freely available source code are values not easily dismissed.</P>
24 <P STYLE="margin-left: 0.79in">This document is designed to help
25 people set up and use unixODBC. My database of choice is MySQL, which
26 I have used with great success for several years, and it is the
27 database I will discuss setting up</P>
28 <P STYLE="margin-left: 0.79in">ODBC is an interface by which programs
29 and programmers can communicate with any database which has an ODBC
30 driver. While most databases have one or more APIs in various
31 programming languages, ODBC allows the same programming code to talk
32 with numerous types of databases. (ODBC is not the only interface to
33 do this, but it is very widely used and supported)</P>
34 <H4>Getting Started</H4>
35 <P STYLE="margin-left: 0.79in">UnixODBC is available in source code
36 only. This means that you download a tar file from
37 <A HREF="http://www.unixODBC.org/">http://www.unixODBC.org</A> ,
38 extract it, compile it, and install it. Before you do so though you
39 need some other things.</P>
40 <H4>Prerequisets:
41 </H4>
42 <OL>
43 <LI><P>The Qt toolkit version 2.x sources from <A HREF="http://www.troll.no/">http://www.troll.no</A>
44 . Make sure it is version 2 or higher !</P>
45 <OL>
46 <LI><P>Download the Qt v2 sources.</P>
47 <LI><P>Extract the sources to somewhere, usually this is done by
48 placing the tar file in a directory like /usr/local or /opt and
49 using the command.<BR><B>tar zxvf qt-2.0.1.tar.gz </B><BR>to
50 extract the files. This will create a subdirectory qt-2.0.1 .
51 Remember that only root can normally write to /usr/local or /opt.
52 This is an example, use the name of the file you have.</P>
53 <LI><P>Compile the sources. Assuming you have a relatively recent
54 version of Linux with all the appropriate stuff (libg++, gcc or
55 egcs etc) You issue 3 commands from the qt-2.0.1
56 directory.<BR><B>./configure</B><BR><B>make</B><BR><B>make install</B></P>
57 <LI><P>This last command is scary since it will install the new
58 libqt into places where any old v1.4x libqt may exist. Rest assured
59 that the full name of the library is different and it will not
60 overwrite your existing libqt. It should choke on rewriting the
61 symlink to libqt.so and thus not mess up your existing Qt / KDE
62 apps. If it does rewrite this link, you will need to set it back to
63 its original link.</P>
64 <LI><P>For more information, see <A HREF="http://www.troll.no/">http://www.troll.no</A>
65 . Please don't bother the unixODBC people for instructions on
66 setting up Qt.</P>
67 </OL>
68 </OL>
69 <OL START=2>
70 <LI><P>A Database - in this case MySQL from <A HREF="http://www.mysql.com/">http://www.mysql.com</A></P>
71 <OL>
72 <LI><P>Again, I strongly suggest you get the sources and compile
73 them yourself. The process is similar if not identical to that for
74 Qt described above. By default MySQL installs it's executable files
75 in<B><I> /usr/local/bin</I></B>, it's include files (source
76 headers) in <B><I>/usr/local/include/mysql</I></B> and it's
77 libraries in <B><I>/usr/local/lib/mysql</I></B>. The actual
78 database files are in <B><I>/usr/local/var</I>.</B></P>
79 <LI><P>Before you can use MySQL, you need to run
80 <BR><B>/usr/local/bin/mysql_install_db</B> <BR>as root to set up
81 the system tables. To actually start the database, run
82 <BR><B>/usr/local/bin/safe_mysqld &amp;</B></P>
83 <LI><P>MySQL comes with very extensive documentation. Refer to it
84 for questions on compiling, installing and using MySQL. This is
85 especially true for permissions. If the permissions aren't correct,
86 no interface will work.</P>
87 </OL>
88 </OL>
89 <H4>Installing unixODBC</H4>
90 <OL>
91 <LI><P>As mentioned before, get the source tar file from
92 <A HREF="http://www.unixodbc.org/">http://www.unixodbc.org</A> . As
93 root, move the tar file to /op or /usr/local or where ever you want
94 the source to reside. Untar the file and run the following commands
95 from the command line in the unixODBC source
96 directories:<BR><B>./configure</B><BR><B>./make</B><BR><B>./make
97 install</B></P>
98 <LI><P>Assuming that you have all the libraries and tools that it
99 needs, you should be breezing through this compile. Certainly after
100 all that practice with Qt and MySQL this should be old hat. UnixODBC
101 takes quite a while to compile, actually all of these packages do.
102 Relax and enjoy it.
103 </P>
104 </OL>
105 <H4>Installing a Driver</H4>
106 <P STYLE="margin-left: 0.79in">UnixODBC by itself isn't a whole lot
107 of good without a driver. MySQL has an ODBC driver named MyODBC but
108 it isn't included with the current edition of unixODBC, so you have
109 to get it and compile it yourself. I'll be referring to version
110 2.50.24, the latest as of this writing. The installation is much the
111 same as the other packages, but you need to give configure some
112 options. It will prompt you for the path to the MySQL sources if you
113 don't specify the path, but you also have to supply the
114 <I>--with-unixODBC=</I>&lt;your unixODBC directory here&gt; flag. The
115 following is from the MyODBC INSTALL file:
116 </P>
117 <P STYLE="margin-left: 0.79in"><I> To make configure look for
118 unixODBC instead of iODBC, use</I></P>
119 <P STYLE="margin-left: 0.79in"><I> --with-unixODBC=DIR</I></P>
120 <P STYLE="margin-left: 0.79in"><I> Where DIR is where unixODBC
121 is installed.</I></P>
122 <P STYLE="margin-left: 0.79in"><I> And (as usual), if the
123 unixODBC headers and libraries aren't located</I></P>
124 <P STYLE="margin-left: 0.79in"><I> in DIR/include and DIR/lib,
125 use</I></P>
126 <P STYLE="margin-left: 0.79in"><I>
127 --with-unixODBC-libs=LIBDIR --with-unixODBC-includes=INCDIR</I></P>
128 <P STYLE="margin-left: 0.79in"><I> You might want to specify a
129 prefix other than /usr/local for installation,<BR> I, for example
130 keep my ODBC drivers in /usr/local/odbc/lib, so I add</I></P>
131 <P STYLE="margin-left: 0.79in"><I> --prefix=/usr/local/odbc</I></P>
132 <P STYLE="margin-left: 0.79in">So here is my configure line:</P>
133 <P STYLE="margin-left: 0.79in"><B>./configure
134 <I>--with-unixodbc=/usr/local --with-mysql-sources=/usr/local/mysql</I></B></P>
135 <P STYLE="margin-left: 0.79in">Running <B>make</B> and then <B>make
136 install</B> puts the resulting library: <B>libmyodbc-2.50.23.so</B>
137 into /usr/local/lib. WAIT A MINUTE ! Didn't I say it was version
138 2.50.24 ? Yes, I did. However, unless you want to go in and change
139 the version info in the source code, it will create the library with
140 that name. I don't consider this a big deal and so I didn't mess with
141 it.</P>
142 <P STYLE="margin-left: 0.79in">If you omit the <I>--with-mysql-sources</I>
143 flag, configure will fail. If you omit the <SPAN STYLE="font-weight: medium"><I>--with-unixodbc</I></SPAN>
144 flag, configure will complete and MyODBC will compile. However, it
145 will not work correctly when using it with unixODBC. The problems
146 described below occurred when I omitted this flag: <BR><BR>1) If the
147 DSN (Data Source Name) you create is also the name of a database, the
148 driver points to that database no matter what you specify the
149 database to be.<BR>2) If the DSN is not the name of an existing
150 database, it will fail, not allowing you to login to the database.
151 The trace log file will tell you that it couldn't find a database
152 with the name of the DSN. This is confusing if you specified a valid
153 database name in the .odbc.ini file .
154 </P>
155 <P STYLE="margin-left: 0.79in">When using the <I>--with-unixodbc</I>
156 flag, These problems disappear and it works the way it should.
157 </P>
158 <P STYLE="margin-left: 0.79in">A note: MyODBC does not support ODBC
159 version 3 as of version 2.50.24 . When writing programs that utilize
160 this driver, I have had success with specifying V_OD_ODBC2 when
161 calling SQLSetEnvAttr(...) .</P>
162 <H4>Setting up unixODBC</H4>
163 <P STYLE="margin-left: 0.79in">At long last we come to actually
164 setting up unixODBC and using it. While most of this information
165 exists on the unixODBC web pages and user's guide, I found it
166 difficult to find and follow, so I repeat it here in hopes that it
167 will be made clearer.</P>
168 <P STYLE="margin-left: 0.79in">UnixODBC consists of a lot of
169 libraries, installed in <B>/usr/local/lib</B>, and a few executable
170 files (binaries) installed into <B>/usr/local/bin</B>. These
171 executable files are <I>ODBCConfig</I>, <I>DataManager</I>, and
172 <SPAN STYLE="font-weight: medium"><I>odbcinst</I></SPAN>.
173 </P>
174 <P><B>In order to get unixODBC running, do these things in this
175 order:</B></P>
176 <P><B>Do this as root...</B></P>
177 <P STYLE="margin-left: 0.79in">In an xterm, type ODBCConfig . This is
178 a GUI program and must be run in an X session. At the very least you
179 need to set up a driver to use. The drivers will be specific to one
180 database application, like MyODBC is specific to MySQL. In addition
181 to this, you need to specify a setup file to use for this drive. The
182 setup files are the <B>/usr/local/lib/libodbc*S.so</B> libraries
183 where * signifies the database application, so
184 <B>/usr/local/lib/libodbcmyS.so</B> is the &quot;setup file&quot; for
185 MyODBC. The driver (not the setup file) is
186 <B>/usr/local/lib/libmyodbc-2.50.23.so. </B>
187 </P>
188 <P STYLE="margin-left: 0.79in; font-weight: medium">To set up the
189 driver, run ODBCConfig as root, go to the drivers tab and click on
190 &quot;New&quot;. The following are the settings I use...</P>
191 <P STYLE="margin-left: 0.79in"><B>Name: myodbc<BR>Description: MySQL
192 driver.<BR>Driver: /usr/local/lib/libmyodbc-2.50.23.so<BR>Setup:
193 /usr/local/lib/libodbcmyS.so</B><BR><B>FileUsage: 1</B></P>
194 <P STYLE="margin-left: 0.79in; font-weight: medium">You should have a
195 driver set up before setting up a DSN. After having done so, you may
196 want to set up a system DSN. You do this by selecting the &quot;System
197 DSN&quot; tab, clicking on 'New', specifying the driver to use and
198 filling in the required information. You will want to select the
199 driver name you just defined as the Driver in the first screen that
200 displays, and click OK.</P>
201 <P STYLE="margin-left: 0.79in; font-weight: medium">Doing this as
202 root will create and edit the <B>/usr/local/etc/odbcinst.ini</B> (for
203 the driver info) and <B>/usr/local/etc/odbc.ini</B> (for the system
204 DSN) files. Early versions of unixODBC would put these files in /etc,
205 and you can still use a configure option : <I>--sysconfdir=/etc</I>
206 to put those files in that location.</P>
207 <P STYLE="font-weight: medium"><B>Do this as a normal user:</B>
208 </P>
209 <P STYLE="margin-left: 0.79in">The process for setting up a user DSN
210 is identical to setting up a system DSN. You simply select the &quot;User
211 DSN&quot; tab in ODBCConfig and fill out the required fields. The
212 following is how I filled out a User DSN.</P>
213 <P STYLE="margin-left: 0.79in"><B>Name: mysqltest<BR>Description:
214 myodbc<BR>Driver: myodbc<BR>Trace: Yes<BR>TraceFile: mysql.log<BR>Host:
215 localhost<BR>Port: 3306<BR>Socket:<BR>Database: test</B></P>
216 <P STYLE="margin-left: 0.79in">This will create and edit a file named
217 ~/.odbc.ini . Since the test database comes without any tables, you
218 may want to specify mysql as the database instead, so you can see the
219 tables when running DataManager.</P>
220 <P><B>Run DataManager</B></P>
221 <P STYLE="margin-left: 0.79in">Now you should be able to run
222 DataManager and see your drivers, DSNs and tables for each DSN. See
223 the unixODBC web site for screen shots of what it should look like.
224 </P>
225 <P><B>OK, Now What ?</B></P>
226 <P STYLE="margin-left: 0.79in">UnixODBC is not so much an end user
227 program, but rather an intermediary between a program and one or more
228 databases. There is information in the unixODBC documentation for
229 example, about setting up StarOffice to use an ODBC connection. I am
230 in the process of writing a <A HREF="http://www.info2000.net/~cmorrison/databuilder.html">program</A>
231 that makes use of unixODBC and numerous others are as well. It may
232 well be that in time unixODBC will be included in numerous Linux
233 distributions and installed by default. Until that time I hope that
234 this document helps you get this software up and running.</P>
235 <P ALIGN=RIGHT STYLE="margin-left: 0.79in">Charles
236 Morrison<BR>[email protected]</P>
237 </BODY>
238 </HTML>