wp-cli / db-command
使用存储在 wp-config.php 中的凭据执行基本的数据库操作。
Requires
- wp-cli/wp-cli: ^2.5
Requires (Dev)
- wp-cli/entity-command: ^1.3 || ^2
- wp-cli/wp-cli-tests: ^4
- dev-main / 2.x-dev
- v2.1.1
- v2.1.0
- v2.0.27
- v2.0.26
- v2.0.25
- v2.0.24
- v2.0.23
- v2.0.22
- v2.0.21
- v2.0.20
- v2.0.19
- v2.0.18
- v2.0.17
- v2.0.16
- v2.0.15
- v2.0.14
- v2.0.13
- v2.0.12
- v2.0.11
- v2.0.10
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.1
- v1.0.0
- dev-bump-framework-2-11
- dev-fix/support-php-8.1
- dev-add/switch-to-github-actions
- dev-experimental-stdin-manipulation-for-compat
- dev-refactor-db-command-internals
- dev-emoji-issue
- dev-issue-83-add-docs-for-where-argument
- dev-issue-73-wp_get_table_names
This package is auto-updated.
Last update: 2024-09-13 15:10:21 UTC
README
使用存储在 wp-config.php 中的凭据执行基本的数据库操作。
使用
此包实现了以下命令
wp db
使用存储在 wp-config.php 中的凭据执行基本的数据库操作。
wp db
示例
# Create a new database.
$ wp db create
Success: Database created.
# Drop an existing database.
$ wp db drop --yes
Success: Database dropped.
# Reset the current database.
$ wp db reset --yes
Success: Database reset.
# Execute a SQL query stored in a file.
$ wp db query < debug.sql
wp db clean
从数据库中删除所有具有 $table_prefix
的表。
wp db clean [--dbuser=<value>] [--dbpass=<value>] [--yes] [--defaults]
对 wp-config.php 中指定的每个具有 $table_prefix
的表运行 DROP_TABLE
。
选项
[--dbuser=<value>]
Username to pass to mysql. Defaults to DB_USER.
[--dbpass=<value>]
Password to pass to mysql. Defaults to DB_PASSWORD.
[--yes]
Answer yes to the confirmation message.
[--defaults]
Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
示例
# Delete all tables that match the current site prefix.
$ wp db clean --yes
Success: Tables dropped.
wp db create
创建一个新的数据库。
wp db create [--dbuser=<value>] [--dbpass=<value>] [--defaults]
使用 wp-config.php 中指定的 DB_HOST
、DB_NAME
、DB_USER
和 DB_PASSWORD
数据库凭据运行 CREATE_DATABASE
SQL 语句。
选项
[--dbuser=<value>]
Username to pass to mysql. Defaults to DB_USER.
[--dbpass=<value>]
Password to pass to mysql. Defaults to DB_PASSWORD.
[--defaults]
Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
示例
$ wp db create
Success: Database created.
wp db drop
删除现有的数据库。
wp db drop [--dbuser=<value>] [--dbpass=<value>] [--yes] [--defaults]
使用 wp-config.php 中指定的 DB_HOST
、DB_NAME
、DB_USER
和 DB_PASSWORD
数据库凭据运行 DROP_DATABASE
SQL 语句。
选项
[--dbuser=<value>]
Username to pass to mysql. Defaults to DB_USER.
[--dbpass=<value>]
Password to pass to mysql. Defaults to DB_PASSWORD.
[--yes]
Answer yes to the confirmation message.
[--defaults]
Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
示例
$ wp db drop --yes
Success: Database dropped.
wp db reset
从数据库中删除所有表。
wp db reset [--dbuser=<value>] [--dbpass=<value>] [--yes] [--defaults]
使用 wp-config.php 中指定的 DB_HOST
、DB_NAME
、DB_USER
和 DB_PASSWORD
数据库凭据运行 DROP_DATABASE
和 CREATE_DATABASE
SQL 语句。
选项
[--dbuser=<value>]
Username to pass to mysql. Defaults to DB_USER.
[--dbpass=<value>]
Password to pass to mysql. Defaults to DB_PASSWORD.
[--yes]
Answer yes to the confirmation message.
[--defaults]
Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
示例
$ wp db reset --yes
Success: Database reset.
wp db check
检查数据库的当前状态。
wp db check [--dbuser=<value>] [--dbpass=<value>] [--<field>=<value>] [--defaults]
使用 wp-config.php 中指定的 DB_HOST
、DB_NAME
、DB_USER
和 DB_PASSWORD
数据库凭据运行 mysqlcheck
工具的 --check
选项。
有关 CHECK TABLE
语句的更多详细信息,请参阅文档。
此命令不会检查 WordPress 是否已安装;要执行此操作,请运行 wp core is-installed
。
选项
[--dbuser=<value>]
Username to pass to mysqlcheck. Defaults to DB_USER.
[--dbpass=<value>]
Password to pass to mysqlcheck. Defaults to DB_PASSWORD.
[--<field>=<value>]
Extra arguments to pass to mysqlcheck. [Refer to mysqlcheck docs](https://dev.mysqlserver.cn/doc/en/mysqlcheck.html).
[--defaults]
Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
示例
$ wp db check
Success: Database checked.
wp db optimize
优化数据库。
wp db optimize [--dbuser=<value>] [--dbpass=<value>] [--<field>=<value>] [--defaults]
使用 wp-config.php 中指定的 DB_HOST
、DB_NAME
、DB_USER
和 DB_PASSWORD
数据库凭据运行 mysqlcheck
工具的 --optimize=true
选项。
有关 OPTIMIZE TABLE
语句的更多详细信息,请参阅文档。
选项
[--dbuser=<value>]
Username to pass to mysqlcheck. Defaults to DB_USER.
[--dbpass=<value>]
Password to pass to mysqlcheck. Defaults to DB_PASSWORD.
[--<field>=<value>]
Extra arguments to pass to mysqlcheck. [Refer to mysqlcheck docs](https://dev.mysqlserver.cn/doc/en/mysqlcheck.html).
[--defaults]
Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
示例
$ wp db optimize
Success: Database optimized.
wp db prefix
显示数据库表前缀。
wp db prefix
显示数据库表前缀,该前缀由数据库处理程序对当前站点的解释定义。
示例
$ wp db prefix
wp_
wp db repair
修复数据库。
wp db repair [--dbuser=<value>] [--dbpass=<value>] [--<field>=<value>] [--defaults]
使用 wp-config.php 中指定的 DB_HOST
、DB_NAME
、DB_USER
和 DB_PASSWORD
数据库凭据运行 mysqlcheck
工具的 --repair=true
选项。
有关 REPAIR TABLE
语句的更多详细信息,请参阅文档。
选项
[--dbuser=<value>]
Username to pass to mysqlcheck. Defaults to DB_USER.
[--dbpass=<value>]
Password to pass to mysqlcheck. Defaults to DB_PASSWORD.
[--<field>=<value>]
Extra arguments to pass to mysqlcheck. [Refer to mysqlcheck docs](https://dev.mysqlserver.cn/doc/en/mysqlcheck.html).
[--defaults]
Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
示例
$ wp db repair
Success: Database repaired.
wp db cli
使用 wp-config.php 中的凭据打开 MySQL 控制台。
wp db cli [--database=<database>] [--default-character-set=<character-set>] [--dbuser=<value>] [--dbpass=<value>] [--<field>=<value>] [--defaults]
选项
[--database=<database>]
Use a specific database. Defaults to DB_NAME.
[--default-character-set=<character-set>]
Use a specific character set. Defaults to DB_CHARSET when defined.
[--dbuser=<value>]
Username to pass to mysql. Defaults to DB_USER.
[--dbpass=<value>]
Password to pass to mysql. Defaults to DB_PASSWORD.
[--<field>=<value>]
Extra arguments to pass to mysql. [Refer to mysql docs](https://dev.mysqlserver.cn/doc/en/mysql-command-options.html).
[--defaults]
Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
示例
# Open MySQL console
$ wp db cli
mysql>
wp db query
对数据库执行 SQL 查询。
wp db query [<sql>] [--dbuser=<value>] [--dbpass=<value>] [--<field>=<value>] [--defaults]
使用 wp-config.php 中指定的 DB_HOST
、DB_NAME
、DB_USER
和 DB_PASSWORD
数据库凭据执行任意 SQL 查询。
使用 --skip-column-names
MySQL 参数从 SELECT 查询中排除标题。将输出重定向以删除整个 ASCII 表。
选项
[<sql>]
A SQL query. If not passed, will try to read from STDIN.
[--dbuser=<value>]
Username to pass to mysql. Defaults to DB_USER.
[--dbpass=<value>]
Password to pass to mysql. Defaults to DB_PASSWORD.
[--<field>=<value>]
Extra arguments to pass to mysql. [Refer to mysql docs](https://dev.mysqlserver.cn/doc/en/mysql-command-options.html).
[--defaults]
Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
示例
# Execute a query stored in a file
$ wp db query < debug.sql
# Query for a specific value in the database (pipe the result to remove the ASCII table borders)
$ wp db query 'SELECT option_value FROM wp_options WHERE option_name="home"' --skip-column-names
+---------------------+
| https://example.com |
+---------------------+
# Check all tables in the database
$ wp db query "CHECK TABLE $(wp db tables | paste -s -d, -);"
+---------------------------------------+-------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+---------------------------------------+-------+----------+----------+
| wordpress_dbase.wp_users | check | status | OK |
| wordpress_dbase.wp_usermeta | check | status | OK |
| wordpress_dbase.wp_posts | check | status | OK |
| wordpress_dbase.wp_comments | check | status | OK |
| wordpress_dbase.wp_links | check | status | OK |
| wordpress_dbase.wp_options | check | status | OK |
| wordpress_dbase.wp_postmeta | check | status | OK |
| wordpress_dbase.wp_terms | check | status | OK |
| wordpress_dbase.wp_term_taxonomy | check | status | OK |
| wordpress_dbase.wp_term_relationships | check | status | OK |
| wordpress_dbase.wp_termmeta | check | status | OK |
| wordpress_dbase.wp_commentmeta | check | status | OK |
+---------------------------------------+-------+----------+----------+
# Pass extra arguments through to MySQL
$ wp db query 'SELECT * FROM wp_options WHERE option_name="home"' --skip-column-names
+---+------+------------------------------+-----+
| 2 | home | http://wordpress-develop.dev | yes |
+---+------+------------------------------+-----+
多站点使用
请注意,全局--url
参数对此命令无影响。如果您想查询除主站点以外的站点数据,需要手动修改表名,使用包含站点ID的前缀。
例如,要获取第二个站点的home
选项,可以将上面的示例修改如下
$ wp db query 'SELECT option_value FROM wp_2_options WHERE option_name="home"' --skip-column-names
+----------------------+
| https://example2.com |
+----------------------+
要确认您要查询站点的ID,可以使用wp site list
命令
# wp site list --fields=blog_id,url
+---------+-----------------------+
| blog_id | url |
+---------+-----------------------+
| 1 | https://example1.com/ |
| 2 | https://example2.com/ |
+---------+-----------------------+
wp db export
将数据库导出到文件或到STDOUT。
wp db export [<file>] [--dbuser=<value>] [--dbpass=<value>] [--<field>=<value>] [--tables=<tables>] [--exclude_tables=<tables>] [--include-tablespaces] [--porcelain] [--add-drop-table] [--defaults]
使用在wp-config.php中指定的DB_HOST
、DB_NAME
、DB_USER
和DB_PASSWORD
数据库凭证运行mysqldump
实用程序。接受任何有效的mysqldump
标志。
选项
[<file>]
The name of the SQL file to export. If '-', then outputs to STDOUT. If
omitted, it will be '{dbname}-{Y-m-d}-{random-hash}.sql'.
[--dbuser=<value>]
Username to pass to mysqldump. Defaults to DB_USER.
[--dbpass=<value>]
Password to pass to mysqldump. Defaults to DB_PASSWORD.
[--<field>=<value>]
Extra arguments to pass to mysqldump. [Refer to mysqldump docs](https://dev.mysqlserver.cn/doc/en/mysqldump.html#mysqldump-option-summary).
[--tables=<tables>]
The comma separated list of specific tables to export. Excluding this parameter will export all tables in the database.
[--exclude_tables=<tables>]
The comma separated list of specific tables that should be skipped from exporting. Excluding this parameter will export all tables in the database.
[--include-tablespaces]
Skips adding the default --no-tablespaces option to mysqldump.
[--porcelain]
Output filename for the exported database.
[--add-drop-table]
Include a `DROP TABLE IF EXISTS` statement before each `CREATE TABLE` statement.
[--defaults]
Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
示例
# Export database with drop query included
$ wp db export --add-drop-table
Success: Exported to 'wordpress_dbase-db72bb5.sql'.
# Export certain tables
$ wp db export --tables=wp_options,wp_users
Success: Exported to 'wordpress_dbase-db72bb5.sql'.
# Export all tables matching a wildcard
$ wp db export --tables=$(wp db tables 'wp_user*' --format=csv)
Success: Exported to 'wordpress_dbase-db72bb5.sql'.
# Export all tables matching prefix
$ wp db export --tables=$(wp db tables --all-tables-with-prefix --format=csv)
Success: Exported to 'wordpress_dbase-db72bb5.sql'.
# Export certain posts without create table statements
$ wp db export --no-create-info=true --tables=wp_posts --where="ID in (100,101,102)"
Success: Exported to 'wordpress_dbase-db72bb5.sql'.
# Export relating meta for certain posts without create table statements
$ wp db export --no-create-info=true --tables=wp_postmeta --where="post_id in (100,101,102)"
Success: Exported to 'wordpress_dbase-db72bb5.sql'.
# Skip certain tables from the exported database
$ wp db export --exclude_tables=wp_options,wp_users
Success: Exported to 'wordpress_dbase-db72bb5.sql'.
# Skip all tables matching a wildcard from the exported database
$ wp db export --exclude_tables=$(wp db tables 'wp_user*' --format=csv)
Success: Exported to 'wordpress_dbase-db72bb5.sql'.
# Skip all tables matching prefix from the exported database
$ wp db export --exclude_tables=$(wp db tables --all-tables-with-prefix --format=csv)
Success: Exported to 'wordpress_dbase-db72bb5.sql'.
# Export database to STDOUT.
$ wp db export -
-- MySQL dump 10.13 Distrib 5.7.19, for osx10.12 (x86_64)
--
-- Host: localhost Database: wpdev
-- ------------------------------------------------------
-- Server version 5.7.19
...
wp db import
从文件或STDIN导入数据库。
wp db import [<file>] [--dbuser=<value>] [--dbpass=<value>] [--<field>=<value>] [--skip-optimization] [--defaults]
使用在wp-config.php中指定的DB_HOST
、DB_NAME
、DB_USER
和DB_PASSWORD
数据库凭证运行SQL查询。此命令不会自动创建数据库,仅执行SQL中定义的任务。
选项
[<file>]
The name of the SQL file to import. If '-', then reads from STDIN. If omitted, it will look for '{dbname}.sql'.
[--dbuser=<value>]
Username to pass to mysql. Defaults to DB_USER.
[--dbpass=<value>]
Password to pass to mysql. Defaults to DB_PASSWORD.
[--<field>=<value>]
Extra arguments to pass to mysql. [Refer to mysql binary docs](https://dev.mysqlserver.cn/doc/refman/8.0/en/mysql-command-options.html).
[--skip-optimization]
When using an SQL file, do not include speed optimization such as disabling auto-commit and key checks.
[--defaults]
Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
示例
# Import MySQL from a file.
$ wp db import wordpress_dbase.sql
Success: Imported from 'wordpress_dbase.sql'.
wp db search
在数据库中查找字符串。
wp db search <search> [<tables>...] [--network] [--all-tables-with-prefix] [--all-tables] [--before_context=<num>] [--after_context=<num>] [--regex] [--regex-flags=<regex-flags>] [--regex-delimiter=<regex-delimiter>] [--table_column_once] [--one_line] [--matches_only] [--stats] [--table_column_color=<color_code>] [--id_color=<color_code>] [--match_color=<color_code>] [--fields=<fields>] [--format=<format>]
在所选数据库表中的所有文本列中搜索给定的字符串,输出带颜色的字符串引用。
默认搜索所有注册到$wpdb的表。在多站点环境中,此默认设置仅限于当前站点的表。
选项
<search>
String to search for. The search is case-insensitive by default.
[<tables>...]
One or more tables to search through for the string.
[--network]
Search through all the tables registered to $wpdb in a multisite install.
[--all-tables-with-prefix]
Search 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.
[--all-tables]
Search through ALL tables in the database, regardless of the prefix, and even if not registered on $wpdb. Overrides --network and --all-tables-with-prefix.
[--before_context=<num>]
Number of characters to display before the match.
---
default: 40
---
[--after_context=<num>]
Number of characters to display after the match.
---
default: 40
---
[--regex]
Runs 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.
[--regex-flags=<regex-flags>]
Pass PCRE modifiers to the regex search (e.g. 'i' for case-insensitivity).
[--regex-delimiter=<regex-delimiter>]
The 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)`.
[--table_column_once]
Output the 'table:column' line once before all matching row lines in the table column rather than before each matching row.
[--one_line]
Place the 'table:column' output on the same line as the row id and match ('table:column:id:match'). Overrides --table_column_once.
[--matches_only]
Only output the string matches (including context). No 'table:column's or row ids are outputted.
[--stats]
Output stats on the number of matches found, time taken, tables/columns/rows searched, tables skipped.
[--table_column_color=<color_code>]
Percent color code to use for the 'table:column' output. For a list of available percent color codes, see below. Default '%G' (bright green).
[--id_color=<color_code>]
Percent color code to use for the row id output. For a list of available percent color codes, see below. Default '%Y' (bright yellow).
[--match_color=<color_code>]
Percent 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).
[--fields=<fields>]
Get a specific subset of the fields.
[--format=<format>]
Render output in a particular format.
---
options:
- table
- csv
- json
- yaml
- ids
- count
---
可用的颜色代码为
它们可以连接使用。例如,默认匹配颜色黑色在芥末(深黄色)背景上%3%k
,可以在亮黄色背景上变为黑色,使用%Y%0%8
。
可用字段
以下字段将默认显示在每个结果中
- 表
- 列
- 匹配
- 主键名称
- 主键值
示例
# Search through the database for the 'wordpress-develop' string
$ wp db search wordpress-develop
wp_options:option_value
1:http://wordpress-develop.dev
wp_options:option_value
1:https://example.com/foo
...
# Search through a multisite database on the subsite 'foo' for the 'example.com' string
$ wp db search example.com --url=example.com/foo
wp_2_comments:comment_author_url
1:https://example.com/
wp_2_options:option_value
...
# Search through the database for the 'https?://' regular expression, printing stats.
$ wp db search 'https?://' --regex --stats
wp_comments:comment_author_url
1:https://wordpress.org/
...
Success: Found 99146 matches in 10.752s (10.559s searching). Searched 12 tables, 53 columns, 1358907 rows. 1 table skipped: wp_term_relationships.
# SQL search database table 'wp_options' where 'option_name' match 'foo'
wp db query 'SELECT * FROM wp_options WHERE option_name like "%foo%"' --skip-column-names
+----+--------------+--------------------------------+-----+
| 98 | foo_options | a:1:{s:12:"_multiwidget";i:1;} | yes |
| 99 | foo_settings | a:0:{} | yes |
+----+--------------+--------------------------------+-----+
# SQL search and delete records from database table 'wp_options' where 'option_name' match 'foo'
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))"
# Search for a string and print the result as a table
$ wp db search https://localhost:8889 --format=table --fields=table,column,match
+------------+--------------+-----------------------------+
| table | column | match |
+------------+--------------+-----------------------------+
| wp_options | option_value | https://localhost:8889 |
| wp_options | option_value | https://localhost:8889 |
| wp_posts | guid | https://localhost:8889/?p=1 |
| wp_users | user_url | https://localhost:8889 |
+------------+--------------+-----------------------------+
# Search for a string and get only the IDs (only works for a single table)
$ wp db search https://localhost:8889 wp_options --format=ids
1 2
wp db tables
列出数据库表。
wp db tables [<table>...] [--scope=<scope>] [--network] [--all-tables-with-prefix] [--all-tables] [--format=<format>]
默认列出注册到$wpdb数据库处理器的所有表。
选项
[<table>...]
List tables based on wildcard search, e.g. 'wp_*_options' or 'wp_post?'.
[--scope=<scope>]
Can be all, global, ms_global, blog, or old tables. Defaults to all.
[--network]
List all the tables in a multisite install.
[--all-tables-with-prefix]
List all tables that match the table prefix even if not registered on $wpdb. Overrides --network.
[--all-tables]
List all tables in the database, regardless of the prefix, and even if not registered on $wpdb. Overrides --all-tables-with-prefix.
[--format=<format>]
Render output in a particular format.
---
default: list
options:
- list
- csv
---
示例
# List tables for a single site, without shared tables like 'wp_users'
$ wp db tables --scope=blog --url=sub.example.com
wp_3_posts
wp_3_comments
wp_3_options
wp_3_postmeta
wp_3_terms
wp_3_term_taxonomy
wp_3_term_relationships
wp_3_termmeta
wp_3_commentmeta
# Export only tables for a single site
$ wp db export --tables=$(wp db tables --url=sub.example.com --format=csv)
Success: Exported to wordpress_dbase.sql
wp db size
显示数据库名称和大小。
wp db size [--size_format=<format>] [--tables] [--human-readable] [--format=<format>] [--scope=<scope>] [--network] [--decimals=<decimals>] [--all-tables-with-prefix] [--all-tables] [--order=<order>] [--orderby=<orderby>]
显示在wp-config.php中指定的DB_NAME
的数据库名称和大小。大小默认为可读数字。
可用的尺寸格式包括
- b (字节)
- kb (千字节)
- mb (兆字节)
- gb (吉字节)
- tb (太字节)
- B (ISO字节设置,不转换)
- KB (ISO千字节设置,1 KB = 1,000 B)
- KiB (ISO千ibi字节设置,1 KiB = 1,024 B)
- MB (ISO兆字节设置,1 MB = 1,000 KB)
- MiB (ISO兆ibi字节设置,1 MiB = 1,024 KiB)
- GB (ISO吉字节设置,1 GB = 1,000 MB)
- GiB (ISO吉ibi字节设置,1 GiB = 1,024 MiB)
- TB (ISO太字节设置,1 TB = 1,000 GB)
- TiB (ISO太ibi字节设置,1 TiB = 1,024 GiB)
选项
[--size_format=<format>]
Display the database size only, as a bare number.
---
options:
- b
- kb
- mb
- gb
- tb
- B
- KB
- KiB
- MB
- MiB
- GB
- GiB
- TB
- TiB
---
[--tables]
Display each table name and size instead of the database size.
[--human-readable]
Display database sizes in human readable formats.
[--format=<format>]
Render output in a particular format.
---
options:
- table
- csv
- json
- yaml
---
[--scope=<scope>]
Can be all, global, ms_global, blog, or old tables. Defaults to all.
[--network]
List all the tables in a multisite install.
[--decimals=<decimals>]
Number of digits after decimal point. Defaults to 0.
[--all-tables-with-prefix]
List all tables that match the table prefix even if not registered on $wpdb. Overrides --network.
[--all-tables]
List all tables in the database, regardless of the prefix, and even if not registered on $wpdb. Overrides --all-tables-with-prefix.
[--order=<order>]
Ascending or Descending order.
---
default: asc
options:
- asc
- desc
---
[--orderby=<orderby>]
Order by fields.
---
default: name
options:
- name
- size
---
示例
$ wp db size
+-------------------+------+
| Name | Size |
+-------------------+------+
| wordpress_default | 6 MB |
+-------------------+------+
$ wp db size --tables
+-----------------------+-------+
| Name | Size |
+-----------------------+-------+
| wp_users | 64 KB |
| wp_usermeta | 48 KB |
| wp_posts | 80 KB |
| wp_comments | 96 KB |
| wp_links | 32 KB |
| wp_options | 32 KB |
| wp_postmeta | 48 KB |
| wp_terms | 48 KB |
| wp_term_taxonomy | 48 KB |
| wp_term_relationships | 32 KB |
| wp_termmeta | 48 KB |
| wp_commentmeta | 48 KB |
+-----------------------+-------+
$ wp db size --size_format=b
5865472
$ wp db size --size_format=kb
5728
$ wp db size --size_format=mb
6
wp db columns
显示有关指定表的信息。
wp db columns <table> [--format]
选项
<table>
Name of the database table.
[--format]
Render output in a particular format.
---
default: table
options:
- table
- csv
- json
- yaml
---
示例
$ wp db columns wp_posts
+-----------------------+---------------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+---------------------+------+-----+---------------------+----------------+
| ID | bigint(20) unsigned | NO | PRI | | auto_increment |
| post_author | bigint(20) unsigned | NO | MUL | 0 | |
| post_date | datetime | NO | | 0000-00-00 00:00:00 | |
| post_date_gmt | datetime | NO | | 0000-00-00 00:00:00 | |
| post_content | longtext | NO | | | |
| post_title | text | NO | | | |
| post_excerpt | text | NO | | | |
| post_status | varchar(20) | NO | | publish | |
| comment_status | varchar(20) | NO | | open | |
| ping_status | varchar(20) | NO | | open | |
| post_password | varchar(255) | NO | | | |
| post_name | varchar(200) | NO | MUL | | |
| to_ping | text | NO | | | |
| pinged | text | NO | | | |
| post_modified | datetime | NO | | 0000-00-00 00:00:00 | |
| post_modified_gmt | datetime | NO | | 0000-00-00 00:00:00 | |
| post_content_filtered | longtext | NO | | | |
| post_parent | bigint(20) unsigned | NO | MUL | 0 | |
| guid | varchar(255) | NO | | | |
| menu_order | int(11) | NO | | 0 | |
| post_type | varchar(20) | NO | MUL | post | |
| post_mime_type | varchar(100) | NO | | | |
| comment_count | bigint(20) | NO | | 0 | |
+-----------------------+---------------------+------+-----+---------------------+----------------+
安装
此软件包包含在WP-CLI本身中,无需额外安装。
要安装此软件包的最新版本,覆盖WP-CLI中包含的版本,请运行
wp package install [email protected]:wp-cli/db-command.git
贡献
我们感谢您主动为这个项目做出贡献。
贡献不仅限于代码。我们鼓励您根据自己的能力以最佳方式做出贡献,例如撰写教程、在当地聚会上进行演示、帮助其他用户解决支持问题或修订我们的文档。
要获得更全面的介绍,请查看WP-CLI贡献指南。此软件包遵循那些政策和指南。
报告错误
认为您找到了错误?我们很乐意您帮助我们修复它。
在您创建新问题之前,您应该先搜索现有问题,看看是否有针对此问题的现有解决方案,或者它是否已经被新版本修复。
一旦您进行了一些搜索,并发现没有针对您的错误的问题已开放或已修复,请创建一个新问题。尽可能提供详细信息,并在可能的情况下提供重现的清晰步骤。更多指导,请查看我们的错误报告文档。
创建拉取请求
想贡献一个新特性?请首先打开一个新问题,讨论该特性是否适合该项目。
一旦您决定投入时间完成您的拉取请求,请遵循我们创建拉取请求的指南,确保它是一个愉快的体验。有关在本地工作于该包的具体信息,请参阅"设置"。
支持
GitHub问题不是用于一般支持问题的地方,但您可以尝试其他方式:https://wp-cli.org/#support
此README.md文件是使用wp scaffold package-readme
(文档)从项目的代码库动态生成的。要提出更改建议,请针对代码库的相应部分提交一个拉取请求。