Solved Wordpress can't connect to mysql database

Apparently this is a very common problem but nothing I've tried works. I have never used Wordpress before and it's been a long time since I've used mysql.

I can access mysql (mysql80), set up a database, users, etc. from mysql. I can access Wordpress from a separate computer on the lan or with lynx on the computer that has Wordpress and mysql to get to wp-admin. But when I let wp-admin page try to set things up for me, it complains
Error establishing a database connection

my.cnf


Code:
[client]
port                            = 3306
socket                          = /tmp/mysql.sock

[mysql]
prompt                          = \u@\h [\d]>\_
no_auto_rehash

[mysqld]
user                            = mysql
port                            = 3306
socket                          = /tmp/mysql.sock
bind-address                    = 127.0.0.1
basedir                         = /usr/local
datadir                         = /var/db/mysql
tmpdir                          = /var/db/mysql_tmpdir
slave-load-tmpdir               = /var/db/mysql_tmpdir
secure-file-priv                = /var/db/mysql_secure

wp-config.sample.php
Code:
// define( 'DB_NAME', 'database_name_here' );
define( 'DB_NAME', 'gwyn' );

/** MySQL database username */
//define( 'DB_USER', 'username_here' );
define( 'DB_USER', 'mysql' );

/** MySQL database password */
//define( 'DB_PASSWORD', 'password_here' );
define( 'DB_PASSWORD', 'password' );

/** MySQL hostname */
define( 'DB_HOST', 'freebsd' );

I use "freebsd" as the host name because that's what /bin/hostname shows and what seems mysql uses. I've tried localhost but that was no different.

I read somewhere that I should comment out the ip address altogether but that didn't help things. I am confused as to why, when I log into mysql, that my prompt is doc@freebsd([none]) instead of mysql>.

I've deleted /var/db/mysql multiple times through all this. So I am at a lost but I might be rushing too much since I'm doing this for a friend who needs it by Monday and I stupidly said, "Sure I can do that!".

My dogs want to be fed and I have to run to the grocery store so I'll format this with more info when I get back within the hour.
 
The host should be localhost in the wordpress config. You can use a host name, but it will likely try to use a network connection in that case, and you server is set to listen only on a socket.

May also be worth double checking the username and password work using the MySQL cli.

The prompt has changed in recent MySQL versions to show your username, host and currently selected database instead of just mysql.
 
Well, the username and password work and I can log in as root, mysql and doc. As I said, I had it set as localhost but that didn't change anything.

EDIT: Sorry but I commented out a few things in my original post. Those are not in there now as I tried with and without the commented ip address, port and such.
 
What does this show you?
SHOW databases;
SELECT user,host FROM mysql.user;
 
Code:
SHOW databases;
+--------------------+
| Database           |
+--------------------+
| gwyn               |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

Code:
SELECT user,host FROM mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| mysql            | localhost |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
 
I would strongly suggest creating a diffent user account, something that's easily identifiable, wp_user for example.

Also verify if your permissions are set up correctly with a command like:
SHOW GRANTS FOR 'wp_user'@'localhost';
Make sure the account is permitted to access the gwyn database. I'm not sure what kind of access WordPress requires but this should cover almost everything:
GRANT ALL on 'gwyn.*' TO 'wp_user'@'localhost';
Don't forget to run FLUSH PRIVILEGES; if you changed any grants.
 
Does mysql -u wp_user -p gwyn work?

Make sure to check /var/db/mysql/`hostname -f`.err on the server too.
 
It does.

I'm wondering if my nginx.conf file is wrong with PHP. Or php-fpm. Or my.cnf. I've never dealt with those myself and I've only copied instructions from the wordpress and nginx people. Now I think I'm just seeing what sticks to the wall and making a mess of things.
 
Try my script - it's really straightforward and will get you up and running fairly easily.
Thread 70938

Once you have things working you can change the components to suit. My script uses Apache and Mysql server 56.
 
drhowarddrfine Have you tried to check your MySQL logs to verify if WP made any connections at all? You might want to try and rule out problems with the connection or with authentication. Is there anything specific in the WP install log?
 
Apparently this is a very common problem but nothing I've tried works. I have never used Wordpress before and it's been a long time since I've used mysql.

I can access mysql (mysql80), set up a database, users, etc. from mysql. I can access Wordpress from a separate computer on the lan or with lynx on the computer that has Wordpress and mysql to get to wp-admin. But when I let wp-admin page try to set things up for me, it complains

wp-config.sample.php


You have to copy ur wp-config.sample.php to wp-config.php and edit that file. The -sample.php files arent read by WP.
 
Alexander Huemeyer Yes, I did that.

ShelLuser In /var/db/mysql/freebsd.err is an error that it can't write error log because it doesn't have permission but /var/db/mysql is www:www and 640.

Code:
2019-08-16T17:50:30.6NZ mysqld_safe Logging to '/var/db/mysql/freebsd.err'.
2019-08-16T17:50:30.6NZ mysqld_safe Starting mysqld daemon with databases from /var/db/mysql
mysqld: Error on realpath() on '/var/db/mysql/mysql_secure' (Error 2 - No such file or directory)
2019-08-16T17:50:30.950723Z 0 [Warning] [MY-011068] [Server] The syntax 'expire-logs-days' is deprecated and will be removed in a future release. Please use binlog_expire_logs_seconds instead.
2019-08-16T17:50:30.950820Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2019-08-16T17:50:30.950873Z 0 [Warning] [MY-011068] [Server] The syntax 'expire-logs-days' is deprecated and will be removed in a future release. Please use binlog_expire_logs_seconds instead.
2019-08-16T17:50:30.950932Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2019-08-16T17:50:30.951158Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/db/mysql/mysql_secure
2019-08-16T17:50:30.951193Z 0 [ERROR] [MY-010187] [Server] Could not open file './freebsd.err' for error logging: Permission denied
2019-08-16T17:50:30.951296Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-08-16T17:50:30.6NZ mysqld_safe mysqld from pid file /var/db/mysql/freebsd.pid ended

But when I do ps -ax|grep mysql I see this
Code:
37098  -  Is      0:00.09 /bin/sh /usr/local/bin/mysqld_safe --defaults-extra-file=/usr/local/etc/mysql/my.cnf --basedir=/usr/local --datadir=/var/db/mysql --pid-file=/var/db/mysql/freebsd.pid --user=mysql
38325  -  I       1:35.08 /usr/local/libexec/mysqld --defaults-extra-file=/usr/local/etc/mysql/my.cnf --basedir=/usr/local --datadir=/var/db/mysql --plugin-dir=/usr/local/lib/mysql/plugin --log-error=freebsd.er
 
Just in case, there is a WordPress plugin to postgres. See HERE.

[EDIT]

Also JIC, Joomla apparently have native support to postgres.
 
Now I see the issue, I think, but I don't know what the fix is.

I was confused when I did ps -ax|grep mysql and saw the mysql output thinking the server was running. But, when I do service mysql-server start, the server starts again and again without complaining that it's already running. In the freebsd.err log, it's interesting it states it can't write to that file but here it is:

Code:
2019-08-16T20:18:41.6NZ mysqld_safe Logging to '/var/db/mysql/freebsd.err'.
2019-08-16T20:18:41.6NZ mysqld_safe Starting mysqld daemon with databases from /var/db/mysql
mysqld: Error on realpath() on '/var/db/mysql/mysql_secure' (Error 2 - No such file or directory)
2019-08-16T20:18:42.027465Z 0 [Warning] [MY-011068] [Server] The syntax 'expire-logs-days' is deprecated and will be removed in a future release. Please use binlog_expire_logs_seconds instead.
2019-08-16T20:18:42.027559Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2019-08-16T20:18:42.027612Z 0 [Warning] [MY-011068] [Server] The syntax 'expire-logs-days' is deprecated and will be removed in a future release. Please use binlog_expire_logs_seconds instead.
2019-08-16T20:18:42.027676Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2019-08-16T20:18:42.027891Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/db/mysql/mysql_secure
2019-08-16T20:18:42.027927Z 0 [ERROR] [MY-010187] [Server] Could not open file './freebsd.err' for error logging: Permission denied
2019-08-16T20:18:42.028051Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-08-16T20:18:42.6NZ mysqld_safe mysqld from pid file /var/db/mysql/freebsd.pid ended
 
/var/db/mysql needs to be owned by mysql:mysql for the mysql-server to write to it I would have thought. If its owned by the www user then only the www user would be able to write to any files there, which you don't want. The mysql user needs to own those files.

Code:
2019-08-16T20:18:42.027927Z 0 [ERROR] [MY-010187] [Server] Could not open file './freebsd.err' for error logging: Permission denied
2019-08-16T20:18:42.028051Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-08-16T20:18:42.6NZ mysqld_safe mysqld from pid file /var/db/mysql/freebsd.pid ended

This also suggests that the mysql-server is not running at the moment. Is it actually running?.
Code:
service mysql-server status
mysql is running as pid 92241
Does
Code:
sockstat |grep mysql
list that it is listening. eg you can see something like this output
Code:
mysql    mysqld     92241 17 stream /tmp/mysql.sock
mysql    mysqld     92241 18 tcp4   127.0.0.1:3306        *:*
 
Strange things are happening.

I was going to try and deinstall mysql80 and install mysql57 but pkg says there is no such thing installed. Hmm. How can that be?

Reinstalling everything now.
 
Back
Top