Setting up bayes with SpamAssassin 3.x, using a MySQL database

Bits taken from the mailing list and Paul Westbrook's experiences.

You can find the database definitions for AWL and bayes here: http://spamassassin.apache.org/full/3.0.x/dist/sql/ (or as part of your 3.0 package).

If you are using MySQL 4.x, I would advise you to change the tables from type MyISAM to InnoDB to improve the locking speed.

Create the tables required with commands such as the following: (Note: Maia has shipped with these tables in its schema for some time now)

  • mysql -u root maia -p < awl_mysql.sql
  • mysql -u root maia -p < bayes_mysql.sql

Backup up the bayesian databases with a command like the following: sa-learn --backup > backup.txt

Next, add the following lines to the file /etc/mail/spamassassin/local.cf

#--local.cf--
use_bayes 1
bayes_store_module                Mail::SpamAssassin::BayesStore::SQL
bayes_sql_dsn                     DBI:mysql:maia
bayes_sql_username                amavis
bayes_sql_password                YourMaiaPass
auto_whitelist_factory            Mail::SpamAssassin::SQLBasedAddrList
user_awl_dsn                      DBI:mysql:maia
user_awl_sql_username             amavis
user_awl_sql_password             YourMaiaPass
#--end local.cf---

Add the bayes database to the newly created SQL tables: sa-learn --restore backup.txt

Test that SpamAssassin can connect to the bayes SQL database:

amavis:$ spamassassin -tD < sample-spam.txt  2>&1  | grep -i database
debug: bayes: Database connection established

If you see output such as the above, restart amavisd-new. Your Amavisd-Maia / SpamAssassin 3 installation should now be set-up to use SQL based bayes. Congrats. :)


Back to FAQ