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

db import doesn't support --ssl flag #218

Open
michaelryanmcneill opened this issue Jan 24, 2022 · 3 comments
Open

db import doesn't support --ssl flag #218

michaelryanmcneill opened this issue Jan 24, 2022 · 3 comments

Comments

@michaelryanmcneill
Copy link

michaelryanmcneill commented Jan 24, 2022

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
@AdsonCicilioti
Copy link

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

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

@michaelryanmcneill
Copy link
Author

michaelryanmcneill commented May 14, 2022

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

@danielbachhuber danielbachhuber changed the title DB Import Doesn't Support SSL db import doesn't support --ssl flag Nov 9, 2022
@danielbachhuber
Copy link
Member

Thanks for the report, @michaelryanmcneill !

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

public function cli( $_, $assoc_args ) {
$command = sprintf( '/usr/bin/env mysql%s --no-auto-rehash', $this->get_defaults_flag_string( $assoc_args ) );
WP_CLI::debug( "Running shell command: {$command}", 'db' );
if ( ! isset( $assoc_args['database'] ) ) {
$assoc_args['database'] = DB_NAME;
}
WP_CLI::debug( 'Associative arguments: ' . json_encode( $assoc_args ), 'db' );
self::run( $command, $assoc_args, null, true );
}

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

public function import( $args, $assoc_args ) {
if ( ! empty( $args[0] ) ) {
$result_file = $args[0];
} else {
$result_file = sprintf( '%s.sql', DB_NAME );
}
// Process options to MySQL.
$mysql_args = array_merge(
[ 'database' => DB_NAME ],
self::get_dbuser_dbpass_args( $assoc_args ),
self::get_mysql_args( $assoc_args )
);

It looks like this was added in #123

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

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