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