How to Update db Table Prefix Via Terminal Command - wordpress

Per these excellent instructions, I can export the tables of a wordpress subsite from a multisite installation. However, I cannot manage to update the table_prefix of the db according to the instructions. Can anyone see what I am doing wrong? or provide another "neat" terminal "one-liner" to update the db table_prefix (see " #6 " below)?
synapsis:
Where:
mainsite = domain.localhost.mainsite.com
subsite = domain.com
#0 sudo su
#1 Create space for db export & conversion
mkdir /tmp/domain.localhost.mainsite.com/
mkdir /tmp/domain.localhost.mainsite.com/domain.com
#2 change to wp root directory
$ cd /var/www/html/domain.localhost.mainsite.com/
#3 Locate blog_id of relevant site (NEVER # 1, this is main site)
wp site list
#4 Export all the subsite db tables to new " .sql " file
wp db export --tables=$(wp db tables --url=domain.localhost.mainsite.com --format=csv --skip-plugins --skip-themes --allow-root) /tmp/domain.sql --allow-root
#5 Identify current db prefix
grep "table_prefix" wp-config.php
output: $table_prefix = 'wpb_';
#6 Change the table prefix to match new location db prefix (" 2nodeh_ ")
sed "s#wpb_<blog_id#>_:#2nodeh_#g" /tmp/domain.sql > /tmp/domain.localhost.mainsite.com/domain.com/domain.sql #This does not seem to work
#7 make " .sql " even smaller, using gzip
gzip /tmp/domain.localhost.mainsite.com/domain.com/domain.sql -c > /tmp/domain.localhost.mainsite.com/domain.com/domain.sql.gz
#8 (move db to safer storage space) upload db to new location and import
(php my admin fastest way)
#9 rsync plugins, themes, & uploads to new location
/wprootdirectory/wp-content/plugins/
/wprootdirectory/wp-content/themes/
/wprootdirectory/wp-content/uploads/sites/<blog_id#>/
Whenever I import the db into the new database the original table_prefix is still present. I know how to use mysql to change the table prefix. I am specifically looking for a single terminal command similar to #6 above... Any tips?

You can use the wp-cli rename package,, which works for me.
https://github.com/iandunn/wp-cli-rename-db-prefix
Note: Please remember to take backup of your existing database before you run the commands.
Thanks

Found the answer, apparently the syntax in item #6 of my question was incorrect, to change a wordpress table prefix using sed, use the following format:
sed --in-place --expression 's#`wp_<blog_id#>_#`<new_prefix>_#g' exported-db.sql
Notes:
1.) The above is specifically for exporting a subsite from a multisite as described on the question, but can be used in other scenarios as well
2.) While temptingly easy, DO NOT, use this method to replace urls if you are moving from "domain.localhost.mainsite.com" to "domain.com" because wordpress serializes urls in the db in some instances, instead use the handy sql query below via the phpmyadmin sql quesy interface, making appropriate url changes:
UPDATE wp_options SET option_value = replace(option_value, 'oldurl.com', 'newurl.com') WHERE option_name = 'home' OR option_name = 'siteurl';UPDATE wp_posts SET guid = replace(guid, 'oldurl.com','newurl.com');UPDATE wp_posts SET post_content = replace(post_content, 'oldurl.com', 'newurl.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'oldurl.com','newurl.com');
3.) As always.. BACKUP YOUR DB, BEFORE YOU DO ANY OF THIS

Related

How to simultaneously test all plugins, theme and db configuration of your wordpress website using phpunit?

I've battled with this question for hours now, searching far and wide through the web finding several guides to setup testing for individual plugins which created new a installation of WordPress and created a new empty database as testing ground for said plugin.
However, what I wanted was to test all my plugins at the same time, as many have integrations with each other and have their own configurations already set in the database which would need to be re-inserted into the newly created test database.
So, I simply edited the file bin/install-wp-tests.sh as described below:
In the function install_wp() include the line at the end of the function: cp -a /$USER/wordpress/wp-content/. $WP_CORE_DIR/wp-content/
In the function create_db(), change content of function to:
mysqldump $USER_wordpress > dump.sql --user="$DB_USER" --password="$DB_PASS"$EXTRA
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
mysql $DB_NAME < dump.sql --user="$DB_USER" --password="$DB_PASS"$EXTRA
(Note: In my case $USER_wordpress is the name of the wordpress databse, and /$USER/wordpress/wp-content/ is the absolute path to wp-content.)
This way, the tests are made using your entire current installation of wordpress including all plugins you've installed or created, and the your current database data.
To load your plugins, you need to specify them on the function _manually_load_plugin() on the file tests/bootstrap.php, by including the plugin like so:
require rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress/wp-content/plugins/' . 'exampleplugin/exampleplugin.php';
I've used the following guides:
https://poweredbycoffee.co.uk/unit-testing-with-wordpress/
https://maheshwaghmare.com/wordpress/blog/phpunit-tests/
https://wpmudev.com/blog/unit-testing-wordpress-plugins-phpunit/
https://sanjeebaryal.com.np/fixing-issues-while-setting-up-php-unit-tests-for-wordpress-plugins/
But non of them answered the fundamental question of how to include all your plugins and database configurations for your tests, so you could test multiple plugins inside the same test and using all your plugin configurations already set inside you db.

Issues after upgrading DB to mariaDB

I have recently built my rundeck server and created a DB using mariaDB and pointed rundeck to this. I followed the official documentation for this on the rundeck site. Since I have changed from the systemDB to mariaDB the service no longer starts.
My rundeck-config.properties file looks like this:
#loglevel.default is the default log level for jobs: ERROR,WARN,INFO,VERBOSE,DEBUG
loglevel.default=INFO
rdeck.base=/var/lib/rundeck
#rss.enabled if set to true enables RSS feeds that are public (non-authenticated)
rss.enabled=false
#change hostname here
grails.serverURL=http://IP OF SERVER:4440
dataSource.driverClassName=
dataSource.url = jdbc:mysql://IP OF SERVER/rundeck?autoReconnect=true&useSSL=false
dataSource.username = DB User
dataSource.password = Password
grails.plugin.databasemigration.updateOnStart=true
autoReconnect=true
#to store projects on backend
rundeck.projectsStorageType=db
#Encryption for key storage
rundeck.storage.provider.1.type=
rundeck.storage.provider.1.path=keys
rundeck.storage.converter.1.type=jasypt-encryption
rundeck.storage.converter.1.path=keys
rundeck.storage.converter.1.config.encryptorType=custom
rundeck.storage.converter.1.config.password=7ee99cf09ffc59e7
rundeck.storage.converter.1.config.algorithm=PBEWITHSHA256AND128BITAES-CBC-BC
rundeck.storage.converter.1.config.provider=BC
#Encryption for project config storage
rundeck.projectsStorageType=db
rundeck.config.storage.converter.1.type=jasypt-encryption
rundeck.config.storage.converter.1.path=projects
rundeck.config.storage.converter.1.config.password=7ee99cf09ffc59e7
rundeck.config.storage.converter.1.config.encryptorType=custom
rundeck.config.storage.converter.1.config.algorithm=PBEWITHSHA256AND128BITAES-CBC-BC
rundeck.config.storage.converter.1.config.provider=BC
rundeck.feature.repository.enabled=true
Can anyone help with this
A couple of things here:
Your dataSource.driverClassName is empty, set it to org.mariadb.jdbc.Driver, check the full example here.
Your rundeck.storage.provider.1.type is also empty, set it as rundeck.storage.provider.1.type=db.

"Modules are Outdated" Error

I get this error when I create a new module:
"Please upgrade your database: Run "bin/magento setup:upgrade" from the Magento root directory.
The following modules are outdated:
Sangeeta_Octan data: current version - none, required version - 0.0.1";i:1;s:1781:"#0
I searched on google and found no solution other than reinstalling Magento. Such as:
version has been changed from "2.0.0.0" to "2.0.0" during development,
so update tool can't recognize that "2.0.0.0" <= "2.0.0". Please,
re-install your application from scratch to get latest version. `
Do I have any options apart from reinstalling?
Change the setup_version of your module (Sangeeta_Octan) in
app/code/Sangeeta/Octan/etc/module.xml. Try a different version
name like setup_version="2.0.1" or setup_version="3.0.0"
Run bin/magento setup:upgrade
If that doesn't work, disable your module by changing your module name in app/etc/config.phpfrom Sangeeta_Octan => 1 to Sangeeta_Octan => 0. Then run bin/magento setup:upgrade
I hope below solution also solve your problem.
https://magento.stackexchange.com/questions/112293/mysql-error-and-possible-duplicates-running-bin-magento-setupupgrade-after-rena/112299#112299
in mysql find the table setup_module It will have 3 fields. Find the NULL values in data_version & have them match the schema_version
As an alternative, you can access your magento database and look at the table setup_module
You will see a list of all installed modules and you can manually set the schema/data version numbers here.
Delete the offending rows from the setup_module table (if they are there) and run the command bin/magento setup:upgrade from your Magento 2 root directory.
This is happens because of something wrong while running "bin/magento setup:upgrade" and the data_version in Module versions registry is null. It is loaded from DB, We can just proceed by manually changing it in db.
Go db via php myadmin and check "setup_module" table, the
data_version which are mentioned "null".
Login to Mysql database => then update table setup_module of the "data_version" column same as "schema_version"

Migrating to local server

I have my wordpress site on my local server at the following path :
wordpress-4.2.3\wordpress\wp-content\themes\mytheme
and the url to access my local site is:
http://localhost/wordpress-4.2.3/wordpress/
Now I need to migrate it to another local server, for this I have imported database successfully and copied wordpress folder and placed it in my project's folder as below:
my-project-name\wp-content\themes\mytheme
and also changed WordPress Address (URL) and Site Address (URL) which is initially http://localhost/wordpress-4.2.3/wordpress/ to http://local-server-ip/my-project-name/ but it is not working. Any suggestions?
You need to replace all URLs in the database, it is not sufficient to change the values only in the options table (otherwise links and images are corrupted).
Manual Migration:
Export your database (e.g. through phpMyAdmin) and do a search&replace with the old and new url
Update your wp-config.php (database name, login and passwort)
Update your .htaccess file (check the RewriteBase and Rewrite Rule)
Migration with Plugin:
Download a migration plugin, such as "Wordpress Duplicator"
Copy all data to folder "my-project-name"
Open your database > click on SQL tab > Run these commands manually
---------------------------------------------------------------------------
WP Update Query in database
---------------------------------------------------------------------------
UPDATE wp_options SET option_value = replace(option_value, 'http://localhost/wordpress-4.2.3/wordpress', 'http://local-server-ip/my-project-name') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = REPLACE (guid, 'http://localhost/wordpress-4.2.3/wordpress', 'http://local-server-ip/my-project-name');
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://localhost/wordpress-4.2.3/wordpress', 'http://local-server-ip/my-project-name');
UPDATE wp_posts SET post_content = REPLACE (post_content, 'src="http://localhost/wordpress-4.2.3/wordpress','src="http://local-server-ip/my-project-name');
then login to your wordpress admin panel go to Setting > Permalinks > click on Save Changes button.
Note: if you have changed your database don't forget to change credintials in wp-config.php

WP from remote to local

I really hope you can help me!
I need to make some changes on a WP website from Xampp on my mac.
I did the backup of the DB and via FTP I copied all the files in XAMPP/htdocs/b
I modified the wp-config.php as follow:
define('DB_NAME', 'db:name');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
after importing the DB I also changed the siteurl under wp_options.
Now my problem is this... wen I open the website no pictures loads and any link goes to /xampp/ folder
I tried so many things but nothing seams to work. I cannot even access the wp-login.php due to user and psw wrong.
please please help!
* I realise that img url is: img src="/wp-content/themes/nm/images/common/impcontent/mapfiller.jpg" so it looks for the imgs into the localhost/wp-content/... insted of localhost/b/wp-content/... how do I change that???
In wp-config.php set the following values to your proper values:
define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');
Once this is working, install and run https://wordpress.org/plugins/velvet-blues-update-urls/ to fix the path issues.
Execute the following query in phpmyadmin, note: wp_ is prefix of table. If you have changed the prefix of the table at the time of installation then use that prefix with wp_ in the below query
UPDATE wp_options SET option_value = replace(option_value, 'old_domain_url_here', 'new_domain_url_here') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'old_domain_url_here', 'new_domain_url_here');
UPDATE wp_posts SET post_content = replace(post_content, 'old_domain_url_here', 'new_domain_url_here');
Try using https://github.com/wp-sync-db/wp-sync-db
Install it both on localhost and on remote. Follow the instructions, set correct domains and push from local to remote. It should work nice :)

Resources