Last active
May 6, 2020 13:40
-
-
Save yousan/10b44cea1f3d66ee711cc7161e2d5a8a to your computer and use it in GitHub Desktop.
Revisions
-
yousan revised this gist
May 6, 2020 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,7 +31,8 @@ IFS=$'\n' for TABLE in ${TABLES} do NEW_TABLE=`echo ${TABLE} | sed -e 's/^'${PREFIX}'/'${NEW_PREFIX}'/'` echo 'DROP TABLE IF EXISTS ' ${NEW_TABLE} | wp db cli # Remove tables echo 'RENAME TABLE `'${TABLE}'` TO `'${NEW_TABLE}'`;' | wp db cli # Do RENAME here done # Change table prefix at wp-config.php -
yousan revised this gist
May 4, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,4 +35,4 @@ echo 'RENAME table `'${TABLE}'` TO `'${NEW_TABLE}'`;' | wp db cli # Do RENAME he done # Change table prefix at wp-config.php wp config set table_prefix ${NEW_PREFIX} -
yousan revised this gist
May 4, 2020 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,12 @@ # Change WordPress table prefix # WP-CLI is reqiured # WARNING: BACKUP is strongly recommended # usage: change_db_prefix.sh wp_new_prefix_ # 1. Get all WordPress tables # 2. Change wp_options and wp_usermeta values # 3. Rename tables # 4. Change table prefix at wp-config.php PREFIX=`wp db prefix` NEW_PREFIX=$1 -
yousan created this gist
May 4, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ #!/usr/bin/env bash # Change WordPress table prefix # WP-CLI is reqiured # WARNING: BACKUP is strongly recommended PREFIX=`wp db prefix` NEW_PREFIX=$1 if [[ -z "$1" ]] ; then echo 'No prefix is specified. Please specify new table prefix.' exit; fi # Get all WordPress tables # @see https://developer.wordpress.org/cli/commands/db/tables/ TABLES=`wp db tables --all-tables-with-prefix` # Change options and usermeta table value wp search-replace ${PREFIX} ${NEW_PREFIX} ${PREFIX}options wp search-replace ${PREFIX} ${NEW_PREFIX} ${PREFIX}usermeta # Rename tables # @see https://www.wpbeginner.com/wp-tutorials/how-to-change-the-wordpress-database-prefix-to-improve-security/ IFS=$'\n' for TABLE in ${TABLES} do NEW_TABLE=`echo ${TABLE} | sed -e 's/^'${PREFIX}'/'${NEW_PREFIX}'/'` echo 'RENAME table `'${TABLE}'` TO `'${NEW_TABLE}'`;' | wp db cli # Do RENAME here done # Change table prefix at wp-config.php set table_prefix ${NEW_PREFIX}