wp-cli / db-command

Performs basic database operations using credentials stored in wp-config.php.
MIT License
71 stars 59 forks source link

WP DB won't work if db connection is secured #126

Closed dotker closed 5 years ago

dotker commented 6 years ago

Hello guys and gals! Anyone got wp-cli to work with secured database connections? Seems not working and seems people are rarely using a secured database connections(for remote databases)?

schlessera commented 5 years ago

@dotker WP-CLI just uses the configuration that is set in your wp-config.php file.

What are you actually trying to do that fails, and what error does it produce?

dotker commented 5 years ago

If the flag: define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL); is on. Getting mysqldump: Got error: 1045: "Access denied for user ... So it doesn't work with secure database connection.

If a wp plugin does a backup with SSL connection to a remote database it works fine but wp-cli doesn't.

dotker commented 5 years ago

Also just like to add that the database user has REQUIRE SSL with it so it can only accept secured connections. And thanks for looking and/or assistance on this issue.

schlessera commented 5 years ago

@dotker As you're referencing mysqldump, I assume you are trying to use the wp db export command.

The MYSQLI_CLIENT_SSL flag is specific to the PHP mysqli extension. The mysqldump binary is not PHP code, so the flag does nothing in this case.

Did you try adding the --ssl flag to the command? This would forward the --ssl flag to the mysqldump binary.

danielbachhuber commented 5 years ago

@dotker Any further information to share, or can we close this issue?

mikebridge commented 4 years ago

I think the --ssl flag is missing from wp help db export. @schlessera 's suggestion works for me:

$ wp db export --path=/var/www/html
mysqldump: Got error: 9002: "SSL connection is required. Please specify SSL options and retry." when trying to connect
$ wp db export --ssl --path=/var/www/html
Success: Exported to 'wordpress-2020-09-15-ab86af3.sql'.