Dolt is a SQL database that you can fork, clone, branch, merge, push
and pull just like a git repository. Connect to Dolt just like any
MySQL database to run queries or update the data using SQL
commands. Use the command line interface to import CSV files, commit
your changes, push them to a remote, or merge your teammate's changes.
All the commands you know for Git work exactly the same for Dolt. Git
versions files, Dolt versions tables. It's like Git and MySQL had a
baby!
We also built DoltHub, a place to share
Dolt databases. We host public data for free! If you want to host
your own version of DoltHub, we have DoltLab.
Check out our quick-start guide to skip the docs
and get started as fast as humanly possible! Or keep reading for a
high level overview of how to use the command line tool.
The dolt CLI has the same commands as git, with some extras.
$ dolt
Valid commands for dolt are
init - Create an empty Dolt data repository.
status - Show the working tree status.
add - Add table changes to the list of staged table changes.
diff - Diff a table.
reset - Remove table changes from the list of staged table changes.
commit - Record changes to the repository.
sql - Run a SQL query against tables in repository.
sql-server - Start a MySQL-compatible server.
sql-client - Starts a built-in MySQL client.
log - Show commit logs.
branch - Create, list, edit, delete branches.
checkout - Checkout a branch or overwrite a table from HEAD.
merge - Merge a branch.
conflicts - Commands for viewing and resolving merge conflicts.
revert - Undo the changes introduced in a commit.
clone - Clone from a remote data repository.
fetch - Update the database from a remote data repository.
pull - Fetch from a dolt remote data repository and merge.
push - Push to a dolt remote.
config - Dolt configuration.
remote - Manage set of tracked repositories.
backup - Manage a set of server backups.
login - Login to a dolt remote host.
creds - Commands for managing credentials.
ls - List tables in the working set.
schema - Commands for showing and importing table schemas.
table - Commands for copying, renaming, deleting, and exporting tables.
tag - Create, list, delete tags.
blame - Show what revision and author last modified each row of a table.
constraints - Commands for handling constraints.
migrate - Executes a repository migration to update to the latest format.
read-tables - Fetch table(s) at a specific commit into a new dolt repo
gc - Cleans up unreferenced data from the repository.
filter-branch - Edits the commit history using the provided query.
merge-base - Find the common ancestor of two commits.
version - Displays the current Dolt cli version.
dump - Export all tables in the working set into a file.
Installation
From Latest Release
To install on Linux or Mac based systems run this command in your
terminal:
This will download the latest dolt release and put it in
/usr/local/bin/, which is probably on your $PATH.
The install script needs sudo in order to put dolt in /usr/local/bin. If you don't have root
privileges or aren't comfortable running a script with them, you can download the dolt binary
for your platform from the latest release, unzip it,
and put the binary somewhere on your $PATH.
Homebrew
Dolt is on Homebrew, updated every release.
brew install dolt
Windows
Download the latest Microsoft Installer (.msi file) in
releases and run
it.
Use dolt sql to jump into a SQL shell, or run single queries with
the -q option.
$ dolt sql -q "select * from state_populations where state = 'New York'"
+----------+------------+
| state | population |
+----------+------------+
| New York | 340120 |
+----------+------------+
add the new tables and commit them. Every command matches git
exactly, but with tables instead of files.
$ dolt add .
$ dolt commit -m "initial data"
$ dolt status
On branch master
nothing to commit, working tree clean
Update the tables with more SQL commands, this time using the shell:
$ dolt sql
# Welcome to the DoltSQL shell.
# Statements must be terminated with ';'.
# "exit" or "quit" (or Ctrl-D) to exit.
state_pops> update state_populations set population = 0 where state like 'New%';
Query OK, 3 rows affected
Rows matched: 3 Changed: 3 Warnings: 0
state_pops> exit
Bye
See what you changed with dolt diff:
$ dolt diff
diff --dolt a/state_populations b/state_populations
--- a/state_populations @ qqr3vd0ea6264oddfk4nmte66cajlhfl
+++ b/state_populations @ 17cinjh5jpimilefd57b4ifeetjcbvn2
+-----+---------------+------------+
| | state | population |
+-----+---------------+------------+
| < | New Hampshire | 141885 |
| > | New Hampshire | 0 |
| < | New Jersey | 184139 |
| > | New Jersey | 0 |
| < | New York | 340120 |
| > | New York | 0 |
+-----+---------------+------------+
Then commit your changes once more with dolt add and dolt commit.
$ dolt add state_populations
$ dolt commit -m "More like Old Jersey"
See the history of your repository with dolt log.
% dolt log
commit babgn65p1r5n36ao4gfdj99811qauo8j
Author: Zach Musgrave <[email protected]>
Date: Wed Nov 11 13:42:27 -0800 2020
More like Old Jersey
commit 9hgk7jb7hlkvvkbornpldcopqh2gn6jo
Author: Zach Musgrave <[email protected]>
Date: Wed Nov 11 13:40:53 -0800 2020
initial data
commit 8o8ldh58pjovn8uvqvdq2olf7dm63dj9
Author: Zach Musgrave <[email protected]>
Date: Wed Nov 11 13:36:24 -0800 2020
Initialize data repository
Importing data
If you have data in flat files like CSV or JSON, you can import them
using the dolt table import command. Use dolt table import -u to
add data to an existing table, or dolt table import -c to create a
new one.
Just like with git, it's a good idea to make changes on your own
branch, then merge them back to master. The dolt checkout command
works exactly the same as git checkout.
$ dolt checkout -b <branch>
The merge command works the same too.
$ dolt merge <branch>
Working with remotes
Dolt supports remotes just like git. Remotes are set up automatically
when you clone data from one.
To push to a remote, you'll need credentials. Run dolt login to open
a browser to sign in and cache your local credentials. You can sign
into DoltHub with your Google account, your Github account, or with a
user name and password.
$ dolt login
If you have a repo that you created locally that you now want to push
to a remote, add a remote exactly like you would with git.
There's a lot more to Dolt than can fit in a README file! For full
documentation, check out the docs on
DoltHub. Some of the topics we didn't
cover here:
Dolt relies heavily on open source code and ideas from the
Noms project. We are very
thankful to the Noms team for making this code freely available,
without which we would not have been able to build Dolt so rapidly.
Dolt is licensed under the Apache License, Version 2.0. See
LICENSE for
details.
请发表评论