我也有类似的问题(woocommerce测试用户),并编写了以下shell脚本:
#!/bin/bash
# set for your local setup
DB=wordpress ; DBUSER=wordpress ; DBPASS=wordpress
INS_WPU="INSERT INTO wp_users (ID, user_login, user_pass, user_nicename, user_email, user_url, user_registered, user_activation_key, user_status, display_name) VALUES"
INS_WPM="INSERT INTO wp_usermeta (umeta_id, user_id, meta_key, meta_value) VALUES"
# password is \'testuser\'
TESTUSERPASS=\'$P$BptzXm87Y8pxffjyy4Ur0ANs8uqW7J.\'
function ins_test_user(){
# 2 parameters : firstname, lastname
NAM1="$1"
NAM2="$2"
# get the last unused wp_users ID
SQL="select 1+max(ID) from wp_users into @wpuid;\\n"
# get the last unused wp_usermeta ID
SQL="${SQL}select 1+max(umeta_id) from wp_usermeta into @wpmid;\\n"
# insert wp_users record
SQL="${SQL}${INS_WPU} (@wpuid, \'${NAM1}${NAM2}\',\'${TESTUSERPASS}\',\'${NAM1} ${NAM2}\',\'${NAM1}.${NAM2}@example.org\',\'http://${NAM1}.${NAM2}.example.com\',now(),\'\',0,\'test user ${CODE}\');\\n"
# insert wp_usermeta records
SQL="${SQL}${INS_WPM}(0+@wpmid,@wpuid,\'billing_phone\',\'\');\\n"
SQL="${SQL}${INS_WPM}(1+@wpmid,@wpuid,\'nickname\',\'${NAM1} ${NAM2}\');\\n"
SQL="${SQL}${INS_WPM}(2+@wpmid,@wpuid,\'first_name\',\'${NAM1}\');\\n"
SQL="${SQL}${INS_WPM}(3+@wpmid,@wpuid,\'last_name\',\'${NAM2}\');\\n"
SQL="${SQL}${INS_WPM}(4+@wpmid,@wpuid,\'description\',\'\');\\n"
SQL="${SQL}${INS_WPM}(5+@wpmid,@wpuid,\'rich_editing\',\'true\');\\n"
SQL="${SQL}${INS_WPM}(6+@wpmid,@wpuid,\'syntax_highlighting\',\'true\');\\n"
SQL="${SQL}${INS_WPM}(7+@wpmid,@wpuid,\'comment_shortcuts\',\'false\');\\n"
SQL="${SQL}${INS_WPM}(8+@wpmid,@wpuid,\'admin_color\',\'fresh\');\\n"
SQL="${SQL}${INS_WPM}(9+@wpmid,@wpuid,\'use_ssl\',\'0\');\\n"
SQL="${SQL}${INS_WPM}(10+@wpmid,@wpuid,\'show_admin_bar_front\',\'true\');\\n"
SQL="${SQL}${INS_WPM}(11+@wpmid,@wpuid,\'locale\',\'\');\\n"
SQL="${SQL}${INS_WPM}(12+@wpmid,@wpuid,\'wp_capabilities\',\'a:1:{s:8:\\"customer\\";b:1;}\');\\n"
SQL="${SQL}${INS_WPM}(13+@wpmid,@wpuid,\'wp_user_level\',\'0\');\\n"
SQL="${SQL}${INS_WPM}(14+@wpmid,@wpuid,\'dismissed_wp_pointers\',\'\');\\n"
SQL="${SQL}${INS_WPM}(15+@wpmid,@wpuid,\'billing_first_name\',\'${NAM1}\');\\n"
SQL="${SQL}${INS_WPM}(16+@wpmid,@wpuid,\'billing_last_name\',\'${NAM2}\');\\n"
SQL="${SQL}${INS_WPM}(17+@wpmid,@wpuid,\'billing_company\',\'\');\\n"
SQL="${SQL}${INS_WPM}(18+@wpmid,@wpuid,\'billing_address_1\',\'somewhere\');\\n"
SQL="${SQL}${INS_WPM}(19+@wpmid,@wpuid,\'billing_address_2\',\'la la land\');\\n"
SQL="${SQL}${INS_WPM}(20+@wpmid,@wpuid,\'billing_city\',\'X\');\\n"
SQL="${SQL}${INS_WPM}(21+@wpmid,@wpuid,\'billing_postcode\',\'90210\');\\n"
SQL="${SQL}${INS_WPM}(22+@wpmid,@wpuid,\'billing_country\',\'AF\');\\n"
SQL="${SQL}${INS_WPM}(23+@wpmid,@wpuid,\'billing_state\',\'\');\\n"
SQL="${SQL}${INS_WPM}(24+@wpmid,@wpuid,\'billing_email\',\'${NAM1}.${NAM2}@example.org\');\\n"
SQL="${SQL}${INS_WPM}(25+@wpmid,@wpuid,\'shipping_first_name\',\'\');\\n"
SQL="${SQL}${INS_WPM}(26+@wpmid,@wpuid,\'shipping_last_name\',\'\');\\n"
SQL="${SQL}${INS_WPM}(27+@wpmid,@wpuid,\'shipping_company\',\'\');\\n"
SQL="${SQL}${INS_WPM}(28+@wpmid,@wpuid,\'shipping_address_1\',\'\');\\n"
SQL="${SQL}${INS_WPM}(29+@wpmid,@wpuid,\'shipping_address_2\',\'\');\\n"
SQL="${SQL}${INS_WPM}(30+@wpmid,@wpuid,\'shipping_city\',\'\');\\n"
SQL="${SQL}${INS_WPM}(31+@wpmid,@wpuid,\'shipping_postcode\',\'\');\\n"
SQL="${SQL}${INS_WPM}(32+@wpmid,@wpuid,\'shipping_country\',\'\');\\n"
SQL="${SQL}${INS_WPM}(33+@wpmid,@wpuid,\'shipping_state\',\'\');\\n"
# commit after each user
SQL="${SQL}commit;\\n"
echo -e "$SQL"
}
{
echo "set autocommit=off;\\n"
ins_test_user jane doe
ins_test_user joe bloggs
ins_test_user architeuthis dux
ins_test_user ftagn fnord
ins_test_user pete brick
ins_test_user kaiser soze
echo "set autocommit=on;\\n"
} | mysql -D $DB -u $DBUSER --password="$DBPASS"