public function import( $args, $assoc_args ) {
		if ( ! empty( $args[0] ) ) {
			$result_file = $args[0];
		} else {
			$result_file = sprintf( '%s.sql', DB_NAME );
		}

		$mysql_args = array(
			'database' => DB_NAME,
		);
		$mysql_args = array_merge( self::get_dbuser_dbpass_args( $assoc_args ), $mysql_args );

		if ( '-' !== $result_file ) {
			if ( ! is_readable( $result_file ) ) {
				WP_CLI::error( sprintf( 'Import file missing or not readable: %s', $result_file ) );
			}

			$query = Utils\get_flag_value( $assoc_args, 'skip-optimization' )
				? 'SOURCE %s;'
				: 'SET autocommit = 0; SET unique_checks = 0; SET foreign_key_checks = 0; SOURCE %s; COMMIT;';

			$mysql_args['execute'] = sprintf( $query, $result_file );
		}
		// Check if any mysql option pass.
		$mysql_args = array_merge( $mysql_args, self::get_mysql_args( $assoc_args ) );

		self::run( '/usr/bin/env mysql --no-defaults --no-auto-rehash', $mysql_args );

		WP_CLI::success( sprintf( "Imported from '%s'.", $result_file ) );
	}
public function import( $args, $assoc_args ) {
		if ( ! empty( $args[0] ) ) {
			$result_file = $args[0];
		} else {
			$result_file = sprintf( '%s.sql', DB_NAME );
		}

		$mysql_args = array(
			'database' => DB_NAME,
		);
		$mysql_args = array_merge( self::get_dbuser_dbpass_args( $assoc_args ), $mysql_args );

		if ( '-' !== $result_file ) {
			if ( ! is_readable( $result_file ) ) {
				WP_CLI::error( sprintf( 'Import file missing or not readable: %s', $result_file ) );
			}

			$query = Utils\get_flag_value( $assoc_args, 'skip-optimization' )
				? 'SOURCE %s;'
				: 'SET autocommit = 0; SET unique_checks = 0; SET foreign_key_checks = 0; SOURCE %s; COMMIT;';

			$mysql_args['execute'] = sprintf( $query, $result_file );
		}
		// Check if any mysql option pass.
		$mysql_args = array_merge( $mysql_args, self::get_mysql_args( $assoc_args ) );

		self::run( '/usr/bin/env mysql --no-defaults --no-auto-rehash', $mysql_args );

		WP_CLI::success( sprintf( "Imported from '%s'.", $result_file ) );
	}
public function import ( $ args , $ assoc_args ) { if ( ! empty ( $ args [ 0 ] ) ) { $ result_file = $ args [ 0 ] ; } else { $ result_file = sprintf ( '%s.sql' , DB_NAME ) ; } $ mysql_args = array ( 'database' => DB_NAME , ) ; $ mysql_args = array_merge ( self :: get_dbuser_dbpass_args ( $ assoc_args ) , $ mysql_args ) ; if ( '-' !== $ result_file ) { if ( ! is_readable ( $ result_file ) ) { WP_CLI :: error ( sprintf ( 'Import file missing or not readable: %s' , $ result_file ) ) ; } $ query = Utils \ get_flag_value ( $ assoc_args , 'skip-optimization' ) ? 'SOURCE %s;' : 'SET autocommit = 0; SET unique_checks = 0; SET foreign_key_checks = 0; SOURCE %s; COMMIT;' ; $ mysql_args [ 'execute' ] = sprintf ( $ query , $ result_file ) ; } // Check if any mysql option pass. $ mysql_args = array_merge ( $ mysql_args , self :: get_mysql_args ( $ assoc_args ) ) ; self :: run ( '/usr/bin/env mysql --no-defaults --no-auto-rehash' , $ mysql_args ) ; WP_CLI :: success ( sprintf ( "Imported from '%s'." , $ result_file ) ) ; }
Imports a database from a file or from STDIN.

Runs SQL queries using `DB_HOST`, `DB_NAME`, `DB_USER` and
`DB_PASSWORD` database credentials specified in wp-config.php. This
does not create database by itself and only performs whatever tasks are
defined in the SQL.

## OPTIONS

[<file>]
: The name of the SQL file to import. If '-', then reads from STDIN. If omitted, it will look for '{dbname}.sql'.

[--dbuser=<value>]
: Username to pass to mysql. Defaults to DB_USER.

[--dbpass=<value>]
: Password to pass to mysql. Defaults to DB_PASSWORD.

[--<field>=<value>]
: Extra arguments to pass to mysql. [Refer to mysql binary docs](https://dev.mysql.com/doc/refman/8.0/en/mysql-command-options.html).

[--skip-optimization]
: When using an SQL file, do not include speed optimization such as disabling auto-commit and key checks.

## EXAMPLES

# Import MySQL from a file.
$ wp db import wordpress_dbase.sql
Success: Imported from 'wordpress_dbase.sql'.
Imports a database from a file or from STDIN .