xref: /netbsd-src/external/ibm-public/postfix/dist/proto/MYSQL_README.html (revision 059c16a85b0b39d60ad6d18f53c09510815afa2b)
1<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"
2        "http://www.w3.org/TR/html4/loose.dtd">
3
4<html>
5
6<head>
7
8<title>Postfix MySQL Howto</title>
9
10<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
11<link rel='stylesheet' type='text/css' href='postfix-doc.css'>
12
13</head>
14
15<body>
16
17<h1><img src="postfix-logo.jpg" width="203" height="98" ALT="">Postfix MySQL Howto</h1>
18
19<hr>
20
21<h2>Introduction</h2>
22
23<p> The Postfix mysql map type allows you to hook up Postfix to a
24MySQL database. This implementation allows for multiple mysql
25databases: you can use one for a virtual(5) table, one for an
26access(5) table, and one for an aliases(5) table if you want.  You
27can specify multiple servers for the same database, so that Postfix
28can switch to a good database server if one goes bad.  </p>
29
30<p> Busy mail servers using mysql maps will generate lots of
31concurrent mysql clients, so the mysql server(s) should be run with
32this fact in mind.  You can reduce the number of concurrent mysql
33clients by using the Postfix proxymap(8) service. </p>
34
35<h2>Building Postfix with MySQL support</h2>
36
37<p> These instructions assume that you build Postfix from source
38code as described in the INSTALL document. Some modification may
39be required if you build Postfix from a vendor-specific source
40package.  </p>
41
42<p> Note: to use mysql with Debian GNU/Linux's Postfix, all you
43need is to install the postfix-mysql package and you're done.
44There is no need to recompile Postfix. </p>
45
46<p> The Postfix MySQL client utilizes the mysql client library,
47which can be obtained from: </p>
48
49<blockquote>
50    <p> http://www.mysql.com/downloads/ </p>
51</blockquote>
52
53<p> In order to build Postfix with mysql map support, you will need to add
54-DHAS_MYSQL and -I for the directory containing the mysql headers, and
55the mysqlclient library (and libm) to AUXLIBS_MYSQL, for example: </p>
56
57<blockquote>
58<pre>
59make -f Makefile.init makefiles \
60    "CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include" \
61    "AUXLIBS_MYSQL=-L/usr/local/mysql/lib -lmysqlclient -lz -lm"
62</pre>
63</blockquote>
64
65<p> If your MySQL shared library is in a directory that the RUN-TIME
66linker does not know about, add a "-Wl,-R,/path/to/directory" option after
67"-lmysqlclient". </p>
68
69<p> Postfix versions before 3.0 use AUXLIBS instead of AUXLIBS_MYSQL.
70With Postfix 3.0 and later, the old AUXLIBS variable still supports
71building a statically-loaded MySQL database client, but only the new
72AUXLIBS_MYSQL variable supports building a dynamically-loaded or
73statically-loaded MySQL database client.  </p>
74
75<blockquote>
76
77<p> Failure to use the AUXLIBS_MYSQL variable will defeat the purpose
78of dynamic database client loading. Every Postfix executable file
79will have MYSQL database library dependencies. And that was exactly
80what dynamic database client loading was meant to avoid. </p>
81
82</blockquote>
83
84<p> On Solaris, use this instead: </p>
85
86<blockquote>
87<pre>
88make -f Makefile.init makefiles \
89    "CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include" \
90    "AUXLIBS_MYSQL=-L/usr/local/mysql/lib -R/usr/local/mysql/lib \
91        -lmysqlclient -lz -lm"
92</pre>
93</blockquote>
94
95<p> Then, just run 'make'. This requires libz, the compression
96library.  Older mysql implementations build without libz. </p>
97
98<h2>Using MySQL tables</h2>
99
100<p> Once Postfix is built with mysql support, you can specify a
101map type in main.cf like this: </p>
102
103<blockquote>
104<pre>
105alias_maps = mysql:/etc/postfix/mysql-aliases.cf
106</pre>
107</blockquote>
108
109<p> The file /etc/postfix/mysql-aliases.cf specifies lots of
110information telling Postfix how to reference the mysql database.
111For a complete description, see the mysql_table(5) manual page. </p>
112
113<h2>Example: local aliases </h2>
114
115<pre>
116#
117# mysql config file for local(8) aliases(5) lookups
118#
119
120# The user name and password to log into the mysql server.
121user = someone
122password = some_password
123
124# The database name on the servers.
125dbname = customer_database
126
127# For Postfix 2.2 and later The SQL query template.
128# See mysql_table(5) for details.
129query = SELECT forw_addr FROM mxaliases WHERE alias='%s' AND status='paid'
130
131# For Postfix releases prior to 2.2. See mysql_table(5) for details.
132select_field = forw_addr
133table = mxaliases
134where_field = alias
135# Don't forget the leading "AND"!
136additional_conditions = AND status = 'paid'
137
138# This is necessary to make UTF8 queries work for Postfix 2.11 .. 3.1,
139# and is the default setting as of Postfix 3.2.
140option_group = client
141</pre>
142
143<h2>Additional notes</h2>
144
145<p> Postfix 3.2 and later read <b>[client]</b> option group settings
146by default. To disable this, specify no <b>option_file</b> and
147specify "<b>option_group =</b>" (i.e. an empty value).  </p>
148
149<p> Postfix 3.1 and earlier don't read <b>[client]</b> option group
150settings unless a non-empty <b>option_file</b> or <b>option_group</b>
151value are specified. To enable this, specify, for example
152"<b>option_group = client</b>".  </p>
153
154<p> The MySQL configuration interface setup allows for multiple
155mysql databases: you can use one for a virtual table, one for an
156access table, and one for an aliases table if you want. </p>
157
158<p> Since sites that have a need for multiple mail exchangers may
159enjoy the convenience of using a networked mailer database, but do
160not want to introduce a single point of failure to their system,
161we've included the ability to have Postfix reference multiple hosts
162for access to a single mysql map.  This will work if sites set up
163mirrored mysql databases on two or more hosts.  Whenever queries
164fail with an error at one host, the rest of the hosts will be tried
165in random order.  If no mysql server hosts are reachable, then mail
166will be deferred until at least one of those hosts is reachable.
167</p>
168
169<h2>Credits</h2>
170
171<ul>
172
173<li> The initial version was contributed by Scott Cotton and Joshua
174Marcus, IC Group, Inc.</li>
175
176<li> Liviu Daia revised the configuration interface and added the
177main.cf configuration feature.</li>
178
179<li> Liviu Daia with further refinements from Jose Luis Tallon and
180Victor Duchovni developed the common query, result_format, domain and
181expansion_limit interface for LDAP, MySQL and PostgreSQL.</li>
182
183</ul>
184
185</body>
186
187</html>
188