]> git.sur5r.net Git - bacula/docs/blob - docs/manual/mysql.tex
af32170da4e9cba92f969994817dc31b2e58c901
[bacula/docs] / docs / manual / mysql.tex
1 %%
2 %%
3
4 \section*{Installing and Configuring MySQL}
5 \label{_ChapterStart}
6 \index[general]{MySQL!Installing and Configuring }
7 \index[general]{Installing and Configuring MySQL }
8 \addcontentsline{toc}{section}{Installing and Configuring MySQL}
9
10 \subsection*{Installing and Configuring MySQL -- Phase I}
11 \index[general]{Installing and Configuring MySQL -- Phase I }
12 \index[general]{Phase I!Installing and Configuring MySQL -- }
13 \addcontentsline{toc}{subsection}{Installing and Configuring MySQL -- Phase I}
14
15 If you use the ./configure \verb:--:with-mysql=mysql-directory statement for
16 configuring {\bf Bacula}, you will need MySQL version 3.23.53 or later
17 installed in the {\bf mysql-directory}.
18 Bacula has been tested on MySQL version 4.1.12 and works providing
19 you are running it in the default installation that is compatible
20 with MySQL 3.23.x.  If you are using one of the new modes such
21 as ANSI/ISO compatibility, you may experience problems.
22
23 If MySQL is installed in the standard system location, you need only enter
24 {\bf \verb:--:with-mysql} since the configure program will search all the
25 standard locations.  If you install MySQL in your home directory or some
26 other non-standard directory, you will need to provide the full path to it.
27
28 Installing and Configuring MySQL is not difficult but can be confusing the
29 first time. As a consequence, below, we list the steps that we used to install
30 it on our machines. Please note that our configuration leaves MySQL without
31 any user passwords. This may be an undesirable situation if you have other
32 users on your system. 
33
34 The notes below describe how to build MySQL from the source tar files. If
35 you have a pre-installed MySQL, you can return to complete the installation
36 of Bacula, then come back to Phase II of the MySQL installation.  If you
37 wish to install MySQL from rpms, you will probably need to install
38 the following:
39
40 \footnotesize
41 \begin{verbatim}
42 mysql-<version>.rpm
43 mysql-server-<version>.rpm
44 \end{verbatim}
45 \normalsize
46 Once these packages are installed, you will be able to build Bacula (using
47 the files installed with the mysql package, then run MySQL using the
48 files installed with mysql-server. If you have installed MySQL by rpms,
49 please skip Phase I below, and return to complete the installation of
50 Bacula, then come back to Phase II of the MySQL installation when indicated
51 to do so.
52
53 Beginning with Bacula version 1.31, the thread safe version of the
54 MySQL client library is used, and hence you must add the {\bf
55 \verb:--:enable-thread-safe-client} option to the {\bf ./configure} as shown below: 
56
57 \begin{enumerate}
58 \item Download MySQL source code from 
59    \elink{www.mysql.com/downloads}{http://www.mysql.com/downloads}  
60
61 \item Detar it with something like:
62
63    {\bf tar xvfz mysql-filename}  
64
65 Note, the above command requires GNU tar. If you do not  have GNU tar, a
66 command such as:
67
68 {\bf zcat mysql-filename | tar xvf - 
69
70 }  will probably accomplish the same thing. 
71
72 \item cd {\bf mysql-source-directory}
73
74    where you replace {\bf mysql-source-directory} with the  directory name where
75    you put the MySQL source code.  
76
77 \item ./configure \verb:--:enable-thread-safe-client \verb:--:prefix=mysql-directory
78
79    where you replace {\bf mysql-directory} with the directory  name where you
80    want to install mysql. Normally for system  wide use this is /usr/local/mysql.
81    In my case, I use  \~{}kern/mysql.  
82
83 \item make
84
85    This takes a bit of time.  
86
87 \item make install
88
89    This will put all the necessary binaries, libraries and support  files into
90    the {\bf mysql-directory} that you specified above.  
91
92 \item ./scripts/mysql\_install\_db
93
94    This will create the necessary MySQL databases for controlling  user access.
95 Note, this script can also be found in the  {\bf bin} directory in the
96 installation directory 
97
98 \end{enumerate}
99
100 The MySQL client library {\bf mysqlclient} requires the gzip compression
101 library {\bf libz.a} or {\bf libz.so}. If you are using rpm packages, these
102 libraries are in the {\bf libz-devel} package. On Debian systems, you will
103 need to load the {\bf zlib1g-dev} package. If you are not using rpms or debs,
104 you will need to find the appropriate package for your system. 
105
106 At this point, you should return to completing the installation of {\bf
107 Bacula}. Later after Bacula is installed, come back to this chapter to
108 complete the installation. Please note, the installation files used in the
109 second phase of the MySQL installation are created during the Bacula
110 Installation. 
111
112 \label{mysql_phase2}
113 \subsection*{Installing and Configuring MySQL -- Phase II}
114 \index[general]{Installing and Configuring MySQL -- Phase II }
115 \index[general]{Phase II!Installing and Configuring MySQL -- }
116 \addcontentsline{toc}{subsection}{Installing and Configuring MySQL -- Phase
117 II}
118
119 At this point, you should have built and installed MySQL, or already have a
120 running MySQL, and you should have configured, built and installed {\bf
121 Bacula}. If not, please complete these items before proceeding. 
122
123 Please note that the {\bf ./configure} used to build {\bf Bacula} will need to
124 include {\bf \verb:--:with-mysql=mysql-directory}, where {\bf mysql-directory} is the
125 directory name that you specified on the ./configure command for configuring
126 MySQL. This is needed so that Bacula can find the necessary include headers
127 and library files for interfacing to MySQL. 
128
129 {\bf Bacula} will install scripts for manipulating the database (create,
130 delete, make tables etc) into the main installation directory. These files
131 will be of the form *\_bacula\_* (e.g. create\_bacula\_database). These files
132 are also available in the \lt{}bacula-src\gt{}/src/cats directory after
133 running ./configure. If you inspect create\_bacula\_database, you will see
134 that it calls create\_mysql\_database. The *\_bacula\_* files are provided for
135 convenience. It doesn't matter what database you have chosen;
136 create\_bacula\_database will always create your database. 
137
138 Now you will create the Bacula MySQL database and the tables that Bacula uses.
139
140
141 \begin{enumerate}
142 \item Start {\bf mysql}. You might want to use the {\bf startmysql}  script
143    provided in the Bacula release.  
144
145 \item cd \lt{}install-directory\gt{}
146    This directory contains the Bacula catalog  interface routines.  
147
148 \item ./grant\_mysql\_privileges
149    This script creates unrestricted access rights for the user {\bf bacula}. 
150    You may  want to modify it to suit your situation. Please
151    note that none of the userids, including root, are password protected.  
152    If you need more security, please assign a password to the root user
153    and to bacula. The program {\bf mysqladmin} can be used for this.
154
155 \item ./create\_mysql\_database
156    This script creates the MySQL {\bf bacula} database.  The databases you
157    create as well as the access databases will be located in
158    \lt{}install-dir\gt{}/var/ in a subdirectory with the name of the
159    database, where \lt{}install-dir\gt{} is the directory name that you
160    specified on the {\bf \verb:--:prefix} option.  This can be important to
161    know if you want to make a special backup of the Bacula database or to
162    check its size.
163
164 \item ./make\_mysql\_tables
165    This script creates the MySQL tables used by {\bf Bacula}. 
166 \end{enumerate}
167
168 Each of the three scripts (grant\_mysql\_privileges, create\_mysql\_database
169 and make\_mysql\_tables) allows the addition of a command line argument. This
170 can be useful for specifying the user and or password. For example, you might
171 need to add {\bf -u root} to the command line to have sufficient privilege to
172 create the Bacula tables. 
173
174 To take a closer look at the access privileges that you have setup with the
175 above, you can do: 
176
177 \footnotesize
178 \begin{verbatim}
179 mysql-directory/bin/mysql -u root mysql
180 select * from user;
181 \end{verbatim}
182 \normalsize
183
184 \subsection*{Re-initializing the Catalog Database}
185 \index[general]{Database!Re-initializing the Catalog }
186 \index[general]{Re-initializing the Catalog Database }
187 \addcontentsline{toc}{subsection}{Re-initializing the Catalog Database}
188
189 After you have done some initial testing with {\bf Bacula}, you will probably
190 want to re-initialize the catalog database and throw away all the test Jobs
191 that you ran. To do so, you can do the following: 
192
193 \footnotesize
194 \begin{verbatim}
195   cd <install-directory>
196   ./drop_mysql_tables
197   ./make_mysql_tables
198 \end{verbatim}
199 \normalsize
200
201 Please note that all information in the database will be lost and you will be
202 starting from scratch. If you have written on any Volumes, you must write an
203 end of file mark on the volume so that Bacula can reuse it. Do so with: 
204
205 \footnotesize
206 \begin{verbatim}
207    (stop Bacula or unmount the drive)
208    mt -f /dev/nst0 rewind
209    mt -f /dev/nst0 weof
210 \end{verbatim}
211 \normalsize
212
213 Where you should replace {\bf /dev/nst0} with the appropriate tape drive
214 device name for your machine. 
215
216 \subsection*{Linking Bacula with MySQL}
217 \index[general]{Linking Bacula with MySQL }
218 \index[general]{MySQL!Linking Bacula with }
219 \addcontentsline{toc}{subsection}{Linking Bacula with MySQL}
220
221 After configuring Bacula with 
222
223 ./configure \verb:--:enable-thread-safe-client \verb:--:prefix=\lt{}mysql-directory\gt{}
224 where \lt{}mysql-directory\gt{} is in my case {\bf /home/kern/mysql}, you may
225 have to configure the loader so that it can find the MySQL shared libraries.
226 If you have previously followed this procedure and later add the {\bf
227 \verb:--:enable-thread-safe-client} options, you will need to rerun the {\bf
228 ldconfig} program shown below. If you put MySQL in a standard place such as
229 {\bf /usr/lib} or {\bf /usr/local/lib} this will not be necessary, but in my
230 case it is. The description that follows is Linux specific. For other
231 operating systems, please consult your manuals on how to do the same thing: 
232
233 First edit: {\bf /etc/ld.so.conf} and add a new line to the end of the file
234 with the name of the mysql-directory. In my case, it is: 
235
236 /home/kern/mysql/lib/mysql then rebuild the loader's cache with: 
237
238 /sbin/ldconfig If you upgrade to a new version of {\bf MySQL}, the shared
239 library names will probably change, and you must re-run the {\bf
240 /sbin/ldconfig} command so that the runtime loader can find them. 
241
242 Alternatively, your system my have a loader environment variable that can be
243 set. For example, on a Solaris system where I do not have root permission, I
244 use: 
245
246 LD\_LIBRARY\_PATH=/home/kern/mysql/lib/mysql 
247
248 Finally, if you have encryption enabled in MySQL, you may need to add {\bf
249 -lssl -lcrypto} to the link. In that case, you can either export the
250 appropriate LDFLAGS definition, or alternatively, you can include them
251 directly on the ./configure line as in: 
252
253 \footnotesize
254 \begin{verbatim}
255 LDFLAGS="-lssl -lcyrpto" \
256    ./configure \
257       <your-options>
258 \end{verbatim}
259 \normalsize
260
261 \subsection*{Installing MySQL from RPMs}
262 \index[general]{MySQL!Installing from RPMs}
263 \index[general]{Installing MySQL from RPMs}
264 \addcontentsline{toc}{subsection}{Installing MySQL from RPMs}
265 If you are installing MySQL from RPMs, you will need to install
266 both the MySQL binaries and the client libraries.  The client
267 libraries are ususally found in a devel package, so you must
268 install:
269
270 \footnotesize
271 \begin{verbatim}
272   mysql
273   mysql-devel
274 \end{verbatim}
275 \normalsize
276
277 This will be the same with most other package managers too.
278
279 \subsection*{Upgrading MySQL}
280 \index[general]{Upgrading MySQL }
281 \index[general]{Upgrading!MySQL }
282 \addcontentsline{toc}{subsection}{Upgrading MySQL}
283 If you upgrade MySQL, you must reconfigure, rebuild, and re-install 
284 Bacula otherwise you are likely to get bizarre failures.  If you
285 install from rpms and you upgrade MySQL, you must also rebuild Bacula.
286 You can do so by rebuilding from the source rpm. To do so, you may need
287 to modify the bacula.spec file to account for the new MySQL version.