@@ -539,6 +539,9 @@ public function export( $args, $assoc_args ) {
539
539
* [--dbpass=<value>]
540
540
* : Password to pass to mysql. Defaults to DB_PASSWORD.
541
541
*
542
+ * [--<field>=<value>]
543
+ * : Extra arguments to pass to mysql. [Refer to mysql binary docs](https://dev.mysql.com/doc/refman/8.0/en/mysql-command-options.html).
544
+ *
542
545
* [--skip-optimization]
543
546
* : When using an SQL file, do not include speed optimization such as disabling auto-commit and key checks.
544
547
*
@@ -571,6 +574,8 @@ public function import( $args, $assoc_args ) {
571
574
572
575
$ mysql_args ['execute ' ] = sprintf ( $ query , $ result_file );
573
576
}
577
+ // Check if any mysql option pass.
578
+ $ mysql_args = array_merge ( $ mysql_args , self ::get_mysql_args ( $ assoc_args ) );
574
579
575
580
self ::run ( '/usr/bin/env mysql --no-defaults --no-auto-rehash ' , $ mysql_args );
576
581
@@ -1025,10 +1030,10 @@ public function prefix() {
1025
1030
* | 98 | foo_options | a:1:{s:12:"_multiwidget";i:1;} | yes |
1026
1031
* | 99 | foo_settings | a:0:{} | yes |
1027
1032
* +----+--------------+--------------------------------+-----+
1028
- *
1033
+ *
1029
1034
* # SQL search and delete records from database table 'wp_options' where 'option_name' match 'foo'
1030
1035
* wp db query "DELETE from wp_options where option_id in ($(wp db query "SELECT GROUP_CONCAT(option_id SEPARATOR ',') from wp_options where option_name like '%foo%';" --silent --skip-column-names))"
1031
- *
1036
+ *
1032
1037
* @when after_wp_load
1033
1038
*/
1034
1039
public function search ( $ args , $ assoc_args ) {
@@ -1429,4 +1434,113 @@ private function get_colors( $assoc_args, $colors ) {
1429
1434
1430
1435
return $ colors ;
1431
1436
}
1437
+
1438
+ /**
1439
+ * Helper to pluck `mysql` options from associative args array.
1440
+ *
1441
+ * @param array $assoc_args Associative args array.
1442
+ * @return array Array with `mysql` options set if in passed-in associative args array.
1443
+ */
1444
+ private static function get_mysql_args ( $ assoc_args ) {
1445
+
1446
+ $ allowed_mysql_options = [
1447
+ 'auto-rehash ' ,
1448
+ 'auto-vertical-output ' ,
1449
+ 'batch ' ,
1450
+ 'binary-as-hex ' ,
1451
+ 'binary-mode ' ,
1452
+ 'bind-address ' ,
1453
+ 'character-sets-dir ' ,
1454
+ 'column-names ' ,
1455
+ 'column-type-info ' ,
1456
+ 'comments ' ,
1457
+ 'compress ' ,
1458
+ 'connect-expired-password ' ,
1459
+ 'connect_timeout ' ,
1460
+ 'database ' ,
1461
+ 'debug ' ,
1462
+ 'debug-check ' ,
1463
+ 'debug-info ' ,
1464
+ 'default-auth ' ,
1465
+ 'default-character-set ' ,
1466
+ 'defaults-extra-file ' ,
1467
+ 'defaults-file ' ,
1468
+ 'defaults-group-suffix ' ,
1469
+ 'delimiter ' ,
1470
+ 'enable-cleartext-plugin ' ,
1471
+ 'execute ' ,
1472
+ 'force ' ,
1473
+ 'get-server-public-key ' ,
1474
+ 'help ' ,
1475
+ 'histignore ' ,
1476
+ 'host ' ,
1477
+ 'html ' ,
1478
+ 'ignore-spaces ' ,
1479
+ 'init-command ' ,
1480
+ 'line-numbers ' ,
1481
+ 'local-infile ' ,
1482
+ 'login-path ' ,
1483
+ 'max_allowed_packet ' ,
1484
+ 'max_join_size ' ,
1485
+ 'named-commands ' ,
1486
+ 'net_buffer_length ' ,
1487
+ 'no-beep ' ,
1488
+ 'one-database ' ,
1489
+ 'pager ' ,
1490
+ 'pipe ' ,
1491
+ 'plugin-dir ' ,
1492
+ 'port ' ,
1493
+ 'print-defaults ' ,
1494
+ 'protocol ' ,
1495
+ 'quick ' ,
1496
+ 'raw ' ,
1497
+ 'reconnect ' ,
1498
+ 'i-am-a-dummy ' ,
1499
+ 'safe-updates ' ,
1500
+ 'secure-auth ' ,
1501
+ 'select_limit ' ,
1502
+ 'server-public-key-path ' ,
1503
+ 'shared-memory-base-name ' ,
1504
+ 'show-warnings ' ,
1505
+ 'sigint-ignore ' ,
1506
+ 'silent ' ,
1507
+ 'skip-auto-rehash ' ,
1508
+ 'skip-column-names ' ,
1509
+ 'skip-line-numbers ' ,
1510
+ 'skip-named-commands ' ,
1511
+ 'skip-pager ' ,
1512
+ 'skip-reconnect ' ,
1513
+ 'socket ' ,
1514
+ 'ssl-ca ' ,
1515
+ 'ssl-capath ' ,
1516
+ 'ssl-cert ' ,
1517
+ 'ssl-cipher ' ,
1518
+ 'ssl-crl ' ,
1519
+ 'ssl-crlpath ' ,
1520
+ 'ssl-fips-mode ' ,
1521
+ 'ssl-key ' ,
1522
+ 'ssl-mode ' ,
1523
+ 'syslog ' ,
1524
+ 'table ' ,
1525
+ 'tee ' ,
1526
+ 'tls-version ' ,
1527
+ 'unbuffered ' ,
1528
+ 'verbose ' ,
1529
+ 'version ' ,
1530
+ 'vertical ' ,
1531
+ 'wait ' ,
1532
+ 'xml '
1533
+ ];
1534
+
1535
+ $ mysql_args = array ();
1536
+
1537
+ foreach ( $ assoc_args as $ mysql_option_key => $ mysql_option_value ) {
1538
+ // Check flags to make sure they only contain valid options.
1539
+ if ( in_array ( $ mysql_option_key , $ allowed_mysql_options , true ) && ! empty ( $ mysql_option_value ) ) {
1540
+ $ mysql_args [$ mysql_option_key ] = $ mysql_option_value ;
1541
+ }
1542
+ }
1543
+
1544
+ return $ mysql_args ;
1545
+ }
1432
1546
}
0 commit comments