My wp config create command:

wp core config --dbname=wordpress --dbuser=wordpress --dbpass='this is not the real password'

Running it:

$ wp core config --dbname=wordpress --dbuser=wordpress --dbpass='this is not the real password'
ERROR 1045 (28000): Access denied for user 'wordpress'@'localhost' (using password: YES)

Some evidence about why I think the problem is that wp-cli is trying to use the '\@localhost version' of the user I'm specifying; from the MariaDB 'monitor':

MariaDB [(none)]> SELECT Host, User FROM mysql.user;
| Host      | User      |
| %         | wordpress |
| | root      |
| ::1       | root      |
| localhost |           |
| localhost | root      |

This didn't work either:

$ wp core config --dbhost=\% --dbname=wordpress --dbuser=wordpress --dbpass='this is not the real password'
ERROR 2005 (HY000): Unknown MySQL server host '%' (8)

How can I tell wp-cli to use the '% version' of the wordpress user?

A seemingly relevant GitHub issue for the wp-cli project:

  • 1
    Maybe: --dbhost=\% ? But it looks a bit wierd, in my opinion. I have never seen this before. Is % perhaps just a placeholder for Perhaps try with --dbhost= It's a long-shot. Sorry. :-/ – Zeth Nov 3 '18 at 11:32
  • @Zeth The '%' host means 'all hosts', i.e. that user can connect to the MySQL or MariaDB instance from any host. The '\@localhost' users can only connect from the same host as on which the DB server is running. – Kenny Evitt Nov 3 '18 at 11:37
  • 1
    Ahh..! I see. But is the database on your local machine? The dbhost is telling the config, which host that the database is located on. So then you should insert the IP-address of the host where the database is located. Or am I missing something? – Zeth Nov 3 '18 at 11:43
  • @Zeth The database server instance is on my local machine. But it seems useful for the user to be able to connect from another host (other than the host on which the DB server instance is running), e.g. if I wanted to host the DB server and WordPress app on separate machines. – Kenny Evitt Nov 3 '18 at 13:29
  • It turned out to be a dumb error; the password for the user in wp-config.php was missing the single quote character in it. I'm pretty sure I quoted it correctly in my wp core config ... command, but perhaps not. – Kenny Evitt Nov 3 '18 at 14:00

You probably have an anonymous user ' '@'localhost' or ' '@'' in MariaDB. The recommended solution is to drop this anonymous user (this is usually a good thing to do anyways).

| improve this answer | |
  • Would the anonymous user appear in the mysql.user table as having an empty or blank User column value (name)? – Kenny Evitt Nov 3 '18 at 13:27
  • 1
    Yes, to remove it try DELETE FROM mysql.user WHERE User=''; FLUSH PRIVILEGES; – yurha Nov 3 '18 at 13:31
  • It didn't help. wp db check still fails with mysqlcheck: Got error: 1045: Access denied for user 'wordpress@%'@'localhost' (using password: YES) when trying to connect. It seems like the wp-cli program just assumes all database users are the '\@localhost' versions. – Kenny Evitt Nov 3 '18 at 13:43
  • Is remote access granted for user 'wordpress'? – yurha Nov 3 '18 at 13:50
  • 1
    Ah, yes. '%' is enough. Well, let me think where problem could be. – yurha Nov 3 '18 at 14:22

For users setup as an 'all hosts' user, i.e. the value of Host in the table mysql.user for the row for that user is '%', there's nothing that needs to be done. wp-cli WILL try to connect as the 'localhost version' of that user, but doing so should be fine if the user really is an 'all hosts' user.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.