最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp cli - How to specify to wp-cli for the `wp config create` (`wp core config`) command that the DB user is an 'all host

matteradmin8PV0评论

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 |
| 127.0.0.1 | 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:

  • wp config create ERROR 1045 (28000): Access denied for user · Issue #4505 · wp-cli/wp-cli

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 |
| 127.0.0.1 | 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:

  • wp config create ERROR 1045 (28000): Access denied for user · Issue #4505 · wp-cli/wp-cli
Share Improve this question edited Nov 3, 2018 at 11:34 Kenny Evitt asked Nov 3, 2018 at 11:24 Kenny EvittKenny Evitt 1217 bronze badges 5
  • 1 Maybe: --dbhost=\% ? But it looks a bit wierd, in my opinion. I have never seen this before. Is % perhaps just a placeholder for 127.0.0.1? Perhaps try with --dbhost=127.0.0.1. It's a long-shot. Sorry. :-/ – Zeth Commented Nov 3, 2018 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 Commented Nov 3, 2018 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 Commented Nov 3, 2018 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 Commented Nov 3, 2018 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 Commented Nov 3, 2018 at 14:00
Add a comment  | 

2 Answers 2

Reset to default 1

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

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.

Post a comment

comment list (0)

  1. No comments so far