Solving Database Connection Issues
When MailPoet is unable to connect to the database, a warning like this is displayed:
What Is The Problem?
MailPoet uses a PHP Data Objects (PDO) extension to connect to the database. If your website is on a Unix server and
localhost is used as a database hostname, then PDO will try to connect to the database via a socket file specified in the PHP configuration (during the compilation or via
php.ini). As described in
the PHP documentation:
When the host name is set to "localhost", then the connection to the server is made thru a domain socket. If PDO_MYSQL is compiled against libmysqlclient then the location of the socket file is at libmysqlclient's compiled in location. If PDO_MYSQL is compiled against mysqlnd a default socket can be set thru the pdo_mysql.default_socket setting.
When that socket file is missing, MailPoet is unable to connect to the database.
What Is The Solution?
- Open the file wp-config.php file.
- Find the line
define('DB_HOST', 'localhost');and replace it with
- Find your
mysql.sockfile. Common locations include:
or, if you use MAMP or LAMP look for inside the MySQL's
- Edit your
php.inifile and properly set the value for
- Restart your web Apache server to pickup the changes.
If you need further assistance to fix this, please contact your hosting provider's technical support and provide a link to this article. Or if you want a developer to help you? We recommend those at Codeable (affiliate link).