128263Spst#++
228263Spst# NAME
350472Speter#	mysql_table 5
428263Spst# SUMMARY
561981Sbrian#	Postfix MySQL client configuration
661981Sbrian# SYNOPSIS
728263Spst#	\fBpostmap -q "\fIstring\fB" mysql:/etc/postfix/filename\fR
861981Sbrian#
961981Sbrian#	\fBpostmap -q - mysql:/etc/postfix/\fIfilename\fR <\fIinputfile\fR
1061981Sbrian# DESCRIPTION
1161981Sbrian#	The Postfix mail system uses optional tables for address
1261981Sbrian#	rewriting or mail routing. These tables are usually in
1361981Sbrian#	\fBdbm\fR or \fBdb\fR format.
1461981Sbrian#
1528320Spst#	Alternatively, lookup tables can be specified as MySQL databases.
1661981Sbrian#	In order to use MySQL lookups, define a MySQL source as a lookup
1761981Sbrian#	table in main.cf, for example:
1861981Sbrian# .nf
1961981Sbrian#	    alias_maps = mysql:/etc/mysql-aliases.cf
2061981Sbrian# .fi
2161981Sbrian#
2261981Sbrian#	The file /etc/postfix/mysql-aliases.cf has the same format as
2361981Sbrian#	the Postfix main.cf file, and can specify the parameters
2461981Sbrian#	described below.
2561981Sbrian# BACKWARDS COMPATIBILITY
2661981Sbrian# .ad
2761981Sbrian# .fi
2861981Sbrian#	For compatibility with other Postfix lookup tables, MySQL
2961981Sbrian#	parameters can also be defined in main.cf.  In order to do that,
3061981Sbrian#	specify as MySQL source a name that doesn't begin with a slash
3161981Sbrian#	or a dot.  The MySQL parameters will then be accessible as the
3261981Sbrian#	name you've given the source in its definition, an underscore,
3361981Sbrian#	and the name of the parameter.	For example, if the map is
3461981Sbrian#	specified as "mysql:\fImysqlname\fR", the parameter "hosts"
35#	below would be defined in main.cf as "\fImysqlname\fR_hosts".
36#
37#	Note: with this form, the passwords for the MySQL sources are
38#	written in main.cf, which is normally world-readable.  Support
39#	for this form will be removed in a future Postfix version.
40#
41#	Normally, the SQL query is specified via a single \fBquery\fR
42#	parameter (described in more detail below).  When this
43#	parameter is not specified in the map definition, Postfix
44#	reverts to an older interface, with the SQL query constructed
45#	from the \fBselect_field\fR, \fBtable\fR, \fBwhere_field\fR
46#	and \fBadditional_conditions\fR parameters.  The old interface
47#	will be gradually phased out. To migrate to the new interface
48#	set:
49#
50# .nf
51#	    \fBquery\fR = SELECT [\fIselect_field\fR]
52#	        FROM [\fItable\fR]
53#	        WHERE [\fIwhere_field\fR] = '%s'
54#	            [\fIadditional_conditions\fR]
55# .fi
56#
57#	Insert the value, not the name, of each legacy parameter. Note
58#	that the \fBadditional_conditions\fR parameter is optional
59#	and if not empty, will always start with \fBAND\fR.
60# LIST MEMBERSHIP
61# .ad
62# .fi
63#	When using SQL to store lists such as $mynetworks,
64#	$mydestination, $relay_domains, $local_recipient_maps,
65#	etc., it is important to understand that the table must
66#	store each list member as a separate key. The table lookup
67#	verifies the *existence* of the key. See "Postfix lists
68#	versus tables" in the DATABASE_README document for a
69#	discussion.
70#
71#	Do NOT create tables that return the full list of domains
72#	in $mydestination or $relay_domains etc., or IP addresses
73#	in $mynetworks.
74#
75#	DO create tables with each matching item as a key and with
76#	an arbitrary value. With SQL databases it is not uncommon to
77#	return the key itself or a constant value.
78# MYSQL PARAMETERS
79# .ad
80# .fi
81# .IP "\fBhosts\fR"
82#	The hosts that Postfix will try to connect to and query from.
83#	Specify \fIunix:\fR for UNIX domain sockets, \fIinet:\fR for TCP
84#	connections (default).  Example:
85# .nf
86#	    hosts = host1.some.domain host2.some.domain
87#	    hosts = unix:/file/name
88# .fi
89#
90#	The hosts are tried in random order, with all connections over
91#	UNIX domain sockets being tried before those over TCP.	The
92#	connections are automatically closed after being idle for about
93#	1 minute, and are re-opened as necessary. Postfix versions 2.0
94#	and earlier do not randomize the host order.
95#
96#	NOTE: if you specify localhost as a hostname (even if you
97#	prefix it with \fIinet:\fR), MySQL will connect to the default
98#	UNIX domain socket.  In order to instruct MySQL to connect to
99#	localhost over TCP you have to specify
100# .nf
101#	    hosts = 127.0.0.1
102# .fi
103# .IP "\fBuser, password\fR"
104#	The user name and password to log into the mysql server.
105#	Example:
106# .nf
107#	    user = someone
108#	    password = some_password
109# .fi
110# .IP "\fBdbname\fR"
111#	The database name on the servers. Example:
112# .nf
113#	    dbname = customer_database
114# .fi
115# .IP "\fBquery\fR"
116#	The SQL query template used to search the database, where \fB%s\fR
117#	is a substitute for the address Postfix is trying to resolve,
118#	e.g.
119# .nf
120#	    query = SELECT replacement FROM aliases WHERE mailbox = '%s'
121# .fi
122#
123#	This parameter supports the following '%' expansions:
124# .RS
125# .IP "\fB\fB%%\fR\fR"
126#	This is replaced by a literal '%' character.
127# .IP "\fB\fB%s\fR\fR"
128#	This is replaced by the input key.
129#	SQL quoting is used to make sure that the input key does not
130#	add unexpected metacharacters.
131# .IP "\fB\fB%u\fR\fR"
132#	When the input key is an address of the form user@domain, \fB%u\fR
133#	is replaced by the SQL quoted local part of the address.
134#	Otherwise, \fB%u\fR is replaced by the entire search string.
135#	If the localpart is empty, the query is suppressed and returns
136#	no results.
137# .IP "\fB\fB%d\fR\fR"
138#	When the input key is an address of the form user@domain, \fB%d\fR
139#	is replaced by the SQL quoted domain part of the address.
140#	Otherwise, the query is suppressed and returns no results.
141# .IP "\fB\fB%[SUD]\fR\fR"
142#	The upper-case equivalents of the above expansions behave in the
143#	\fBquery\fR parameter identically to their lower-case counter-parts.
144#	With the \fBresult_format\fR parameter (see below), they expand the
145#	input key rather than the result value.
146# .IP "\fB\fB%[1-9]\fR\fR"
147#	The patterns %1, %2, ... %9 are replaced by the corresponding
148#	most significant component of the input key's domain. If the
149#	input key is \fIuser@mail.example.com\fR, then %1 is \fBcom\fR,
150#	%2 is \fBexample\fR and %3 is \fBmail\fR. If the input key is
151#	unqualified or does not have enough domain components to satisfy
152#	all the specified patterns, the query is suppressed and returns
153#	no results.
154# .RE
155# .IP
156#	The \fBdomain\fR parameter described below limits the input
157#	keys to addresses in matching domains. When the \fBdomain\fR
158#	parameter is non-empty, SQL queries for unqualified addresses
159#	or addresses in non-matching domains are suppressed
160#	and return no results.
161#
162#	This parameter is available with Postfix 2.2. In prior releases
163#	the SQL query was built from the separate parameters:
164#	\fBselect_field\fR, \fBtable\fR, \fBwhere_field\fR and
165#	\fBadditional_conditions\fR. The mapping from the old parameters
166#	to the equivalent query is:
167#
168# .nf
169#	    SELECT [\fBselect_field\fR]
170#	    FROM [\fBtable\fR]
171#	    WHERE [\fBwhere_field\fR] = '%s'
172#	          [\fBadditional_conditions\fR]
173# .fi
174#
175#	The '%s' in the \fBWHERE\fR clause expands to the escaped search string.
176#	With Postfix 2.2 these legacy parameters are used if the \fBquery\fR
177#	parameter is not specified.
178#
179#	NOTE: DO NOT put quotes around the query parameter.
180# .IP "\fBresult_format (default: \fB%s\fR)\fR"
181#	Format template applied to result attributes. Most commonly used
182#	to append (or prepend) text to the result. This parameter supports
183#	the following '%' expansions:
184# .RS
185# .IP "\fB\fB%%\fR\fR"
186#	This is replaced by a literal '%' character.
187# .IP "\fB\fB%s\fR\fR"
188#	This is replaced by the value of the result attribute. When
189#	result is empty it is skipped.
190# .IP "\fB%u\fR
191#	When the result attribute value is an address of the form
192#	user@domain, \fB%u\fR is replaced by the local part of the
193#	address. When the result has an empty localpart it is skipped.
194# .IP "\fB\fB%d\fR\fR"
195#	When a result attribute value is an address of the form
196#	user@domain, \fB%d\fR is replaced by the domain part of
197#	the attribute value. When the result is unqualified it
198#	is skipped.
199# .IP "\fB\fB%[SUD1-9]\fR\fB"
200#	The upper-case and decimal digit expansions interpolate
201#	the parts of the input key rather than the result. Their
202#	behavior is identical to that described with \fBquery\fR,
203#	and in fact because the input key is known in advance, queries
204#	whose key does not contain all the information specified in
205#	the result template are suppressed and return no results.
206# .RE
207# .IP
208#	For example, using "result_format = smtp:[%s]" allows one
209#	to use a mailHost attribute as the basis of a transport(5)
210#	table. After applying the result format, multiple values
211#	are concatenated as comma separated strings. The expansion_limit
212#	and parameter explained below allows one to restrict the number
213#	of values in the result, which is especially useful for maps that
214#	must return at most one value.
215#
216#	The default value \fB%s\fR specifies that each result value should
217#	be used as is.
218#
219#	This parameter is available with Postfix 2.2 and later.
220#
221#	NOTE: DO NOT put quotes around the result format!
222# .IP "\fBdomain (default: no domain list)\fR"
223#	This is a list of domain names, paths to files, or
224#	dictionaries. When specified, only fully qualified search
225#	keys with a *non-empty* localpart and a matching domain
226#	are eligible for lookup: 'user' lookups, bare domain lookups
227#	and "@domain" lookups are not performed. This can significantly
228#	reduce the query load on the MySQL server.
229# .nf
230#	    domain = postfix.org, hash:/etc/postfix/searchdomains
231# .fi
232#
233#	It is best not to use SQL to store the domains eligible
234#	for SQL lookups.
235#
236#	This parameter is available with Postfix 2.2 and later.
237#
238#	NOTE: DO NOT define this parameter for local(8) aliases,
239#	because the input keys are always unqualified.
240# .IP "\fBexpansion_limit (default: 0)\fR"
241#	A limit on the total number of result elements returned
242#	(as a comma separated list) by a lookup against the map.
243#	A setting of zero disables the limit. Lookups fail with a
244#	temporary error if the limit is exceeded.  Setting the
245#	limit to 1 ensures that lookups do not return multiple
246#	values.
247# OBSOLETE QUERY INTERFACE
248# .ad
249# .fi
250#	This section describes an interface that is deprecated as
251#	of Postfix 2.2. It is replaced by the more general \fBquery\fR
252#	interface described above.  If the \fBquery\fR parameter
253#	is defined, the legacy parameters described here ignored.
254#	Please migrate to the new interface as the legacy interface
255#	may be removed in a future release.
256#
257#	The following parameters can be used to fill in a
258#	SELECT template statement of the form:
259#
260# .nf
261#	    SELECT [\fBselect_field\fR]
262#	    FROM [\fBtable\fR]
263#	    WHERE [\fBwhere_field\fR] = '%s'
264#	          [\fBadditional_conditions\fR]
265# .fi
266#
267#	The specifier %s is replaced by the search string, and is
268#	escaped so if it contains single quotes or other odd characters,
269#	it will not cause a parse error, or worse, a security problem.
270# .IP "\fBselect_field\fR"
271#	The SQL "select" parameter. Example:
272# .nf
273#	    \fBselect_field\fR = forw_addr
274# .fi
275# .IP "\fBtable\fR"
276#	The SQL "select .. from" table name. Example:
277# .nf
278#	    \fBtable\fR = mxaliases
279# .fi
280# .IP "\fBwhere_field\fR
281#	The SQL "select .. where" parameter. Example:
282# .nf
283#	    \fBwhere_field\fR = alias
284# .fi
285# .IP "\fBadditional_conditions\fR
286#	Additional conditions to the SQL query. Example:
287# .nf
288#	    \fBadditional_conditions\fR = AND status = 'paid'
289# .fi
290# SEE ALSO
291#	postmap(1), Postfix lookup table maintenance
292#	postconf(5), configuration parameters
293#	ldap_table(5), LDAP lookup tables
294#	pgsql_table(5), PostgreSQL lookup tables
295#	sqlite_table(5), SQLite lookup tables
296# README FILES
297# .ad
298# .fi
299#	Use "\fBpostconf readme_directory\fR" or
300#	"\fBpostconf html_directory\fR" to locate this information.
301# .na
302# .nf
303#	DATABASE_README, Postfix lookup table overview
304#	MYSQL_README, Postfix MYSQL client guide
305# LICENSE
306# .ad
307# .fi
308#	The Secure Mailer license must be distributed with this software.
309# HISTORY
310#	MySQL support was introduced with Postfix version 1.0.
311# AUTHOR(S)
312#	Original implementation by:
313#	Scott Cotton, Joshua Marcus
314#	IC Group, Inc.
315#
316#	Further enhancements by:
317#	Liviu Daia
318#	Institute of Mathematics of the Romanian Academy
319#	P.O. BOX 1-764
320#	RO-014700 Bucharest, ROMANIA
321#--
322