brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: wp db cli opens a MySQL prompt for the WordPress database

WordPress
~/tips/tip-wordpress-db-cli-mysql-shell

wp db cli

Opens an interactive MySQL client already logged in to the site's database.

For one query, wp db query is enough. To poke around for a while, I’d want a real prompt.

wp db cli

This starts the mysql client (or mariadb) with the database name, user, password and host from wp-config.php. You land on a mysql> prompt in the right database, so SHOW TABLES; works right away. Type exit to leave.

Extra flags go through to the client. I like --pager=less for wide tables, and --database= lets you open another database with the same user. The character set comes from DB_CHARSET, so text with accents shows up properly.

Your own ~/.my.cnf is skipped on purpose, so a wrong setting in there cannot break the login. Add --defaults if you do want it.

The client has to be installed on the machine where WP-CLI runs. In the official WordPress Docker image it is not. And of course this is a live prompt on your production data: an UPDATE without a WHERE runs on every row and there is no undo. Export first if you plan to change things.

Further reading: wp db cli

More WordPress tips wp user application-password create anna backup-script --porcelain define( 'MEDIA_TRASH', true ); wp cli check-update wp theme delete --all wp media image-size All WordPress tips (85) All topics

Link