Ubuntu – Postfix and MySQL configuration

MySQLpostfixUbuntu

I have the problem with configuration of Postfix on my server. I have been used this link like tutorial for creating and configuration Postfix.

https://www.digitalocean.com/community/tutorials/how-to-configure-a-mail-server-using-postfix-dovecot-mysql-and-spamassasin

But, when I tried to test Postfix with command:
postmap -q example.com mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf

I got the error:
postmap: warning: connect to mysql server 127.0.0.1: Can't connect to MySQL server on '127.0.0.1' (111)
postmap: fatal: table mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf: query error: Connection refused

When I tried to test it with command:
telnet 127.0.0.1 3306 or telnet localhost 3306

I got the error:
Trying 127.0.0.1…
telnet: Unable to connect to remote host: Connection refused

MySQL server worked and I couldn't find a way to fix this error.

Does somebody know what is the problem?

Best Answer

This error is telling you that MySQL isn't listening on the port specified.

Can you connect to MySQL using the command line client (e.g. mysql -H127.0.0.1 -P3306?)

I doubt you can if both postmap and telnet are telling you they can't connect. Check the port that you're using - has this been changed from the default? Look in /etc/my.cnf as a first port of call for the current MySQL server config.

Check MySQL is running. Depending on your distribution and how you installed MySQL there are various ways to do this, but check the output of:

ps -ef | grep mysql

You should find at least one mysqld process running.

If it's not running, start the server. If you've got a relatively "normal" install, this can be done using init.d scripts as root (normally something like /etc/init.d/mysql start).