Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Commit 0411a81

Browse files
committed
Document database handling in a readme file.
1 parent dffebed commit 0411a81

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

sql/README.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,63 @@
1-
Database backup files.
1+
# Handling Databases with WPLib Box
2+
3+
The `{project_dir}/sql` directory is used by WPLib Box as the location for importing SQL and for generating backups.
4+
5+
## Backing up your MySQL database to a .SQL file
6+
7+
To backup simply SSH into the box and then run the `box database import` command:
8+
9+
cd /path/to/your/project/directory
10+
vagrant ssh
11+
box database backup
12+
13+
This will create a `backup.sql` file in `/path/to/your/project/sql`. If one already exists it will append a number to the end, e.g. `backup1.sql`, `backup2.sql`, etc.
14+
15+
## Importing a .SQL file into your MySQL database
16+
17+
To import you must copy your SQL file into the /sql directory, SSH into the box and then run the `box database import` command:
18+
19+
### Mac/Linux:
20+
21+
cd /path/to/your/project
22+
cp /path/to/your/sqldump.sql sql/
23+
vagrant ssh
24+
box database import mysqldump.sql
25+
26+
### Windows
27+
28+
cd C:\path\to\your\project
29+
copy C:\path\to\your\mysqldump.sql sql/
30+
vagrant ssh
31+
box database import mysqldump.sql
32+
33+
## Autmatically importing `provision.sql` on first run
34+
35+
If you have a newly cloned/installed WPLib Box it will import a file named `provision.sql` into `/path/to/your/project/sql`.
36+
37+
This is especially useful if you are working on a team and want to commit a copy of the production database in your Git repository so that everyone who clones the project will start with the same database.
38+
39+
## Chunking large .SQL dumps
40+
41+
If a .SQL file gets too large to commit to a GitHub repository you can use _"Chunking"_.
42+
43+
A chunked file is a directory that is a replacement for the chunked .SQL file and the directory contains
44+
a `{filename}.chunks.json` with details about the chunks, and two or more files of the form
45+
`{filename}-???.sql.chunk` containing the MySQL commands.
46+
47+
The following will _"chunk"_ your `provision.sql` into approximately `25mb` chunks so that GitHub will
48+
happily version control them:
49+
50+
vagrant ssh
51+
box database chunk provision.sql
52+
53+
The WPLib Box `database import` command will recognize chunked MySQL files and import them seamlessly.
54+
55+
If you want to recover the original files that was chunked just run the `database unchunk` command:
56+
57+
vagrant ssh
58+
box database unchunk provision.sql
59+
60+
61+
62+
263

0 commit comments

Comments
 (0)