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