Score:0

Postfixadmin can't connect to mysql database (MariaDB)

im flag

I am trying to make my own mail service using Postfix, but I run into an issue in the setup phase, and it's that postfix can't connect to the database. Here's what the error log says:

⛔Database connection string : mysql:host=localhost;dbname=postfixadmindb;charset=UTF8
⛔Problem connecting to database, check database configuration ($CONF['database_*'] entries in config.local.php)
⛔SQLSTATE[HY000] [2002] Permission denied

Here's the config file:

<?php
        $CONF['database_type'] = 'mysqli';
        $CONF['database_host'] = 'localhost';
        $CONF['database_user'] = 'postfixuser';
        $CONF['database_password'] = 'XXXXXXXX';
        $CONF['database_name'] = 'postfixadmindb';
        $CONF['configured'] = true;
        $CONF['encrypt'] = 'md5crypt';
        $CONF['setup_password'] = 'the setup password';
?>

First of all, I tried connecting to the database normally:
sudo mysql -u postfixuser -p'thecorrectpassword' -h localhost postfixadmindb
This works fine and brings me tho the MariaDB shell as expected
I then granted postfixuser all privileges in the database, but that didn't solve the issue.
I checked the log under /var/log/mysql/error.log but it's empty

I'm doing this on a WSL machine running Ubuntu 22.04.1 LTS, serving the postfixadmin web pages with apache.

HBruijn avatar
in flag
Running `sudo mysql -u postf..` will run the mysql commandline client with root privileges and is an insufficient check to see if an unprivileged user can also connect to the mysql socket. Try running that again without `sudo` and if that fails there may be a file system permission problem prevent the postfix user from connecting to the database via the MariaDB socket.
swegbarca avatar
im flag
Thanks for the reply, I just checked and running it without `sudo` does indeed fail: `mysql -u postfixuser -p'XXXX' -h localhost postfixadmindb >ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (13)`
swegbarca avatar
im flag
I solved the problem by granting read and execute permissions to all users on the /run/mysqld directory
HBruijn avatar
in flag
Converted my comment to an answer
Score:0
in flag

Running sudo mysql -u postf.. will run the mysql command-line client with root privileges and is an insufficient check to see if an unprivileged user can also connect to the mysql socket.

Try running that again without sudo and if that fails with an error such as Can't connect to local server through socket '/run/mysqld/mysqld.sock'there may be a file system permission problem that prevents the postfix user from connecting to the database via the MariaDB socket.

Changing the file system permissions on that directory/path is then the solution.

sudo chmod 0755  /run/mysqld/

It should be noted that directories under /run and/or /var/run are often created at boot time by systemd, in this case by the MySQL/MariaDB service unit.

You may need to edit the systemd unit file to make that change in permissions persistent.
If the RuntimeDirectory directive is used you would need to set the correct permissions with the RuntimeDirectoryMode=0755 directive.

If tempfiles.d is used, edit the spec for that

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.