summaryrefslogtreecommitdiffstats
path: root/README_FILES/MYSQL_README
blob: 17699230adf0032d040ba8e8906cfe62ed53cad7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
PPoossttffiixx MMyySSQQLL HHoowwttoo

-------------------------------------------------------------------------------

IInnttrroodduuccttiioonn

The Postfix mysql map type allows you to hook up Postfix to a MySQL database.
This implementation allows for multiple mysql databases: you can use one for a
virtual(5) table, one for an access(5) table, and one for an aliases(5) table
if you want. You can specify multiple servers for the same database, so that
Postfix can switch to a good database server if one goes bad.

Busy mail servers using mysql maps will generate lots of concurrent mysql
clients, so the mysql server(s) should be run with this fact in mind. You can
reduce the number of concurrent mysql clients by using the Postfix proxymap(8)
service.

BBuuiillddiinngg PPoossttffiixx wwiitthh MMyySSQQLL ssuuppppoorrtt

These instructions assume that you build Postfix from source code as described
in the INSTALL document. Some modification may be required if you build Postfix
from a vendor-specific source package.

Note: to use mysql with Debian GNU/Linux's Postfix, all you need is to install
the postfix-mysql package and you're done. There is no need to recompile
Postfix.

The Postfix MySQL client utilizes the mysql client library, which can be
obtained from:

    http://www.mysql.com/downloads/

In order to build Postfix with mysql map support, you will need to add -
DHAS_MYSQL and -I for the directory containing the mysql headers, and the
mysqlclient library (and libm) to AUXLIBS_MYSQL, for example:

    make -f Makefile.init makefiles \
        "CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include" \
        "AUXLIBS_MYSQL=-L/usr/local/mysql/lib -lmysqlclient -lz -lm"

If your MySQL shared library is in a directory that the RUN-TIME linker does
not know about, add a "-Wl,-R,/path/to/directory" option after "-lmysqlclient".

Postfix versions before 3.0 use AUXLIBS instead of AUXLIBS_MYSQL. With Postfix
3.0 and later, the old AUXLIBS variable still supports building a statically-
loaded MySQL database client, but only the new AUXLIBS_MYSQL variable supports
building a dynamically-loaded or statically-loaded MySQL database client.

    Failure to use the AUXLIBS_MYSQL variable will defeat the purpose of
    dynamic database client loading. Every Postfix executable file will have
    MYSQL database library dependencies. And that was exactly what dynamic
    database client loading was meant to avoid.

On Solaris, use this instead:

    make -f Makefile.init makefiles \
        "CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include" \
        "AUXLIBS_MYSQL=-L/usr/local/mysql/lib -R/usr/local/mysql/lib \
            -lmysqlclient -lz -lm"

Then, just run 'make'. This requires libz, the compression library. Older mysql
implementations build without libz.

UUssiinngg MMyySSQQLL ttaabblleess

Once Postfix is built with mysql support, you can specify a map type in main.cf
like this:

    alias_maps = mysql:/etc/postfix/mysql-aliases.cf

The file /etc/postfix/mysql-aliases.cf specifies lots of information telling
Postfix how to reference the mysql database. For a complete description, see
the mysql_table(5) manual page.

EExxaammppllee:: llooccaall aalliiaasseess

#
# mysql config file for local(8) aliases(5) lookups
#

# The user name and password to log into the mysql server.
user = someone
password = some_password

# The database name on the servers.
dbname = customer_database

# For Postfix 2.2 and later The SQL query template.
# See mysql_table(5) for details.
query = SELECT forw_addr FROM mxaliases WHERE alias='%s' AND status='paid'

# For Postfix releases prior to 2.2. See mysql_table(5) for details.
select_field = forw_addr
table = mxaliases
where_field = alias
# Don't forget the leading "AND"!
additional_conditions = AND status = 'paid'

# This is necessary to make UTF8 queries work for Postfix 2.11 .. 3.1,
# and is the default setting as of Postfix 3.2.
option_group = client

AAddddiittiioonnaall nnootteess

Postfix 3.2 and later read [[cclliieenntt]] option group settings by default. To
disable this, specify no ooppttiioonn__ffiillee and specify "ooppttiioonn__ggrroouupp ==" (i.e. an
empty value).

Postfix 3.1 and earlier don't read [[cclliieenntt]] option group settings unless a non-
empty ooppttiioonn__ffiillee or ooppttiioonn__ggrroouupp value are specified. To enable this, specify,
for example "ooppttiioonn__ggrroouupp == cclliieenntt".

The MySQL configuration interface setup allows for multiple mysql databases:
you can use one for a virtual table, one for an access table, and one for an
aliases table if you want.

Since sites that have a need for multiple mail exchangers may enjoy the
convenience of using a networked mailer database, but do not want to introduce
a single point of failure to their system, we've included the ability to have
Postfix reference multiple hosts for access to a single mysql map. This will
work if sites set up mirrored mysql databases on two or more hosts. Whenever
queries fail with an error at one host, the rest of the hosts will be tried in
random order. If no mysql server hosts are reachable, then mail will be
deferred until at least one of those hosts is reachable.

CCrreeddiittss

  * The initial version was contributed by Scott Cotton and Joshua Marcus, IC
    Group, Inc.
  * Liviu Daia revised the configuration interface and added the main.cf
    configuration feature.
  * Liviu Daia with further refinements from Jose Luis Tallon and Victor
    Duchovni developed the common query, result_format, domain and
    expansion_limit interface for LDAP, MySQL and PostgreSQL.