Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp config create ERROR 1045 (28000): Access denied for user #4505

Closed
apb1963 opened this issue Nov 12, 2017 · 13 comments
Closed

wp config create ERROR 1045 (28000): Access denied for user #4505

apb1963 opened this issue Nov 12, 2017 · 13 comments

Comments

@apb1963
Copy link

apb1963 commented Nov 12, 2017

It tacks the @localhost on whether I use a host name or not.

sudo wp config create –path=/usr/local/src/myhost.mydomain –url=https://myhost.mydomain –dbhost=myhost.mydomain –dbname=myhostDBName –dbuser=apb –dbpass=123 –allow-root

ERROR 1045 (28000): Access denied for user ‘apb’@’localhost’ (using password: YES)

$ sudo wp config create –path=/usr/local/src/myhost.mydomain –url=https://myhost.mydomain –dbhost=myhost.mydomain –dbname=myhostDBName –dbuser=’apb’@’myhost.mydomain’ –dbpass=123 –allow-root

ERROR 1045 (28000): Access denied for user ‘apb’@’myhost.mydomain’@’localhost’ (using password: YES)


sudo wp config create –path=/usr/local/src/myhost.mydomain –url=https://myhost.mydomain –dbhost=myhost.mydomain –dbname=myhostDBName –dbuser=”apb@myhost.mydomain” –dbpass=123 –allow-root

ERROR 1045 (28000): Access denied for user ‘apb@myhost.mydomain’@’localhost’ (using password: YES)

Thank you in advance!

$ lsb_release -d
Description:	Ubuntu 16.04.3 LTS

$ wp –info
PHP binary: /usr/bin/php7.0
PHP version: 7.0.22-0ubuntu0.16.04.1
php.ini used: /etc/php/7.0/cli/php.ini
WP-CLI root dir: phar://wp-cli.phar
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: /data/local/src/myscripts
WP-CLI packages dir: /home/apb/.wp-cli/packages/
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 1.4.0


@danielbachhuber
Copy link
Member

@apb1963 It appears your –dbhost=myhost.mydomain argument should be --dbhost=myhost.mydomain. Can you confirm correct usage of your arguments?

More generally, there's not any code that automatically appends 'localhost' to a dbhost, so I suspect this is user error.

@apb1963
Copy link
Author

apb1963 commented Nov 13, 2017

I think you're referencing what appears to be a single hyphen as opposed to double? No, it's a double, that's apparently a copy/paste translation issue with this forum/github.com software. --dbhost has two hyphens. It shows up that way in the preview tab... lets see if it stays that way...

@danielbachhuber
Copy link
Member

@apb1963 Happy to help you debug in Slack: http://wp-cli.org/#support

@apb1963
Copy link
Author

apb1963 commented Nov 13, 2017

Hmm. It did.. I don't know why it showed up that way... but there are two hyphens as required. Lets try again: sudo wp config create --path=/usr/local/src/myhost.mydomain --url=https://myhost.mydomain --dbhost=myhost.mydomain --dbname=myhostDBName --dbuser=apb --dbpass=123 --allow-root

ERROR 1045 (28000): Access denied for user 'apb'@'localhost' (using password: YES)

@apb1963
Copy link
Author

apb1963 commented Nov 13, 2017

Well after I went through the signup process, I went there, and have been sitting there, but I don't see you.

@apb1963
Copy link
Author

apb1963 commented Nov 14, 2017

Reproducing this bug requires a similar if not identical environment.

So, installing ubuntu 16.04.3 is the first step, although skipping this step until later is a possibility. i.e. If you can reproduce without having to install that OS, then you can skip installing it. If not, then installing ubuntu is the only way to accurately attempt reproduction of this bug.

The next step to reproduce requires creating the directory. i.e. mkdir /usr/local/src/myhost.mydomain

Then, using wp-cli install wordpress into that directory.

Then, remove the config file i.e. rm /usr/local/src/myhost.mydomain/wp-config.php or else wp-cli complains (in the next step below) that it already exists and I don't know a way to force an overwrite using wp-cli. Maybe you do.

Next, run the given command (sudo wp config create --path=/usr/local/src/myhost.mydomain --url=https://myhost.mydomain --dbhost=myhost.mydomain --dbname=myhostDBName --dbuser=apb --dbpass=123 --allow-root) to recreate the config file (because I have different parameters then the stock config file and I need to change it). Substitute your own existing non-root user for "apb".

Note that replacing "apb" with "root" works, but leaves me with the wrong user (root) in the wp-config.php file. Obviously I can post process it with various tools, but I think fixing the bug is the better solution. YMMV

@danielbachhuber
Copy link
Member

Then, remove the config file i.e. rm /usr/local/src/myhost.mydomain/wp-config.php or else wp-cli complains (in the next step below) that it already exists and I don't know a way to force an overwrite using wp-cli. Maybe you do.

Why does wp-config.php already exist? Can you please share exact output of all commands you've run?

If not, then installing ubuntu is the only way to accurately attempt reproduction of this bug.

If this is the case, then the bug is with Ubuntu and not WP-CLI.

@gitlost
Copy link
Contributor

gitlost commented Nov 14, 2017

My guess is that your mysql server mysqld as at localhost and the mysql user apb does not exist on it or has insufficient privileges - see https://dev.mysql.com/doc/refman/5.7/en/adding-users.html

@apb1963
Copy link
Author

apb1963 commented Nov 14, 2017

Hmm... I thought that replying to the email I received would end up posting it here, but apparently not. So I'll paste my emails next...

@apb1963
Copy link
Author

apb1963 commented Nov 14, 2017

On 11/13/2017 04:45 PM, Daniel Bachhuber wrote:

Then, remove the config file i.e. rm /usr/local/src/myhost.mydomain/wp-config.php or else wp-cli complains (in the next step below) that it already exists and I don't know a way to force an overwrite using wp-cli. Maybe you do.

Why does wp-config.php already exist? Can you please share exact output of all commands you've run?

Sorry, I forgot to mention that I copy an existing wp install to the above path, so the wp-config.php is from that copy, which is of course not relevant to the current install. In any event, I remove it before doing anything further.

When I first started I didn't know that it would use a cached copy of wp instead of downloading again, so I felt that copying would be more efficient than re-downloading it. I haven't had a chance to go back and change it and I don't think it makes much difference. Let me know if you do, this is what I would do if so, unless it's wrong:
sudo -u apb wp core download --path=/usr/local/src/myhost.mydomain --force --version=latest --allow-root

The intent is to have a pristine, unaltered site /usr/share/wordpress and then also create a template site under /usr/local/src/template which includes woo, storefront and whatever other plugins, then copy it to another installation site - say maybe for example "onions.mydomain" and change the relevant parameters to match.

Although I'm specifying multi-site so far, I don't think I'll actually be using it. I'm trying to plan for the future, with the hope & expectation that the store will be wildly successful. So, towards that end I want each site to have its own DB rather than sharing the same DB, which is what multi-site does if I understand correctly. That way if a particular site gets significant traffic I can move it to its own server without too much hassle I think. That's the current thinking anyway.

If not, then installing ubuntu is the only way to accurately attempt reproduction of this bug.

If this is the case, then the bug is with Ubuntu and not WP-CLI.

With all due respect, I disagree. To use an unrelated and contrived example, (but which should help to clarify my point) if ubuntu requires that you use 'open(filename, "mode")' but you use 'open("mode", filename)' instead because that's how OS-X does it, then the bug is not with ubuntu, as you have failed to provide ubuntu with what it requires. Similarly, if ubuntu adds something to its environment that causes a problem for wp, it's not a bug in ubuntu, it's a failure of the application to acknowledge reality. There are of course exceptions to just about every rule.

The problem may very well be something that's different in my environment that I'm unaware of, seeing as I'm relatively new to wp in all its forms. The problem is, I don't know where I should be looking or what I should be looking for.

If you say wp doesn't explicitly tack on the @localhost, I believe you. But, that still leaves the question of where the heck it's coming from. ubuntu doesn't just randomly insert things, there's got to be a reason. As the error occurs outside of my script as well as inside, the error can not possibly be with my bash script - i.e. I'm not using the script and still get the error). If you're up to it, I can give you an account on my machine if you think investigating up close would be helpful.

I can workaround the problem by using root instead of apb, but then I have to modify the wp-config.php file after it's generated as it stuffs the dbuser (now root instead of apb) into the file. It's not a big deal, a couple of simple sed statements and finished but it's really not how it should be done in my opinion. I guess I can repress my sensibilities if I have to.

With all that said --skip-check allows me to bypass the issue. Unfortunately, when I do so, it does not include any of:

define('DB_NAME', 'wordpress');
define('DB_USER', 'root');
define('DB_PASSWORD', '123');
define('DB_HOST', 'localhost');
define('WP_CONTENT_DIR', '/usr/share/wordpress/wp-content');

in the file.

I can certainly add them to my script easily enough, but I thought I'd mention it since I'm not sure what behavior to expect when using --skip-check.

Thank you

@apb1963
Copy link
Author

apb1963 commented Nov 14, 2017

On 11/13/2017 11:58 PM, gitlost wrote:

My guess is that your mysql server mysqld as at localhost and the mysql user apb does not exist on it or has insufficient privileges - see https://dev.mysql.com/doc/refman/5.7/en/adding-users.html

Thanks for your response. The mysqld server is in fact at localhost and to my knowledge, is correct. You are correct in that apb@localhost does not exist.

However, that's the correct answer to a question that wasn't asked.

The question was, why is "@localhost" getting tacked on whether I want it or not? apb@localhost@localhost is not a valid user, nor will nor should it ever be.
The simple solution is to add apb@localhost as a valid user, but considering the administrator should be at apb@myhost.mydomain, the simple solution isn't a solution at all. And specifying apb@myhost.mydomain ends up as apb@myhost.mydomain@localhost so that solution is not helpful either.

With that said, this is where my inexperience comes in and you've started my brain juice churning and now you've got me wondering if I'm taking the right approach forcing/requiring/expecting the admin to be at the same domain. Perhaps I should simply add apb@localhost as the administrator of myhost.mydomain and xyz@localhost as admin of myhost2.mydomain, and so on. That would circumvent the issue I think. So that might be the easiest work-around until someone can figure out why it's adding @localhost for no apparent reason. I'll give it a try.

Thank you!

@gitlost
Copy link
Contributor

gitlost commented Nov 14, 2017

You're confusing 2 different users - the mysql user and the WordPress user - and 2 different hosts - the mysql host and your site domain. They have nothing to do with each other. The original error message you got

ERROR 1045 (28000): Access denied for user ‘apb’@’localhost’ (using password: YES)

is a MySQL error and apb@localhost refers to the mysql user and mysql host ( <dbuser>@<dbhost>). The mysql user and mysql host are only used by WordPress to connect to the database. They have nothing to do with WordPress users or your site's domain.

@apb1963
Copy link
Author

apb1963 commented Nov 14, 2017

The mysql user and mysql host are only used by WordPress to connect to the database.They have nothing to do with WordPress users or your site's domain.

I agree with the rest of what you've stated and am aware of it, thank you. But in regard to the above quoted statement... Hmmm. You may have hit the nail on the head. I am in fact a bit confused about that point.

Does that mean all I need is root@localhost as my user for all WordPress databases? So I actually don't need different wp-config.php files for each one?? Well actually... I kinda do. If DB1 becomes ultra-popular, I may need to tune the memory limit and/or other parameters for that one DB alone. Right? I guess at that point I'd move that one DB to another server I suppose. Hmmm - I guess it depends on details of the future situation; hard to plan for that.

So, following this to its conclusion to specify/assign/create/etc. a different admin for each WP DB (and in truth, I'm not clear at this point what those admins would be doing exactly) I guess I'd use "wp user create" and "wp user add-cap" to create the admin user? And presumably the potential capabilities are documented somewhere. Or maybe it's add-role I need? Guess I have some reading to do. Focused links are appreciated.

Thanks for pointing me in the right direction!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants