Skip to content

Commit 37f1ba2

Browse files
Regenerate README
1 parent e328454 commit 37f1ba2

File tree

1 file changed

+341
-2
lines changed

1 file changed

+341
-2
lines changed

README.md

+341-2
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,358 @@
11
wp-cli/db-command
22
=================
33

4-
Perform basic database operations using credentials stored in wp-config.php
4+
Perform basic database operations using credentials stored in wp-config.php.
55

66
[![Build Status](https://travis-ci.org/wp-cli/db-command.svg?branch=master)](https://travis-ci.org/wp-cli/db-command)
77

88
Quick links: [Using](#using) | [Installing](#installing) | [Contributing](#contributing)
99

1010
## Using
1111

12+
This package implements the following commands:
1213

14+
### wp db create
15+
16+
Create a new database.
17+
18+
~~~
19+
wp db create
20+
~~~
21+
22+
Runs `CREATE_DATABASE` SQL statement using `DB_HOST`, `DB_NAME`,
23+
`DB_USER` and `DB_PASSWORD` database credentials specified in
24+
wp-config.php.
25+
26+
**EXAMPLES**
27+
28+
$ wp db create
29+
Success: Database created.
30+
31+
32+
33+
### wp db drop
34+
35+
Delete the existing database.
36+
37+
~~~
38+
wp db drop [--yes]
39+
~~~
40+
41+
Runs `DROP_DATABASE` SQL statement using `DB_HOST`, `DB_NAME`,
42+
`DB_USER` and `DB_PASSWORD` database credentials specified in
43+
wp-config.php.
44+
45+
**OPTIONS**
46+
47+
[--yes]
48+
Answer yes to the confirmation message.
49+
50+
**EXAMPLES**
51+
52+
$ wp db drop --yes
53+
Success: Database dropped.
54+
55+
56+
57+
### wp db reset
58+
59+
Remove all tables from the database.
60+
61+
~~~
62+
wp db reset [--yes]
63+
~~~
64+
65+
Runs `DROP_DATABASE` and `CREATE_DATABASE` SQL statements using
66+
`DB_HOST`, `DB_NAME`, `DB_USER` and `DB_PASSWORD` database credentials
67+
specified in wp-config.php.
68+
69+
**OPTIONS**
70+
71+
[--yes]
72+
Answer yes to the confirmation message.
73+
74+
**EXAMPLES**
75+
76+
$ wp db reset --yes
77+
Success: Database reset.
78+
79+
80+
81+
### wp db check
82+
83+
Check the current status of the database.
84+
85+
~~~
86+
wp db check
87+
~~~
88+
89+
Runs `mysqlcheck` utility with `--check` using `DB_HOST`,
90+
`DB_NAME`, `DB_USER` and `DB_PASSWORD` database credentials
91+
specified in wp-config.php.
92+
93+
[See docs](http://dev.mysql.com/doc/refman/5.7/en/check-table.html)
94+
for more details on the `CHECK TABLE` statement.
95+
96+
**EXAMPLES**
97+
98+
$ wp db check
99+
Success: Database checked.
100+
101+
102+
103+
### wp db optimize
104+
105+
Optimize the database.
106+
107+
~~~
108+
wp db optimize
109+
~~~
110+
111+
Runs `mysqlcheck` utility with `--optimize=true` using `DB_HOST`,
112+
`DB_NAME`, `DB_USER` and `DB_PASSWORD` database credentials
113+
specified in wp-config.php.
114+
115+
[See docs](http://dev.mysql.com/doc/refman/5.7/en/optimize-table.html)
116+
for more details on the `OPTIMIZE TABLE` statement.
117+
118+
**EXAMPLES**
119+
120+
$ wp db optimize
121+
Success: Database optimized.
122+
123+
124+
125+
### wp db repair
126+
127+
Repair the database.
128+
129+
~~~
130+
wp db repair
131+
~~~
132+
133+
Runs `mysqlcheck` utility with `--repair=true` using `DB_HOST`,
134+
`DB_NAME`, `DB_USER` and `DB_PASSWORD` database credentials
135+
specified in wp-config.php.
136+
137+
[See docs](http://dev.mysql.com/doc/refman/5.7/en/repair-table.html) for
138+
more details on the `REPAIR TABLE` statement.
139+
140+
**EXAMPLES**
141+
142+
$ wp db repair
143+
Success: Database repaired.
144+
145+
146+
147+
### wp db cli
148+
149+
Open a MySQL console using credentials from wp-config.php
150+
151+
~~~
152+
wp db cli [--database=<database>] [--default-character-set=<character-set>] [--<field>=<value>]
153+
~~~
154+
155+
**OPTIONS**
156+
157+
[--database=<database>]
158+
Use a specific database. Defaults to DB_NAME.
159+
160+
[--default-character-set=<character-set>]
161+
Use a specific character set. Defaults to DB_CHARSET when defined.
162+
163+
[--<field>=<value>]
164+
Extra arguments to pass to the MySQL executable.
165+
166+
**EXAMPLES**
167+
168+
# Open MySQL console
169+
$ wp db cli
170+
mysql>
171+
172+
173+
174+
### wp db query
175+
176+
Execute a SQL query against the database.
177+
178+
~~~
179+
wp db query [<sql>] [--<field>=<value>]
180+
~~~
181+
182+
Executes an arbitrary SQL query using `DB_HOST`, `DB_NAME`, `DB_USER`
183+
and `DB_PASSWORD` database credentials specified in wp-config.php.
184+
185+
**OPTIONS**
186+
187+
[<sql>]
188+
A SQL query. If not passed, will try to read from STDIN.
189+
190+
[--<field>=<value>]
191+
Extra arguments to pass to mysql.
192+
193+
**EXAMPLES**
194+
195+
# Execute a query stored in a file
196+
$ wp db query < debug.sql
197+
198+
# Check all tables in the database
199+
$ wp db query "CHECK TABLE $(wp db tables | paste -s -d',');"
200+
+---------------------------------------+-------+----------+----------+
201+
| Table | Op | Msg_type | Msg_text |
202+
+---------------------------------------+-------+----------+----------+
203+
| wordpress_dbase.wp_users | check | status | OK |
204+
| wordpress_dbase.wp_usermeta | check | status | OK |
205+
| wordpress_dbase.wp_posts | check | status | OK |
206+
| wordpress_dbase.wp_comments | check | status | OK |
207+
| wordpress_dbase.wp_links | check | status | OK |
208+
| wordpress_dbase.wp_options | check | status | OK |
209+
| wordpress_dbase.wp_postmeta | check | status | OK |
210+
| wordpress_dbase.wp_terms | check | status | OK |
211+
| wordpress_dbase.wp_term_taxonomy | check | status | OK |
212+
| wordpress_dbase.wp_term_relationships | check | status | OK |
213+
| wordpress_dbase.wp_termmeta | check | status | OK |
214+
| wordpress_dbase.wp_commentmeta | check | status | OK |
215+
+---------------------------------------+-------+----------+----------+
216+
217+
# Pass extra arguments through to MySQL
218+
$ wp db query 'SELECT * FROM wp_options WHERE option_name="home"' --skip-column-names
219+
+---+------+------------------------------+-----+
220+
| 2 | home | http://wordpress-develop.dev | yes |
221+
+---+------+------------------------------+-----+
222+
223+
224+
225+
### wp db export
226+
227+
Exports the database to a file or to STDOUT.
228+
229+
~~~
230+
wp db export [<file>] [--<field>=<value>] [--tables=<tables>] [--porcelain]
231+
~~~
232+
233+
Runs `mysqldump` utility using `DB_HOST`, `DB_NAME`, `DB_USER` and
234+
`DB_PASSWORD` database credentials specified in wp-config.php.
235+
236+
**OPTIONS**
237+
238+
[<file>]
239+
The name of the SQL file to export. If '-', then outputs to STDOUT. If omitted, it will be '{dbname}.sql'.
240+
241+
[--<field>=<value>]
242+
Extra arguments to pass to mysqldump
243+
244+
[--tables=<tables>]
245+
The comma separated list of specific tables to export. Excluding this parameter will export all tables in the database.
246+
247+
[--porcelain]
248+
Output filename for the exported database.
249+
250+
**EXAMPLES**
251+
252+
# Export database with drop query included
253+
$ wp db export --add-drop-table
254+
Success: Exported to 'wordpress_dbase.sql'.
255+
256+
# Export certain tables
257+
$ wp db export --tables=wp_options,wp_users
258+
Success: Exported to 'wordpress_dbase.sql'.
259+
260+
# Export all tables matching a wildcard
261+
$ wp db export --tables=$(wp db tables 'wp_user*' --format=csv)
262+
Success: Exported to 'wordpress_dbase.sql'.
263+
264+
# Export all tables matching prefix
265+
$ wp db export --tables=$(wp db tables --all-tables-with-prefix --format=csv)
266+
Success: Exported to 'wordpress_dbase.sql'.
267+
268+
269+
270+
### wp db import
271+
272+
Import a database from a file or from STDIN.
273+
274+
~~~
275+
wp db import [<file>] [--skip-optimization]
276+
~~~
277+
278+
Runs SQL queries using `DB_HOST`, `DB_NAME`, `DB_USER` and
279+
`DB_PASSWORD` database credentials specified in wp-config.php. This
280+
does not create database by itself and only performs whatever tasks are
281+
defined in the SQL.
282+
283+
**OPTIONS**
284+
285+
[<file>]
286+
The name of the SQL file to import. If '-', then reads from STDIN. If omitted, it will look for '{dbname}.sql'.
287+
288+
[--skip-optimization]
289+
When using an SQL file, do not include speed optimization such as disabling auto-commit and key checks.
290+
291+
**EXAMPLES**
292+
293+
# Import MySQL from a file.
294+
$ wp db import wordpress_dbase.sql
295+
Success: Imported from 'wordpress_dbase.sql'.
296+
297+
298+
299+
### wp db tables
300+
301+
List the database tables.
302+
303+
~~~
304+
wp db tables [<table>...] [--scope=<scope>] [--network] [--all-tables-with-prefix] [--all-tables] [--format=<format>]
305+
~~~
306+
307+
Defaults to all tables registered to the $wpdb database handler.
308+
309+
**OPTIONS**
310+
311+
[<table>...]
312+
List tables based on wildcard search, e.g. 'wp_*_options' or 'wp_post?'.
313+
314+
[--scope=<scope>]
315+
Can be all, global, ms_global, blog, or old tables. Defaults to all.
316+
317+
[--network]
318+
List all the tables in a multisite install. Overrides --scope=<scope>.
319+
320+
[--all-tables-with-prefix]
321+
List all tables that match the table prefix even if not registered on $wpdb. Overrides --network.
322+
323+
[--all-tables]
324+
List all tables in the database, regardless of the prefix, and even if not registered on $wpdb. Overrides --all-tables-with-prefix.
325+
326+
[--format=<format>]
327+
Render output in a particular format.
328+
---
329+
default: list
330+
options:
331+
- list
332+
- csv
333+
---
334+
335+
**EXAMPLES**
336+
337+
# List tables for a single site, without shared tables like 'wp_users'
338+
$ wp db tables --scope=blog --url=sub.example.com
339+
wp_3_posts
340+
wp_3_comments
341+
wp_3_options
342+
wp_3_postmeta
343+
wp_3_terms
344+
wp_3_term_taxonomy
345+
wp_3_term_relationships
346+
wp_3_termmeta
347+
wp_3_commentmeta
348+
349+
# Export only tables for a single site
350+
$ wp db export --tables=$(wp db tables --url=sub.example.com --format=csv)
351+
Success: Exported to wordpress_dbase.sql
13352

14353
## Installing
15354

16-
Installing this package requires WP-CLI v1.1.0 or greater. Update to the latest stable release with `wp cli update`.
355+
Installing this package requires WP-CLI v0.23.0 or greater. Update to the latest stable release with `wp cli update`.
17356

18357
Once you've done so, you can install this package with `wp package install wp-cli/db-command`.
19358

0 commit comments

Comments
 (0)