db-command icon indicating copy to clipboard operation
db-command copied to clipboard

db import doesn't support --ssl flag

Open michaelryanmcneill opened this issue 3 years ago • 4 comments

Bug Report

Summary

Running wp db import with the --ssl flag fails to properly connect to the database as expected.

How to reproduce

To reproduce, simply attempt to import with a user that requires SSL. For example:

$ wp db import --ssl database-2022-01-24-a50feb0.sql
Error: Failed to get current SQL modes. Reason: ERROR 1045 (28000): Access denied for user 'dbuser'@'127.0.0.1' (using password: YES)

But, if you run wp db cli --ssl, you can successfully connect to the database:

$ wp db cli --ssl
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 44
Server version: 8.0.27 Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [database]>

Environment

OS:	Linux 5.11.0-1025-aws #27~20.04.1-Ubuntu SMP Fri Jan 7 13:09:56 UTC 2022 x86_64
Shell:	/bin/bash
PHP binary:	/RunCloud/Packages/php74rc/bin/php
PHP version:	7.4.26
php.ini used:	/etc/php74rc/php.ini
MySQL binary:	/usr/bin/mysql
MySQL version:	mysql  Ver 15.1 Distrib 10.5.13-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
SQL modes:
WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/home/runcloud/webapps/example-com
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version:	2.5.0

Temporary workaround

To temporarily workaround this issue, use wp db cli --ssl and then source the file.

$ wp db cli --ssl
MySQL [database]> source database-2022-01-24-a50feb0.sql

michaelryanmcneill avatar Jan 24 '22 04:01 michaelryanmcneill

The --http flag don't help on this case?

(I ask because also don't know very well this scenario)

AdsonCicilioti avatar May 14 '22 01:05 AdsonCicilioti

@AdsonCicilioti no, the --http flag will not help in this case. In this case the database is using TLS over TCP.

michaelryanmcneill avatar May 14 '22 17:05 michaelryanmcneill

Thanks for the report, @michaelryanmcneill !

It looks like wp db cli --ssl works because the assoc args are passed directly through:

https://github.com/wp-cli/db-command/blob/196f4d3d171b79e19650182c645f854643439c9e/src/DB_Command.php#L382-L393

However, wp db import runs the arguments through some processing function:

https://github.com/wp-cli/db-command/blob/196f4d3d171b79e19650182c645f854643439c9e/src/DB_Command.php#L722-L734

It looks like this was added in https://github.com/wp-cli/db-command/pull/123

I think we'll need to adapt ::get_mysql_args() to support --ssl.

danielbachhuber avatar Nov 09 '22 18:11 danielbachhuber