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