{"id":13824661,"url":"https://github.com/wp-cli/db-command","last_synced_at":"2025-04-14T08:55:53.666Z","repository":{"id":44626803,"uuid":"83558179","full_name":"wp-cli/db-command","owner":"wp-cli","description":"Performs basic database operations using credentials stored in wp-config.php.","archived":false,"fork":false,"pushed_at":"2025-03-28T17:26:09.000Z","size":9238,"stargazers_count":72,"open_issues_count":18,"forks_count":62,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-07T02:06:54.979Z","etag":null,"topics":["cli","db","hacktoberfest","mariadb","mysql","wordpress","wp-cli","wp-cli-package"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wp-cli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-01T13:36:54.000Z","updated_at":"2025-03-28T17:26:14.000Z","dependencies_parsed_at":"2024-05-04T06:28:31.386Z","dependency_job_id":"344399d7-e554-4746-8119-cde7b1a7627a","html_url":"https://github.com/wp-cli/db-command","commit_stats":{"total_commits":787,"total_committers":82,"mean_commits":9.597560975609756,"dds":0.7611181702668361,"last_synced_commit":"258b9b348d5d1cf884881b1bd1efc819e735af0d"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-cli%2Fdb-command","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-cli%2Fdb-command/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-cli%2Fdb-command/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-cli%2Fdb-command/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wp-cli","download_url":"https://codeload.github.com/wp-cli/db-command/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248852111,"owners_count":21171839,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","db","hacktoberfest","mariadb","mysql","wordpress","wp-cli","wp-cli-package"],"created_at":"2024-08-04T09:01:06.793Z","updated_at":"2025-04-14T08:55:53.638Z","avatar_url":"https://github.com/wp-cli.png","language":"PHP","readme":"wp-cli/db-command\n=================\n\nPerforms basic database operations using credentials stored in wp-config.php.\n\n[![Testing](https://github.com/wp-cli/db-command/actions/workflows/testing.yml/badge.svg)](https://github.com/wp-cli/db-command/actions/workflows/testing.yml)\n\nQuick links: [Using](#using) | [Installing](#installing) | [Contributing](#contributing) | [Support](#support)\n\n## Using\n\nThis package implements the following commands:\n\n### wp db\n\nPerforms basic database operations using credentials stored in wp-config.php.\n\n~~~\nwp db\n~~~\n\n**EXAMPLES**\n\n    # Create a new database.\n    $ wp db create\n    Success: Database created.\n\n    # Drop an existing database.\n    $ wp db drop --yes\n    Success: Database dropped.\n\n    # Reset the current database.\n    $ wp db reset --yes\n    Success: Database reset.\n\n    # Execute a SQL query stored in a file.\n    $ wp db query \u003c debug.sql\n\n\n\n### wp db clean\n\nRemoves all tables with `$table_prefix` from the database.\n\n~~~\nwp db clean [--dbuser=\u003cvalue\u003e] [--dbpass=\u003cvalue\u003e] [--yes] [--defaults]\n~~~\n\nRuns `DROP_TABLE` for each table that has a `$table_prefix` as specified\nin wp-config.php.\n\n**OPTIONS**\n\n\t[--dbuser=\u003cvalue\u003e]\n\t\tUsername to pass to mysql. Defaults to DB_USER.\n\n\t[--dbpass=\u003cvalue\u003e]\n\t\tPassword to pass to mysql. Defaults to DB_PASSWORD.\n\n\t[--yes]\n\t\tAnswer yes to the confirmation message.\n\n\t[--defaults]\n\t\tLoads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.\n\n**EXAMPLES**\n\n    # Delete all tables that match the current site prefix.\n    $ wp db clean --yes\n    Success: Tables dropped.\n\n\n\n### wp db create\n\nCreates a new database.\n\n~~~\nwp db create [--dbuser=\u003cvalue\u003e] [--dbpass=\u003cvalue\u003e] [--defaults]\n~~~\n\nRuns `CREATE_DATABASE` SQL statement using `DB_HOST`, `DB_NAME`,\n`DB_USER` and `DB_PASSWORD` database credentials specified in\nwp-config.php.\n\n**OPTIONS**\n\n\t[--dbuser=\u003cvalue\u003e]\n\t\tUsername to pass to mysql. Defaults to DB_USER.\n\n\t[--dbpass=\u003cvalue\u003e]\n\t\tPassword to pass to mysql. Defaults to DB_PASSWORD.\n\n\t[--defaults]\n\t\tLoads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.\n\n**EXAMPLES**\n\n    $ wp db create\n    Success: Database created.\n\n\n\n### wp db drop\n\nDeletes the existing database.\n\n~~~\nwp db drop [--dbuser=\u003cvalue\u003e] [--dbpass=\u003cvalue\u003e] [--yes] [--defaults]\n~~~\n\nRuns `DROP_DATABASE` SQL statement using `DB_HOST`, `DB_NAME`,\n`DB_USER` and `DB_PASSWORD` database credentials specified in\nwp-config.php.\n\n**OPTIONS**\n\n\t[--dbuser=\u003cvalue\u003e]\n\t\tUsername to pass to mysql. Defaults to DB_USER.\n\n\t[--dbpass=\u003cvalue\u003e]\n\t\tPassword to pass to mysql. Defaults to DB_PASSWORD.\n\n\t[--yes]\n\t\tAnswer yes to the confirmation message.\n\n\t[--defaults]\n\t\tLoads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.\n\n**EXAMPLES**\n\n    $ wp db drop --yes\n    Success: Database dropped.\n\n\n\n### wp db reset\n\nRemoves all tables from the database.\n\n~~~\nwp db reset [--dbuser=\u003cvalue\u003e] [--dbpass=\u003cvalue\u003e] [--yes] [--defaults]\n~~~\n\nRuns `DROP_DATABASE` and `CREATE_DATABASE` SQL statements using\n`DB_HOST`, `DB_NAME`, `DB_USER` and `DB_PASSWORD` database credentials\nspecified in wp-config.php.\n\n**OPTIONS**\n\n\t[--dbuser=\u003cvalue\u003e]\n\t\tUsername to pass to mysql. Defaults to DB_USER.\n\n\t[--dbpass=\u003cvalue\u003e]\n\t\tPassword to pass to mysql. Defaults to DB_PASSWORD.\n\n\t[--yes]\n\t\tAnswer yes to the confirmation message.\n\n\t[--defaults]\n\t\tLoads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.\n\n**EXAMPLES**\n\n    $ wp db reset --yes\n    Success: Database reset.\n\n\n\n### wp db check\n\nChecks the current status of the database.\n\n~~~\nwp db check [--dbuser=\u003cvalue\u003e] [--dbpass=\u003cvalue\u003e] [--\u003cfield\u003e=\u003cvalue\u003e] [--defaults]\n~~~\n\nRuns `mysqlcheck` utility with `--check` using `DB_HOST`,\n`DB_NAME`, `DB_USER` and `DB_PASSWORD` database credentials\nspecified in wp-config.php.\n\n[See docs](http://dev.mysql.com/doc/refman/5.7/en/check-table.html)\nfor more details on the `CHECK TABLE` statement.\n\nThis command does not check whether WordPress is installed;\nto do that run `wp core is-installed`.\n\n**OPTIONS**\n\n\t[--dbuser=\u003cvalue\u003e]\n\t\tUsername to pass to mysqlcheck. Defaults to DB_USER.\n\n\t[--dbpass=\u003cvalue\u003e]\n\t\tPassword to pass to mysqlcheck. Defaults to DB_PASSWORD.\n\n\t[--\u003cfield\u003e=\u003cvalue\u003e]\n\t\tExtra arguments to pass to mysqlcheck. [Refer to mysqlcheck docs](https://dev.mysql.com/doc/en/mysqlcheck.html).\n\n\t[--defaults]\n\t\tLoads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.\n\n**EXAMPLES**\n\n    $ wp db check\n    Success: Database checked.\n\n\n\n### wp db optimize\n\nOptimizes the database.\n\n~~~\nwp db optimize [--dbuser=\u003cvalue\u003e] [--dbpass=\u003cvalue\u003e] [--\u003cfield\u003e=\u003cvalue\u003e] [--defaults]\n~~~\n\nRuns `mysqlcheck` utility with `--optimize=true` using `DB_HOST`,\n`DB_NAME`, `DB_USER` and `DB_PASSWORD` database credentials\nspecified in wp-config.php.\n\n[See docs](http://dev.mysql.com/doc/refman/5.7/en/optimize-table.html)\nfor more details on the `OPTIMIZE TABLE` statement.\n\n**OPTIONS**\n\n\t[--dbuser=\u003cvalue\u003e]\n\t\tUsername to pass to mysqlcheck. Defaults to DB_USER.\n\n\t[--dbpass=\u003cvalue\u003e]\n\t\tPassword to pass to mysqlcheck. Defaults to DB_PASSWORD.\n\n\t[--\u003cfield\u003e=\u003cvalue\u003e]\n\t\tExtra arguments to pass to mysqlcheck. [Refer to mysqlcheck docs](https://dev.mysql.com/doc/en/mysqlcheck.html).\n\n\t[--defaults]\n\t\tLoads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.\n\n**EXAMPLES**\n\n    $ wp db optimize\n    Success: Database optimized.\n\n\n\n### wp db prefix\n\nDisplays the database table prefix.\n\n~~~\nwp db prefix \n~~~\n\nDisplay the database table prefix, as defined by the database handler's interpretation of the current site.\n\n**EXAMPLES**\n\n    $ wp db prefix\n    wp_\n\n\n\n### wp db repair\n\nRepairs the database.\n\n~~~\nwp db repair [--dbuser=\u003cvalue\u003e] [--dbpass=\u003cvalue\u003e] [--\u003cfield\u003e=\u003cvalue\u003e] [--defaults]\n~~~\n\nRuns `mysqlcheck` utility with `--repair=true` using `DB_HOST`,\n`DB_NAME`, `DB_USER` and `DB_PASSWORD` database credentials\nspecified in wp-config.php.\n\n[See docs](http://dev.mysql.com/doc/refman/5.7/en/repair-table.html) for\nmore details on the `REPAIR TABLE` statement.\n\n**OPTIONS**\n\n\t[--dbuser=\u003cvalue\u003e]\n\t\tUsername to pass to mysqlcheck. Defaults to DB_USER.\n\n\t[--dbpass=\u003cvalue\u003e]\n\t\tPassword to pass to mysqlcheck. Defaults to DB_PASSWORD.\n\n\t[--\u003cfield\u003e=\u003cvalue\u003e]\n\t\tExtra arguments to pass to mysqlcheck. [Refer to mysqlcheck docs](https://dev.mysql.com/doc/en/mysqlcheck.html).\n\n\t[--defaults]\n\t\tLoads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.\n\n**EXAMPLES**\n\n    $ wp db repair\n    Success: Database repaired.\n\n\n\n### wp db cli\n\nOpens a MySQL console using credentials from wp-config.php\n\n~~~\nwp db cli [--database=\u003cdatabase\u003e] [--default-character-set=\u003ccharacter-set\u003e] [--dbuser=\u003cvalue\u003e] [--dbpass=\u003cvalue\u003e] [--\u003cfield\u003e=\u003cvalue\u003e] [--defaults]\n~~~\n\n**OPTIONS**\n\n\t[--database=\u003cdatabase\u003e]\n\t\tUse a specific database. Defaults to DB_NAME.\n\n\t[--default-character-set=\u003ccharacter-set\u003e]\n\t\tUse a specific character set. Defaults to DB_CHARSET when defined.\n\n\t[--dbuser=\u003cvalue\u003e]\n\t\tUsername to pass to mysql. Defaults to DB_USER.\n\n\t[--dbpass=\u003cvalue\u003e]\n\t\tPassword to pass to mysql. Defaults to DB_PASSWORD.\n\n\t[--\u003cfield\u003e=\u003cvalue\u003e]\n\t\tExtra arguments to pass to mysql. [Refer to mysql docs](https://dev.mysql.com/doc/en/mysql-command-options.html).\n\n\t[--defaults]\n\t\tLoads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.\n\n**EXAMPLES**\n\n    # Open MySQL console\n    $ wp db cli\n    mysql\u003e\n\n\n\n### wp db query\n\nExecutes a SQL query against the database.\n\n~~~\nwp db query [\u003csql\u003e] [--dbuser=\u003cvalue\u003e] [--dbpass=\u003cvalue\u003e] [--\u003cfield\u003e=\u003cvalue\u003e] [--defaults]\n~~~\n\nExecutes an arbitrary SQL query using `DB_HOST`, `DB_NAME`, `DB_USER`\n and `DB_PASSWORD` database credentials specified in wp-config.php.\n\nUse the `--skip-column-names` MySQL argument to exclude the headers\nfrom a SELECT query. Pipe the output to remove the ASCII table\nentirely.\n\n**OPTIONS**\n\n\t[\u003csql\u003e]\n\t\tA SQL query. If not passed, will try to read from STDIN.\n\n\t[--dbuser=\u003cvalue\u003e]\n\t\tUsername to pass to mysql. Defaults to DB_USER.\n\n\t[--dbpass=\u003cvalue\u003e]\n\t\tPassword to pass to mysql. Defaults to DB_PASSWORD.\n\n\t[--\u003cfield\u003e=\u003cvalue\u003e]\n\t\tExtra arguments to pass to mysql. [Refer to mysql docs](https://dev.mysql.com/doc/en/mysql-command-options.html).\n\n\t[--defaults]\n\t\tLoads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.\n\n**EXAMPLES**\n\n    # Execute a query stored in a file\n    $ wp db query \u003c debug.sql\n\n    # Query for a specific value in the database (pipe the result to remove the ASCII table borders)\n    $ wp db query 'SELECT option_value FROM wp_options WHERE option_name=\"home\"' --skip-column-names\n    +---------------------+\n    | https://example.com |\n    +---------------------+\n\n    # Check all tables in the database\n    $ wp db query \"CHECK TABLE $(wp db tables | paste -s -d, -);\"\n    +---------------------------------------+-------+----------+----------+\n    | Table                                 | Op    | Msg_type | Msg_text |\n    +---------------------------------------+-------+----------+----------+\n    | wordpress_dbase.wp_users              | check | status   | OK       |\n    | wordpress_dbase.wp_usermeta           | check | status   | OK       |\n    | wordpress_dbase.wp_posts              | check | status   | OK       |\n    | wordpress_dbase.wp_comments           | check | status   | OK       |\n    | wordpress_dbase.wp_links              | check | status   | OK       |\n    | wordpress_dbase.wp_options            | check | status   | OK       |\n    | wordpress_dbase.wp_postmeta           | check | status   | OK       |\n    | wordpress_dbase.wp_terms              | check | status   | OK       |\n    | wordpress_dbase.wp_term_taxonomy      | check | status   | OK       |\n    | wordpress_dbase.wp_term_relationships | check | status   | OK       |\n    | wordpress_dbase.wp_termmeta           | check | status   | OK       |\n    | wordpress_dbase.wp_commentmeta        | check | status   | OK       |\n    +---------------------------------------+-------+----------+----------+\n\n    # Pass extra arguments through to MySQL\n    $ wp db query 'SELECT * FROM wp_options WHERE option_name=\"home\"' --skip-column-names\n    +---+------+------------------------------+-----+\n    | 2 | home | http://wordpress-develop.dev | yes |\n    +---+------+------------------------------+-----+\n\n**MULTISITE USAGE**\n\nPlease note that the global `--url` parameter will have no effect on this command.\nIn order to query for data in a site other than your primary site,\nyou will need to manually modify the table names to use the prefix that includes the site's ID.\n\nFor example, to get the `home` option for your second site, modify the example above like so:\n\n    $ wp db query 'SELECT option_value FROM wp_2_options WHERE option_name=\"home\"' --skip-column-names\n    +----------------------+\n    | https://example2.com |\n    +----------------------+\n\nTo confirm the ID for the site you want to query, you can use the `wp site list` command:\n\n    # wp site list --fields=blog_id,url\n    +---------+-----------------------+\n    | blog_id | url                   |\n    +---------+-----------------------+\n    | 1       | https://example1.com/ |\n    | 2       | https://example2.com/ |\n    +---------+-----------------------+\n\n\n\n### wp db export\n\nExports the database to a file or to STDOUT.\n\n~~~\nwp db export [\u003cfile\u003e] [--dbuser=\u003cvalue\u003e] [--dbpass=\u003cvalue\u003e] [--\u003cfield\u003e=\u003cvalue\u003e] [--tables=\u003ctables\u003e] [--exclude_tables=\u003ctables\u003e] [--include-tablespaces] [--porcelain] [--add-drop-table] [--defaults]\n~~~\n\nRuns `mysqldump` utility using `DB_HOST`, `DB_NAME`, `DB_USER` and\n`DB_PASSWORD` database credentials specified in wp-config.php. Accepts any valid `mysqldump` flags.\n\n**OPTIONS**\n\n\t[\u003cfile\u003e]\n\t\tThe name of the SQL file to export. If '-', then outputs to STDOUT. If\n\t\tomitted, it will be '{dbname}-{Y-m-d}-{random-hash}.sql'.\n\n\t[--dbuser=\u003cvalue\u003e]\n\t\tUsername to pass to mysqldump. Defaults to DB_USER.\n\n\t[--dbpass=\u003cvalue\u003e]\n\t\tPassword to pass to mysqldump. Defaults to DB_PASSWORD.\n\n\t[--\u003cfield\u003e=\u003cvalue\u003e]\n\t\tExtra arguments to pass to mysqldump. [Refer to mysqldump docs](https://dev.mysql.com/doc/en/mysqldump.html#mysqldump-option-summary).\n\n\t[--tables=\u003ctables\u003e]\n\t\tThe comma separated list of specific tables to export. Excluding this parameter will export all tables in the database.\n\n\t[--exclude_tables=\u003ctables\u003e]\n\t\tThe comma separated list of specific tables that should be skipped from exporting. Excluding this parameter will export all tables in the database.\n\n\t[--include-tablespaces]\n\t\tSkips adding the default --no-tablespaces option to mysqldump.\n\n\t[--porcelain]\n\t\tOutput filename for the exported database.\n\n\t[--add-drop-table]\n\t\tInclude a `DROP TABLE IF EXISTS` statement before each `CREATE TABLE` statement.\n\n\t[--defaults]\n\t\tLoads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.\n\n**EXAMPLES**\n\n    # Export database with drop query included\n    $ wp db export --add-drop-table\n    Success: Exported to 'wordpress_dbase-db72bb5.sql'.\n\n    # Export certain tables\n    $ wp db export --tables=wp_options,wp_users\n    Success: Exported to 'wordpress_dbase-db72bb5.sql'.\n\n    # Export all tables matching a wildcard\n    $ wp db export --tables=$(wp db tables 'wp_user*' --format=csv)\n    Success: Exported to 'wordpress_dbase-db72bb5.sql'.\n\n    # Export all tables matching prefix\n    $ wp db export --tables=$(wp db tables --all-tables-with-prefix --format=csv)\n    Success: Exported to 'wordpress_dbase-db72bb5.sql'.\n\n    # Export certain posts without create table statements\n    $ wp db export --no-create-info=true --tables=wp_posts --where=\"ID in (100,101,102)\"\n    Success: Exported to 'wordpress_dbase-db72bb5.sql'.\n\n    # Export relating meta for certain posts without create table statements\n    $ wp db export --no-create-info=true --tables=wp_postmeta --where=\"post_id in (100,101,102)\"\n    Success: Exported to 'wordpress_dbase-db72bb5.sql'.\n\n    # Skip certain tables from the exported database\n    $ wp db export --exclude_tables=wp_options,wp_users\n    Success: Exported to 'wordpress_dbase-db72bb5.sql'.\n\n    # Skip all tables matching a wildcard from the exported database\n    $ wp db export --exclude_tables=$(wp db tables 'wp_user*' --format=csv)\n    Success: Exported to 'wordpress_dbase-db72bb5.sql'.\n\n    # Skip all tables matching prefix from the exported database\n    $ wp db export --exclude_tables=$(wp db tables --all-tables-with-prefix --format=csv)\n    Success: Exported to 'wordpress_dbase-db72bb5.sql'.\n\n    # Export database to STDOUT.\n    $ wp db export -\n    -- MySQL dump 10.13  Distrib 5.7.19, for osx10.12 (x86_64)\n    --\n    -- Host: localhost    Database: wpdev\n    -- ------------------------------------------------------\n    -- Server version    5.7.19\n    ...\n\n\n\n### wp db import\n\nImports a database from a file or from STDIN.\n\n~~~\nwp db import [\u003cfile\u003e] [--dbuser=\u003cvalue\u003e] [--dbpass=\u003cvalue\u003e] [--\u003cfield\u003e=\u003cvalue\u003e] [--skip-optimization] [--defaults]\n~~~\n\nRuns SQL queries using `DB_HOST`, `DB_NAME`, `DB_USER` and\n`DB_PASSWORD` database credentials specified in wp-config.php. This\ndoes not create database by itself and only performs whatever tasks are\ndefined in the SQL.\n\n**OPTIONS**\n\n\t[\u003cfile\u003e]\n\t\tThe name of the SQL file to import. If '-', then reads from STDIN. If omitted, it will look for '{dbname}.sql'.\n\n\t[--dbuser=\u003cvalue\u003e]\n\t\tUsername to pass to mysql. Defaults to DB_USER.\n\n\t[--dbpass=\u003cvalue\u003e]\n\t\tPassword to pass to mysql. Defaults to DB_PASSWORD.\n\n\t[--\u003cfield\u003e=\u003cvalue\u003e]\n\t\tExtra arguments to pass to mysql. [Refer to mysql binary docs](https://dev.mysql.com/doc/refman/8.0/en/mysql-command-options.html).\n\n\t[--skip-optimization]\n\t\tWhen using an SQL file, do not include speed optimization such as disabling auto-commit and key checks.\n\n\t[--defaults]\n\t\tLoads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.\n\n**EXAMPLES**\n\n    # Import MySQL from a file.\n    $ wp db import wordpress_dbase.sql\n    Success: Imported from 'wordpress_dbase.sql'.\n\n\n\n### wp db search\n\nFinds a string in the database.\n\n~~~\nwp db search \u003csearch\u003e [\u003ctables\u003e...] [--network] [--all-tables-with-prefix] [--all-tables] [--before_context=\u003cnum\u003e] [--after_context=\u003cnum\u003e] [--regex] [--regex-flags=\u003cregex-flags\u003e] [--regex-delimiter=\u003cregex-delimiter\u003e] [--table_column_once] [--one_line] [--matches_only] [--stats] [--table_column_color=\u003ccolor_code\u003e] [--id_color=\u003ccolor_code\u003e] [--match_color=\u003ccolor_code\u003e] [--fields=\u003cfields\u003e] [--format=\u003cformat\u003e]\n~~~\n\nSearches through all of the text columns in a selection of database tables for a given string, Outputs colorized references to the string.\n\nDefaults to searching through all tables registered to $wpdb. On multisite, this default is limited to the tables for the current site.\n\n**OPTIONS**\n\n\t\u003csearch\u003e\n\t\tString to search for. The search is case-insensitive by default.\n\n\t[\u003ctables\u003e...]\n\t\tOne or more tables to search through for the string.\n\n\t[--network]\n\t\tSearch through all the tables registered to $wpdb in a multisite install.\n\n\t[--all-tables-with-prefix]\n\t\tSearch through all tables that match the registered table prefix, even if not registered on $wpdb. On one hand, sometimes plugins use tables without registering them to $wpdb. On another hand, this could return tables you don't expect. Overrides --network.\n\n\t[--all-tables]\n\t\tSearch through ALL tables in the database, regardless of the prefix, and even if not registered on $wpdb. Overrides --network and --all-tables-with-prefix.\n\n\t[--before_context=\u003cnum\u003e]\n\t\tNumber of characters to display before the match.\n\t\t---\n\t\tdefault: 40\n\t\t---\n\n\t[--after_context=\u003cnum\u003e]\n\t\tNumber of characters to display after the match.\n\t\t---\n\t\tdefault: 40\n\t\t---\n\n\t[--regex]\n\t\tRuns the search as a regular expression (without delimiters). The search becomes case-sensitive (i.e. no PCRE flags are added). Delimiters must be escaped if they occur in the expression. Because the search is run on individual columns, you can use the `^` and `$` tokens to mark the start and end of a match, respectively.\n\n\t[--regex-flags=\u003cregex-flags\u003e]\n\t\tPass PCRE modifiers to the regex search (e.g. 'i' for case-insensitivity).\n\n\t[--regex-delimiter=\u003cregex-delimiter\u003e]\n\t\tThe delimiter to use for the regex. It must be escaped if it appears in the search string. The default value is the result of `chr(1)`.\n\n\t[--table_column_once]\n\t\tOutput the 'table:column' line once before all matching row lines in the table column rather than before each matching row.\n\n\t[--one_line]\n\t\tPlace the 'table:column' output on the same line as the row id and match ('table:column:id:match'). Overrides --table_column_once.\n\n\t[--matches_only]\n\t\tOnly output the string matches (including context). No 'table:column's or row ids are outputted.\n\n\t[--stats]\n\t\tOutput stats on the number of matches found, time taken, tables/columns/rows searched, tables skipped.\n\n\t[--table_column_color=\u003ccolor_code\u003e]\n\t\tPercent color code to use for the 'table:column' output. For a list of available percent color codes, see below. Default '%G' (bright green).\n\n\t[--id_color=\u003ccolor_code\u003e]\n\t\tPercent color code to use for the row id output. For a list of available percent color codes, see below. Default '%Y' (bright yellow).\n\n\t[--match_color=\u003ccolor_code\u003e]\n\t\tPercent color code to use for the match (unless both before and after context are 0, when no color code is used). For a list of available percent color codes, see below. Default '%3%k' (black on a mustard background).\n\n\t[--fields=\u003cfields\u003e]\n\t\tGet a specific subset of the fields.\n\n\t[--format=\u003cformat\u003e]\n\t\tRender output in a particular format.\n\t\t---\n\t\toptions:\n\t\t  - table\n\t\t  - csv\n\t\t  - json\n\t\t  - yaml\n\t\t  - ids\n\t\t  - count\n\t\t---\n\nThe percent color codes available are:\n\n| Code | Color\n| ---- | -----\n|  %y  | Yellow (dark) (mustard)\n|  %g  | Green (dark)\n|  %b  | Blue (dark)\n|  %r  | Red (dark)\n|  %m  | Magenta (dark)\n|  %c  | Cyan (dark)\n|  %w  | White (dark) (light gray)\n|  %k  | Black\n|  %Y  | Yellow (bright)\n|  %G  | Green (bright)\n|  %B  | Blue (bright)\n|  %R  | Red (bright)\n|  %M  | Magenta (bright)\n|  %C  | Cyan (bright)\n|  %W  | White\n|  %K  | Black (bright) (dark gray)\n|  %3  | Yellow background (dark) (mustard)\n|  %2  | Green background (dark)\n|  %4  | Blue background (dark)\n|  %1  | Red background (dark)\n|  %5  | Magenta background (dark)\n|  %6  | Cyan background (dark)\n|  %7  | White background (dark) (light gray)\n|  %0  | Black background\n|  %8  | Reverse\n|  %U  | Underline\n|  %F  | Blink (unlikely to work)\n\nThey can be concatenated. For instance, the default match color of black on a mustard (dark yellow) background `%3%k` can be made black on a bright yellow background with `%Y%0%8`.\n\n**AVAILABLE FIELDS**\n\nThese fields will be displayed by default for each result:\n\n* table\n* column\n* match\n* primary_key_name\n* primary_key_value\n\n**EXAMPLES**\n\n    # Search through the database for the 'wordpress-develop' string\n    $ wp db search wordpress-develop\n    wp_options:option_value\n    1:http://wordpress-develop.dev\n    wp_options:option_value\n    1:https://example.com/foo\n        ...\n\n    # Search through a multisite database on the subsite 'foo' for the 'example.com' string\n    $ wp db search example.com --url=example.com/foo\n    wp_2_comments:comment_author_url\n    1:https://example.com/\n    wp_2_options:option_value\n        ...\n\n    # Search through the database for the 'https?://' regular expression, printing stats.\n    $ wp db search 'https?://' --regex --stats\n    wp_comments:comment_author_url\n    1:https://wordpress.org/\n        ...\n    Success: Found 99146 matches in 10.752s (10.559s searching). Searched 12 tables, 53 columns, 1358907 rows. 1 table skipped: wp_term_relationships.\n\n    # SQL search database table 'wp_options' where 'option_name' match 'foo'\n    wp db query 'SELECT * FROM wp_options WHERE option_name like \"%foo%\"' --skip-column-names\n    +----+--------------+--------------------------------+-----+\n    | 98 | foo_options  | a:1:{s:12:\"_multiwidget\";i:1;} | yes |\n    | 99 | foo_settings | a:0:{}                         | yes |\n    +----+--------------+--------------------------------+-----+\n\n    # SQL search and delete records from database table 'wp_options' where 'option_name' match 'foo'\n    wp db query \"DELETE from wp_options where option_id in ($(wp db query \"SELECT GROUP_CONCAT(option_id SEPARATOR ',') from wp_options where option_name like '%foo%';\" --silent --skip-column-names))\"\n\n    # Search for a string and print the result as a table\n    $ wp db search https://localhost:8889 --format=table --fields=table,column,match\n    +------------+--------------+-----------------------------+\n    | table      | column       | match                       |\n    +------------+--------------+-----------------------------+\n    | wp_options | option_value | https://localhost:8889      |\n    | wp_options | option_value | https://localhost:8889      |\n    | wp_posts   | guid         | https://localhost:8889/?p=1 |\n    | wp_users   | user_url     | https://localhost:8889      |\n    +------------+--------------+-----------------------------+\n\n    # Search for a string and get only the IDs (only works for a single table)\n    $ wp db search https://localhost:8889 wp_options --format=ids\n    1 2\n\n\n\n### wp db tables\n\nLists the database tables.\n\n~~~\nwp db tables [\u003ctable\u003e...] [--scope=\u003cscope\u003e] [--network] [--all-tables-with-prefix] [--all-tables] [--format=\u003cformat\u003e]\n~~~\n\nDefaults to all tables registered to the $wpdb database handler.\n\n**OPTIONS**\n\n\t[\u003ctable\u003e...]\n\t\tList tables based on wildcard search, e.g. 'wp_*_options' or 'wp_post?'.\n\n\t[--scope=\u003cscope\u003e]\n\t\tCan be all, global, ms_global, blog, or old tables. Defaults to all.\n\n\t[--network]\n\t\tList all the tables in a multisite install.\n\n\t[--all-tables-with-prefix]\n\t\tList all tables that match the table prefix even if not registered on $wpdb. Overrides --network.\n\n\t[--all-tables]\n\t\tList all tables in the database, regardless of the prefix, and even if not registered on $wpdb. Overrides --all-tables-with-prefix.\n\n\t[--format=\u003cformat\u003e]\n\t\tRender output in a particular format.\n\t\t---\n\t\tdefault: list\n\t\toptions:\n\t\t  - list\n\t\t  - csv\n\t\t---\n\n**EXAMPLES**\n\n    # List tables for a single site, without shared tables like 'wp_users'\n    $ wp db tables --scope=blog --url=sub.example.com\n    wp_3_posts\n    wp_3_comments\n    wp_3_options\n    wp_3_postmeta\n    wp_3_terms\n    wp_3_term_taxonomy\n    wp_3_term_relationships\n    wp_3_termmeta\n    wp_3_commentmeta\n\n    # Export only tables for a single site\n    $ wp db export --tables=$(wp db tables --url=sub.example.com --format=csv)\n    Success: Exported to wordpress_dbase.sql\n\n\n\n### wp db size\n\nDisplays the database name and size.\n\n~~~\nwp db size [--size_format=\u003cformat\u003e] [--tables] [--human-readable] [--format=\u003cformat\u003e] [--scope=\u003cscope\u003e] [--network] [--decimals=\u003cdecimals\u003e] [--all-tables-with-prefix] [--all-tables] [--order=\u003corder\u003e] [--orderby=\u003corderby\u003e]\n~~~\n\nDisplay the database name and size for `DB_NAME` specified in wp-config.php.\nThe size defaults to a human-readable number.\n\nAvailable size formats include:\n* b (bytes)\n* kb (kilobytes)\n* mb (megabytes)\n* gb (gigabytes)\n* tb (terabytes)\n* B   (ISO Byte setting, with no conversion)\n* KB  (ISO Kilobyte setting, with 1 KB  = 1,000 B)\n* KiB (ISO Kibibyte setting, with 1 KiB = 1,024 B)\n* MB  (ISO Megabyte setting, with 1 MB  = 1,000 KB)\n* MiB (ISO Mebibyte setting, with 1 MiB = 1,024 KiB)\n* GB  (ISO Gigabyte setting, with 1 GB  = 1,000 MB)\n* GiB (ISO Gibibyte setting, with 1 GiB = 1,024 MiB)\n* TB  (ISO Terabyte setting, with 1 TB  = 1,000 GB)\n* TiB (ISO Tebibyte setting, with 1 TiB = 1,024 GiB)\n\n**OPTIONS**\n\n\t[--size_format=\u003cformat\u003e]\n\t\tDisplay the database size only, as a bare number.\n\t\t---\n\t\toptions:\n\t\t  - b\n\t\t  - kb\n\t\t  - mb\n\t\t  - gb\n\t\t  - tb\n\t\t  - B\n\t\t  - KB\n\t\t  - KiB\n\t\t  - MB\n\t\t  - MiB\n\t\t  - GB\n\t\t  - GiB\n\t\t  - TB\n\t\t  - TiB\n\t\t---\n\n\t[--tables]\n\t\tDisplay each table name and size instead of the database size.\n\n\t[--human-readable]\n\t\tDisplay database sizes in human readable formats.\n\n\t[--format=\u003cformat\u003e]\n\t\tRender output in a particular format.\n\t\t---\n\t\toptions:\n\t\t  - table\n\t\t  - csv\n\t\t  - json\n\t\t  - yaml\n\t\t---\n\n\t[--scope=\u003cscope\u003e]\n\t\tCan be all, global, ms_global, blog, or old tables. Defaults to all.\n\n\t[--network]\n\t\tList all the tables in a multisite install.\n\n\t[--decimals=\u003cdecimals\u003e]\n\t\tNumber of digits after decimal point. Defaults to 0.\n\n\t[--all-tables-with-prefix]\n\t\tList all tables that match the table prefix even if not registered on $wpdb. Overrides --network.\n\n\t[--all-tables]\n\t\tList all tables in the database, regardless of the prefix, and even if not registered on $wpdb. Overrides --all-tables-with-prefix.\n\n\t[--order=\u003corder\u003e]\n\t\tAscending or Descending order.\n\t\t---\n\t\tdefault: asc\n\t\toptions:\n\t\t  - asc\n\t\t  - desc\n\t\t---\n\n\t[--orderby=\u003corderby\u003e]\n\t\tOrder by fields.\n\t\t---\n\t\tdefault: name\n\t\toptions:\n\t\t  - name\n\t\t  - size\n\t\t---\n\n**EXAMPLES**\n\n    $ wp db size\n    +-------------------+------+\n    | Name              | Size |\n    +-------------------+------+\n    | wordpress_default | 6 MB |\n    +-------------------+------+\n\n    $ wp db size --tables\n    +-----------------------+-------+\n    | Name                  | Size  |\n    +-----------------------+-------+\n    | wp_users              | 64 KB |\n    | wp_usermeta           | 48 KB |\n    | wp_posts              | 80 KB |\n    | wp_comments           | 96 KB |\n    | wp_links              | 32 KB |\n    | wp_options            | 32 KB |\n    | wp_postmeta           | 48 KB |\n    | wp_terms              | 48 KB |\n    | wp_term_taxonomy      | 48 KB |\n    | wp_term_relationships | 32 KB |\n    | wp_termmeta           | 48 KB |\n    | wp_commentmeta        | 48 KB |\n    +-----------------------+-------+\n\n    $ wp db size --size_format=b\n    5865472\n\n    $ wp db size --size_format=kb\n    5728\n\n    $ wp db size --size_format=mb\n    6\n\n\n\n### wp db columns\n\nDisplays information about a given table.\n\n~~~\nwp db columns \u003ctable\u003e [--format]\n~~~\n\n**OPTIONS**\n\n\t\u003ctable\u003e\n\t\tName of the database table.\n\n\t[--format]\n\t\tRender output in a particular format.\n\t\t---\n\t\tdefault: table\n\t\toptions:\n\t\t  - table\n\t\t  - csv\n\t\t  - json\n\t\t  - yaml\n\t\t---\n\n**EXAMPLES**\n\n    $ wp db columns wp_posts\n    +-----------------------+---------------------+------+-----+---------------------+----------------+\n    |         Field         |        Type         | Null | Key |       Default       |     Extra      |\n    +-----------------------+---------------------+------+-----+---------------------+----------------+\n    | ID                    | bigint(20) unsigned | NO   | PRI |                     | auto_increment |\n    | post_author           | bigint(20) unsigned | NO   | MUL | 0                   |                |\n    | post_date             | datetime            | NO   |     | 0000-00-00 00:00:00 |                |\n    | post_date_gmt         | datetime            | NO   |     | 0000-00-00 00:00:00 |                |\n    | post_content          | longtext            | NO   |     |                     |                |\n    | post_title            | text                | NO   |     |                     |                |\n    | post_excerpt          | text                | NO   |     |                     |                |\n    | post_status           | varchar(20)         | NO   |     | publish             |                |\n    | comment_status        | varchar(20)         | NO   |     | open                |                |\n    | ping_status           | varchar(20)         | NO   |     | open                |                |\n    | post_password         | varchar(255)        | NO   |     |                     |                |\n    | post_name             | varchar(200)        | NO   | MUL |                     |                |\n    | to_ping               | text                | NO   |     |                     |                |\n    | pinged                | text                | NO   |     |                     |                |\n    | post_modified         | datetime            | NO   |     | 0000-00-00 00:00:00 |                |\n    | post_modified_gmt     | datetime            | NO   |     | 0000-00-00 00:00:00 |                |\n    | post_content_filtered | longtext            | NO   |     |                     |                |\n    | post_parent           | bigint(20) unsigned | NO   | MUL | 0                   |                |\n    | guid                  | varchar(255)        | NO   |     |                     |                |\n    | menu_order            | int(11)             | NO   |     | 0                   |                |\n    | post_type             | varchar(20)         | NO   | MUL | post                |                |\n    | post_mime_type        | varchar(100)        | NO   |     |                     |                |\n    | comment_count         | bigint(20)          | NO   |     | 0                   |                |\n    +-----------------------+---------------------+------+-----+---------------------+----------------+\n\n## Installing\n\nThis package is included with WP-CLI itself, no additional installation necessary.\n\nTo install the latest version of this package over what's included in WP-CLI, run:\n\n    wp package install git@github.com:wp-cli/db-command.git\n\n## Contributing\n\nWe appreciate you taking the initiative to contribute to this project.\n\nContributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.\n\nFor a more thorough introduction, [check out WP-CLI's guide to contributing](https://make.wordpress.org/cli/handbook/contributing/). This package follows those policy and guidelines.\n\n### Reporting a bug\n\nThink you’ve found a bug? We’d love for you to help us get it fixed.\n\nBefore you create a new issue, you should [search existing issues](https://github.com/wp-cli/db-command/issues?q=label%3Abug%20) to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version.\n\nOnce you’ve done a bit of searching and discovered there isn’t an open or fixed issue for your bug, please [create a new issue](https://github.com/wp-cli/db-command/issues/new). Include as much detail as you can, and clear steps to reproduce if possible. For more guidance, [review our bug report documentation](https://make.wordpress.org/cli/handbook/bug-reports/).\n\n### Creating a pull request\n\nWant to contribute a new feature? Please first [open a new issue](https://github.com/wp-cli/db-command/issues/new) to discuss whether the feature is a good fit for the project.\n\nOnce you've decided to commit the time to seeing your pull request through, [please follow our guidelines for creating a pull request](https://make.wordpress.org/cli/handbook/pull-requests/) to make sure it's a pleasant experience. See \"[Setting up](https://make.wordpress.org/cli/handbook/pull-requests/#setting-up)\" for details specific to working on this package locally.\n\n## Support\n\nGitHub issues aren't for general support questions, but there are other venues you can try: https://wp-cli.org/#support\n\n\n*This README.md is generated dynamically from the project's codebase using `wp scaffold package-readme` ([doc](https://github.com/wp-cli/scaffold-package-command#wp-scaffold-package-readme)). To suggest changes, please submit a pull request against the corresponding part of the codebase.*\n","funding_links":[],"categories":["Gherkin"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-cli%2Fdb-command","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwp-cli%2Fdb-command","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-cli%2Fdb-command/lists"}