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