Using wp-cli commands to create and import WordPress databases
You can use wp-cli to do a number of tasks around the WordPress database including creation and importing, below are a few commands and what they do.
Remove all existing WordPress tables
wp db reset
This will remove all existing WordPress tables and leave the db empty, but you still have a db.
Delete the WordPress database
wp db drop
This will delete the actual database.
Create a new WordPress database
wp db create
This will create a brand new database.
Import a WordPress database
wp db import awordpressdb.sql
This will import a database.
Export a WordPress database
wp db export
This will export a database.
Search and replace text strings in the database
wp search-replace 'find-word' 'replace-word' --dry-run
wp search-replace 'find-word' 'replace-word'
So the search and replace can be done with a –dry-run parameter which won’t make any permanent change, run without it to make the change. This is a great command to change the WordPress site url.
Optimize a WordPress database
wp db optimize
This will optimize a WordPress database.
Repair a WordPress database
wp db repair
This will repair a WordPress database.
Check database size in mb
wp db size --size_format=mb
Check the database size can use also a number of size parameters including kb, gb etc
More info on wp-cli WordPress DB commands also you can do many things with wp-cli including changing the WordPress installation version.