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