---
name: "Mail::SpamAssassin::BayesStore::MySQL"
section: "3pm"
platform: "linux"
package: "spamassassin"
version: "4.0.2-3"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/Mail::SpamAssassin::BayesStore::MySQL"
---

# Mail::SpamAssassin::BayesStore::MySQL(3pm)

MySQL Specific Bayesian Storage Module Implementation

## NAME

Mail::SpamAssassin::BayesStore::MySQL - MySQL Specific Bayesian Storage Module Implementation

## DESCRIPTION

This module implements a MySQL specific based bayesian storage module.  It requires that you are running at least version 4.1 of MySQL, if you are running a version of MySQL \< 4.1 then several aspects of this module will fail and possibly corrupt your bayes database data.

In addition, this module will support rollback on error, if you are using the InnoDB database table type in MySQL.  For more information please review the instructions in sql/README.bayes.

This module is also compatible with MariaDB and DBD::MariaDB can be used instead of DBD::mysql driver.

## METHODS

### token\_expiration

public instance (Integer, Integer,\
                  Integer, Integer) token\_expiration(\\% `$opts`,\
                                                     Integer `$newdelta`,\
                                                     @ `@vars`)

Description: This method performs the database specific expiration of tokens based on the passed in `$newdelta` and `@vars`.

### seen\_put

public (Boolean) seen\_put (string `$msgid`, char `$flag`)

Description: This method records `$msgid` as the type given by `$flag`.  `$flag` is one of two values 's' for spam and 'h' for ham.

### seen\_delete

public instance (Boolean) seen\_delete (string `$msgid`)

Description: This method removes `$msgid` from the database.

### set\_last\_expire

public instance (Boolean) set\_last\_expire (Integer `$time`)

Description: This method sets the last expire time.

### set\_running\_expire\_tok

public instance (String `$time`) set\_running\_expire\_tok ()

Description: This method sets the time that an expire starts running.

### remove\_running\_expire\_tok

public instance (Boolean) remove\_running\_expire\_tok ()

Description: This method removes the row in the database that indicates that and expire is currently running.

### tok\_get

public instance (Integer, Integer, Integer) tok\_get (String `$token`)

Description: This method retrieves a specified token (`$token`) from the database and returns it's spam\_count, ham\_count and last access time.

### tok\_get\_all

public instance (\\@) tok\_get (@ `$tokens`)

Description: This method retrieves the specified tokens (`$tokens`) from storage and returns an array ref of arrays spam count, ham count and last access time.

### nspam\_nham\_change

public instance (Boolean) nspam\_nham\_change (Integer `$num_spam`,\
                                              Integer `$num_ham`)

Description: This method updates the number of spam and the number of ham in the database.

### tok\_touch

public instance (Boolean) tok\_touch (String `$token`,\
                                      String `$atime`)

Description: This method updates the given tokens (`$token`) atime.

The assumption is that the token already exists in the database.

### tok\_touch\_all

public instance (Boolean) tok\_touch (\\@ `$tokens`\
                                      String `$atime`)

Description: This method does a mass update of the given list of tokens `$tokens`, if the existing token atime is \< `$atime`.

The assumption is that the tokens already exist in the database.

We should never be touching more than N\_SIGNIFICANT\_TOKENS, so we can make some assumptions about how to handle the data (ie no need to batch like we do in tok\_get\_all)

### cleanup

public instance (Boolean) cleanup ()

Description: This method performs any cleanup necessary before moving onto the next operation.

### clear\_database

public instance (Boolean) clear\_database ()

Description: This method deletes all records for a particular user.

Callers should be aware that any errors returned by this method could causes the database to be inconsistent for the given user.

## Private Methods

### \_connect\_db

private instance (Boolean) \_connect\_db ()

Description: This method connects to the SQL database.

### \_initialize\_db

private instance (Boolean) \_initialize\_db ()

Description: This method will check to see if a user has had their bayes variables initialized. If not then it will perform this initialization.

### \_put\_token

private instance (Boolean) \_put\_token (string `$token`,\
                                        integer `$spam_count`,\
                                        integer `$ham_count`,\
 				       string `$atime`)

Description: This method performs the work of either inserting or updating a token in the database.

### \_put\_tokens

private instance (Boolean) \_put\_tokens (\\% `$tokens`,\
                                         integer `$spam_count`,\
                                         integer `$ham_count`,\
 			 	        string `$atime`)

Description: This method performs the work of either inserting or updating tokens in the database.

### \_token\_select\_string

private instance (String) \_token\_select\_string

Description: This method returns the string to be used in SELECT statements to represent the token column.

The default is to use the RPAD function to pad the token out to 5 characters.
