0

I use Ubuntu 16.04 with Bash and I tried to run the following command set to automatically create a WordPress wp-config.php file with the WordPress Bash extension WP-CLI. Yet I'm having some problem I miss (Bash related?).

loh="127.0.0.1"
drt="/var/www/html"
domain="example-xyz.com"
dbuserp_1="example-xyz.password"

rm -rf "$drt/$domain"/ 2>/dev/null
wp core download --path="$drt/$domain" --allow-root

wpConfig() {
    rm -rf "$drt/$domain"/ 2>/dev/null
    wp core download --path="$drt/$domain" --allow-root
    wp config create \
    --path=${drt}/${domain} \
    --dbname=${domain} \
    --dbuser=${domain} \
    --dbpass=${dbuserp_1} \
    --dbhost=${loh} \
    --allow-root
}
wpConfig

I double checked that the DB user password I use is correct.

And yet, I get this error:

ERROR 1045 (28000): Access denied for user 'example-xyz.com'@'localhost' (using password: YES)

Changing all ${x} to "$x" changed nothing.

I fail to understand why I get the above error (what does it have to do with MySQL itself, as this error seem MySQL related).

  • Does mysql -u "$domain" -p"$dbuserp_1" "$domain" work with those same variables set? If not, what error do you get? – Michael Homer Mar 5 '18 at 7:11
  • It doesn't. I get the exact same error. – user9303970 Mar 5 '18 at 7:26
  • It sounds like your username and password don't match, then. Error 1045 means the login wasn't valid, before even trying to look at the database itself. Have a look for shell special characters in the password, perhaps, if it looks right. – Michael Homer Mar 5 '18 at 7:34
  • printf "%s %s\n" "$domain" "$dbuserp_1" to check they're set to what you think they are. Look out for any shell special characters, $, `, *`, spaces, etc in them too. – Michael Homer Mar 5 '18 at 7:37
  • They seem just fine. The only "special" char there is a hyphen in the domain. – user9303970 Mar 5 '18 at 7:42
2

If your MySQL database and/or user aren’t created before you run wp config create, you need to tell it to skip the database check:

wp config create --skip-check ...

This will create wp-config.php with the parameters you specify, and it won’t fail if it can’t connect to the database.

1

Seems like MySQL error. You are either entering wrong password or MySQL is setup with no password for example-xyz.com . Are you sure you have configure the user in MySQL? Normally you will have to replace the example username and password with the ones you configured while configuring MySQL during installation, or with any other user added later on.

  • Why does creating a wp-config.php be dependent on MySQL? I could create such a file with proper credentials without using WP-CLI so it is unclear why WP-CLI must already have the relevant DB stack to create that file. I'll think I'll just pass on using WP-CLI for that task. – user9303970 Mar 5 '18 at 7:30

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.