docs: make Chinese README the default
This commit is contained in:
@@ -1,51 +1,40 @@
|
||||
<!-- WEHUB_ZH_README -->
|
||||
> [!NOTE]
|
||||
> 本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
|
||||
> [English](./README.en.md) · [原始项目](https://github.com/dolthub/dolt) · [上游 README](https://github.com/dolthub/dolt/blob/HEAD/README.md)
|
||||
> 原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
|
||||
|
||||
<img height="100" src="./images/Dolt-Logo@3x.svg"/>
|
||||
|
||||
# Dolt is Git for Data!
|
||||
# Dolt 是数据的 Git!
|
||||
|
||||
Dolt is a SQL database that you can fork, clone, branch, merge, push
|
||||
and pull just like a Git repository.
|
||||
Dolt 是一款 SQL 数据库,你可以像操作 Git 仓库一样对它进行 fork、clone、branch、merge、push 和 pull。
|
||||
|
||||
Connect to Dolt just like any MySQL database to read or modify schema
|
||||
and data. Version control functionality is exposed in SQL via system
|
||||
tables, functions, and procedures.
|
||||
像连接任何 MySQL 数据库一样连接 Dolt,即可读取或修改 schema 和数据。版本控制功能通过 SQL 中的系统表、函数和存储过程暴露出来。
|
||||
|
||||
Or, use the Git-like 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 的命令行界面导入 CSV 文件、提交更改、推送到远程,或合并队友的更改。你熟悉的所有 Git 命令在 Dolt 中用法完全相同。
|
||||
|
||||
Git versions files. Dolt versions tables. It's like Git and MySQL had a
|
||||
baby.
|
||||
Git 对文件进行版本控制。Dolt 对表进行版本控制。它就像 Git 和 MySQL 的结合体。
|
||||
|
||||
We also built [DoltHub](https://www.dolthub.com), 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](https://www.doltlab.com).
|
||||
If you want us to run a Dolt server for you, we have [Hosted Dolt](https://hosted.doltdb.com).
|
||||
我们还构建了 [DoltHub](https://www.dolthub.com),,一个分享 Dolt 数据库的平台。我们免费托管公开数据。如果你想自行托管 DoltHub,我们有 [DoltLab](https://www.doltlab.com).。如果你想让我们为你运行 Dolt 服务器,我们有 [Hosted Dolt](https://hosted.doltdb.com).。
|
||||
|
||||
Prefer Postgres instead of MySQL? Try [Doltgres](https://github.com/dolthub/doltgresql), now
|
||||
in its Beta release.
|
||||
更喜欢 Postgres 而不是 MySQL?试试 [Doltgres](https://github.com/dolthub/doltgresql),,目前已进入 Beta 版本。
|
||||
|
||||
[Join us on Discord](https://discord.com/invite/RFwfYpu) to say hi and
|
||||
ask questions, or [check out our roadmap](https://dolthub.com/docs/other/roadmap)
|
||||
to see what we're building next.
|
||||
[加入我们的 Discord](https://discord.com/invite/RFwfYpu)打个招呼、提问,或[查看我们的路线图](https://dolthub.com/docs/other/roadmap),了解我们接下来要构建什么。
|
||||
|
||||
# Video Introduction
|
||||
# 视频介绍
|
||||
|
||||
[](https://www.youtube.com/watch?v=H2iZy0Cme10)
|
||||
|
||||
# What's it for?
|
||||
# 它有什么用?
|
||||
|
||||
Lots of things! Dolt is a generally useful tool with countless
|
||||
applications. But if you want some ideas, [here's how people are using
|
||||
it so far](https://dolthub.com/blog/2024-10-15-dolt-use-cases/).
|
||||
用途很多!Dolt 是一款通用工具,应用场景数不胜数。但如果你想找些灵感,[可以看看人们目前是如何使用它的](https://dolthub.com/blog/2024-10-15-dolt-use-cases/).。
|
||||
|
||||
Dolt powers [Beads](https://github.com/gastownhall/beads) and
|
||||
[Gas Town](https://github.com/steveyegge/gastown). It's the best database
|
||||
for agent memory, especially as you move up the ladder to multi-agent and
|
||||
multi-machine workflows.
|
||||
Dolt 为 [Beads](https://github.com/gastownhall/beads) 和 [Gas Town](https://github.com/steveyegge/gastown). 提供支持。它是智能体记忆(agent memory)的最佳数据库,尤其是在你迈向多智能体、多机器工作流时。
|
||||
|
||||
# Dolt CLI
|
||||
|
||||
The `dolt` CLI has the same commands as `git`, with some extras.
|
||||
`dolt` CLI 拥有与 `git` 相同的命令,并附带一些额外功能。
|
||||
|
||||
```
|
||||
$ dolt
|
||||
@@ -90,40 +79,34 @@ Valid commands for dolt are
|
||||
dump - Export all tables in the working set into a file.
|
||||
```
|
||||
|
||||
# Installation
|
||||
# 安装
|
||||
|
||||
Dolt is a single ~103 megabyte program.
|
||||
Dolt 是一个约 103 MB 的单一程序。
|
||||
|
||||
```bash
|
||||
dolt $ du -h /Users/timsehn/go/bin/dolt
|
||||
103M /Users/timsehn/go/bin/dolt
|
||||
```
|
||||
|
||||
It's really easy to install. Download it and put it on your `PATH`.
|
||||
We have a bunch of ways to make this even easier for most platforms.
|
||||
安装非常简单。下载后放到你的 `PATH` 上即可。我们还为大多数平台提供了多种更便捷的方式。
|
||||
|
||||
## From Latest Release
|
||||
## 从最新版本安装
|
||||
|
||||
To install on Linux or Mac based systems run this command in your
|
||||
terminal:
|
||||
要在基于 Linux 或 Mac 的系统上安装,请在终端中运行以下命令:
|
||||
|
||||
```
|
||||
sudo bash -c 'curl -L https://github.com/dolthub/dolt/releases/latest/download/install.sh | bash'
|
||||
```
|
||||
|
||||
This will download the latest `dolt` release and put it in
|
||||
`/usr/local/bin/`, which is probably on your `$PATH`.
|
||||
这将下载最新的 `dolt` 版本,并放到 `/usr/local/bin/` 中,该路径很可能已在你的 `$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](https://github.com/dolthub/dolt/releases), unzip it,
|
||||
and put the binary somewhere on your `$PATH`.
|
||||
安装脚本需要 sudo 权限,以便将 `dolt` 放到 `/usr/local/bin` 中。如果你没有 root 权限,或不愿以 root 权限运行脚本,可以从[最新版本](https://github.com/dolthub/dolt/releases),)下载适用于你平台的 dolt 二进制文件,解压后,将二进制文件放到 `$PATH` 上的某个位置。
|
||||
|
||||
### Linux
|
||||
|
||||
#### Arch Linux
|
||||
|
||||
Dolt is packaged in the official repositories for Arch Linux.
|
||||
Dolt 已收录在 Arch Linux 的官方软件仓库中。
|
||||
|
||||
```
|
||||
pacman -S dolt
|
||||
@@ -133,14 +116,14 @@ pacman -S dolt
|
||||
|
||||
#### Homebrew
|
||||
|
||||
Dolt is on Homebrew, updated every release.
|
||||
Dolt 已上架 Homebrew,每个版本发布时都会更新。
|
||||
|
||||
```
|
||||
brew install dolt
|
||||
```
|
||||
#### MacPorts
|
||||
|
||||
On macOS, Dolt can also be installed via a [community-managed port](https://ports.macports.org/port/dolt/) via [MacPorts](https://www.macports.org):
|
||||
在 macOS 上,也可以通过 [MacPorts](https://www.macports.org):) 的[社区维护 port](https://ports.macports.org/port/dolt/)) 安装 Dolt。
|
||||
|
||||
```sh
|
||||
sudo port install dolt
|
||||
@@ -148,15 +131,13 @@ sudo port install dolt
|
||||
|
||||
### Windows
|
||||
|
||||
Download the latest Microsoft Installer (`.msi` file) in
|
||||
[releases](https://github.com/dolthub/dolt/releases) and run
|
||||
it.
|
||||
在 [releases](https://github.com/dolthub/dolt/releases)) 中下载最新的 Microsoft Installer(`.msi` 文件)并运行。
|
||||
|
||||
For information on running on Windows, see [here](https://dolthub.com/docs/introduction/installation/windows).
|
||||
有关在 Windows 上运行的信息,请参见[此处](https://dolthub.com/docs/introduction/installation/windows).。
|
||||
|
||||
#### Chocolatey
|
||||
|
||||
You can install `dolt` using [Chocolatey](https://chocolatey.org/):
|
||||
你可以使用 [Chocolatey](https://chocolatey.org/):) 安装 `dolt`。
|
||||
|
||||
```sh
|
||||
choco install dolt
|
||||
@@ -164,32 +145,30 @@ choco install dolt
|
||||
|
||||
#### Docker
|
||||
|
||||
There are following official Docker images for Dolt:
|
||||
Dolt 提供以下官方 Docker 镜像:
|
||||
|
||||
* [`dolthub/dolt`](https://hub.docker.com/r/dolthub/dolt) for running Dolt
|
||||
as CLI tool.
|
||||
* [`dolthub/dolt-sql-server`](https://hub.docker.com/r/dolthub/dolt-sql-server) for running Dolt in server mode.
|
||||
* [`dolthub/dolt`](https://hub.docker.com/r/dolthub/dolt)):将 Dolt 作为 CLI 工具运行。
|
||||
* [`dolthub/dolt-sql-server`](https://hub.docker.com/r/dolthub/dolt-sql-server)):以服务器模式运行 Dolt。
|
||||
|
||||
## From Source
|
||||
## 从源码构建
|
||||
|
||||
Make sure you have Go installed, and that `go` is in your path. Dolt has a dependency on [cgo](https://pkg.go.dev/cmd/cgo), so you will need a working C compiler and toolchain as well.
|
||||
请确保已安装 Go,且 `go` 在你的 path 中。Dolt 依赖 [cgo](https://pkg.go.dev/cmd/cgo),),因此你还需要可用的 C 编译器和工具链。
|
||||
|
||||
Clone this repository and cd into the `go` directory. Then run:
|
||||
克隆此仓库并进入 `go` 目录。然后运行:
|
||||
|
||||
```
|
||||
go install ./cmd/dolt
|
||||
```
|
||||
|
||||
The output will be in `$GOPATH/bin`, which defaults to `~/go/bin`. To test your build, try:
|
||||
输出将位于 `$GOPATH/bin`,默认值为 `~/go/bin`。要测试你的构建,请尝试:
|
||||
|
||||
```
|
||||
~/go/bin/dolt version
|
||||
```
|
||||
|
||||
# Configuration
|
||||
# 配置
|
||||
|
||||
Verify that your installation has succeeded by running `dolt` in your
|
||||
terminal.
|
||||
在终端中运行 `dolt`,验证安装是否成功。
|
||||
|
||||
```
|
||||
$ dolt
|
||||
@@ -197,19 +176,18 @@ Valid commands for dolt are
|
||||
[...]
|
||||
```
|
||||
|
||||
Configure `dolt` with your user name and email, which you'll need to
|
||||
create commits. The commands work exactly the same as git.
|
||||
使用你的用户名和邮箱配置 `dolt`,创建提交时需要这些信息。命令用法与 git 完全相同。
|
||||
|
||||
```
|
||||
$ dolt config --global --add user.email YOU@DOMAIN.COM
|
||||
$ dolt config --global --add user.name "YOUR NAME"
|
||||
```
|
||||
|
||||
# Getting started
|
||||
# 入门
|
||||
|
||||
## Navigate to the directory where you would like your data stored
|
||||
## 导航到你想存放数据的目录
|
||||
|
||||
Dolt needs a place to store your databases. I'm going to put my databases in `~/dolt`.
|
||||
Dolt 需要一个位置来存储你的数据库。我将把数据库放在 `~/dolt`。
|
||||
|
||||
```bash
|
||||
% cd ~
|
||||
@@ -217,24 +195,24 @@ Dolt needs a place to store your databases. I'm going to put my databases in `~/
|
||||
% cd dolt
|
||||
```
|
||||
|
||||
Any databases you create will be stored in this directory. So, for this example, a directory named `getting_started` will be created here once you run `create database getting_started`. Navigating to `~/dolt/getting_started` will allow you to access this database using the Dolt command line.
|
||||
你创建的任何数据库都会存储在此目录中。因此,在本示例中,运行 `create database getting_started` 后,将在此处创建一个名为 `getting_started` 的目录。进入 `~/dolt/getting_started` 后,即可使用 Dolt 命令行访问该数据库。
|
||||
|
||||
NOTE: For this example, the `getting_started` directory will be created after you run `create database getting_started;` in a SQL shell in the [Create a schema section](#create-a-schema). Don't do anything except make the directory and navigate to it just yet.
|
||||
注意:在本示例中,`getting_started` 目录将在你在 [Create a schema section](#create-a-schema) 的 SQL shell 中运行 `create database getting_started;` 后创建。目前只需创建目录并进入即可,不要执行其他操作。
|
||||
|
||||
## Start a MySQL-compatible database server
|
||||
## 启动兼容 MySQL 的数据库服务器
|
||||
|
||||
Dolt ships with a MySQL compatible database server built in. To start it you use the command `dolt sql-server`. Running this command starts the server on port 3306.
|
||||
Dolt 内置了一个与 MySQL 兼容的数据库服务器。要启动它,请使用命令 `dolt sql-server`。运行该命令后,服务器会在 3306 端口启动。
|
||||
|
||||
```bash
|
||||
dolt sql-server
|
||||
Starting server with Config HP="localhost:3306"|T="28800000"|R="false"|L="info"
|
||||
```
|
||||
|
||||
Your terminal will just hang there. This means the server is running. Any errors will be printed in this terminal. Just leave it there and open a new terminal.
|
||||
此时终端会停在那里不动。这表示服务器正在运行。任何错误都会打印在这个终端中。让它保持运行,并打开一个新的终端。
|
||||
|
||||
## Connect with a MySQL client (up to version 8.4)
|
||||
## 使用 MySQL 客户端连接(最高支持 8.4 版本)
|
||||
|
||||
In the new terminal, we will now connect to the running database server using a client. Dolt also ships with a MySQL compatible client.
|
||||
在新的终端中,我们将使用客户端连接到正在运行的数据库服务器。Dolt 也自带了一个与 MySQL 兼容的客户端。
|
||||
|
||||
```bash
|
||||
% dolt -u root -p "" sql
|
||||
@@ -244,26 +222,26 @@ In the new terminal, we will now connect to the running database server using a
|
||||
mysql>
|
||||
```
|
||||
|
||||
In the other terminal where you ran `dolt sql-server`, you'll see the following log line.
|
||||
在运行 `dolt sql-server` 的另一个终端中,你会看到以下日志行。
|
||||
|
||||
```
|
||||
2022-06-06T13:14:32-07:00 INFO [conn 1] NewConnection {DisableClientMultiStatements=false}
|
||||
```
|
||||
|
||||
You are connected!
|
||||
你已经连接成功!
|
||||
|
||||
While we're here let's grab a copy of MySQL so we can connect with that client. Head over to the [MySQL Getting Started](https://dev.mysql.com/doc/mysql-getting-started/en/) documentation and install MySQL on your machine. I used [Homebrew](https://brew.sh/) to install MySQL on my Mac: `brew install mysql@8.4`. Alternatively, you can install only the client component by running `brew install mysql-client@8.4`.
|
||||
趁这个机会,我们先安装一份 MySQL,以便使用该客户端进行连接。请前往 [MySQL Getting Started](https://dev.mysql.com/doc/mysql-getting-started/en/) 文档,在你的机器上安装 MySQL。我在 Mac 上使用 [Homebrew](https://brew.sh/) 安装 MySQL:`brew install mysql@8.4`。或者,你也可以通过运行 `brew install mysql-client@8.4` 仅安装客户端组件。
|
||||
|
||||
NOTE: Make sure you install a MySQL 8.4 release. MySQL 8.4 is the current Long Term Support (LTS) release, meaning this is the stable and supported version of MySQL. MySQL 9.0 is also available, but is an "innovation" release, meaning it has more recent changes and features, but may not be as stable as the LTS release. The 9.0 release changes authentication support and isn't able to connect to a Dolt SQL server by default. You can install MySQL 8.4 with Homebrew by running `brew install mysql@8.4`. If you do want to use MySQL-9.0, read [our post on how to configure Dolt for `caching_sha2_password` authentication](https://www.dolthub.com/blog/2024-12-11-mysql9-and-caching-sha2-auth-support/).
|
||||
注意:请确保安装的是 MySQL 8.4 版本。MySQL 8.4 是当前长期支持(Long Term Support,LTS)版本,也就是说它是 MySQL 稳定且受支持的版本。MySQL 9.0 也可获得,但属于“创新”(innovation)版本,意味着它包含更多最新变更和功能,但可能不如 LTS 版本稳定。9.0 版本更改了认证支持,默认情况下无法连接到 Dolt SQL 服务器。你可以通过运行 `brew install mysql@8.4` 用 Homebrew 安装 MySQL 8.4。如果你确实想使用 MySQL 9.0,请阅读[我们关于如何为 `caching_sha2_password` 认证配置 Dolt 的文章](https://www.dolthub.com/blog/2024-12-11-mysql9-and-caching-sha2-auth-support/).
|
||||
|
||||
MySQL comes with a MySQL server called `mysqld` and a MySQL client called `mysql`. You're only interested in the client. After following the instructions from MySQL's documentation, make sure you have a copy of the `mysql` client on your path:
|
||||
MySQL 附带一个名为 `mysqld` 的 MySQL 服务器和一个名为 `mysql` 的 MySQL 客户端。你只需关注客户端。按照 MySQL 文档中的说明操作后,请确保你的路径上有 `mysql` 客户端:
|
||||
|
||||
```bash
|
||||
% mysql --version
|
||||
mysql Ver 8.0.29 for macos12.2 on x86_64 (Homebrew)
|
||||
```
|
||||
|
||||
Now, to connect the `mysql` client to Dolt, you are going to force the MySQL client through the TCP interface by passing in a host and port. The default is the socket interface which Dolt supports, but is only available on `localhost`. So, it's better to show off the TCP interface. The MySQL client also requires you specify a user, in this case `root`.
|
||||
现在,要将 `mysql` 客户端连接到 Dolt,你需要通过传入主机和端口,强制 MySQL 客户端走 TCP 接口。默认使用的是 socket 接口,Dolt 也支持该接口,但仅在 `localhost` 上可用。因此,更好的做法是演示 TCP 接口。MySQL 客户端还要求你指定用户,此处为 `root`。
|
||||
|
||||
```bash
|
||||
% mysql --host 127.0.0.1 --port 3306 -uroot
|
||||
@@ -282,17 +260,17 @@ Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
|
||||
mysql>
|
||||
```
|
||||
|
||||
Again, to ensure the client actually connected, you should see the following in the `dolt sql-server` terminal
|
||||
同样,为了确认客户端确实已连接,你应该在 `dolt sql-server` 终端中看到以下内容
|
||||
|
||||
```
|
||||
2022-06-06T13:26:55-07:00 INFO [conn 2] NewConnection {DisableClientMultiStatements=false}
|
||||
```
|
||||
|
||||
As you can see, Dolt supports any MySQL-compatible client. Dolt ships with a client but you can use any MySQL client, like the one that comes with MySQL.
|
||||
如你所见,Dolt 支持任何与 MySQL 兼容的客户端。Dolt 自带客户端,但你可以使用任何 MySQL 客户端,例如 MySQL 自带的那个。
|
||||
|
||||
## Create a schema
|
||||
## 创建 schema
|
||||
|
||||
Now we're actually ready to do something interesting. I'll stay in the `mysql` client and execute the following SQL statements to create a database called `getting_started`. The `getting_started` database will have three tables: `employees`, `teams`, and `employees_teams`.
|
||||
现在我们终于可以做些有意思的事了。我会留在 `mysql` 客户端中,执行以下 SQL 语句来创建一个名为 `getting_started` 的数据库。`getting_started` 数据库将包含三张表:`employees`、`teams` 和 `employees_teams`。
|
||||
|
||||
```
|
||||
mysql> create database getting_started;
|
||||
@@ -332,17 +310,17 @@ mysql> show tables;
|
||||
3 rows in set (0.00 sec)
|
||||
```
|
||||
|
||||
Dolt supports foreign keys, secondary indexes, triggers, check constraints, and stored procedures. It's a modern, feature-rich SQL database.
|
||||
Dolt 支持外键、二级索引、触发器、检查约束和存储过程。它是一个功能丰富的现代 SQL 数据库。
|
||||
|
||||
## Make a Dolt commit
|
||||
## 创建 Dolt commit
|
||||
|
||||
It's time to use your first Dolt feature. We're going to make a Dolt [commit](https://dolthub.com/docs/concepts/dolt/commits). A Dolt commit allows you to time travel and see lineage. Make a Dolt commit whenever you want to restore or compare to this point in time.
|
||||
是时候使用你的第一个 Dolt 功能了。我们将创建一个 Dolt [commit](https://dolthub.com/docs/concepts/dolt/commits). Dolt commit 允许你进行时间旅行并查看血缘关系。每当你想恢复到这一时间点或与之进行比较时,就创建一个 Dolt commit。
|
||||
|
||||
Dolt exposes version control functionality through a Git-style interface. On the command line, Dolt commands map exactly to their Git equivalent with the targets being tables instead of files. In SQL, Dolt exposes version control read operations as [system tables](https://dolthub.com/docs/sql-reference/version-control/dolt-system-tables) and version control write operations as [stored procedures](https://dolthub.com/docs/sql-reference/version-control/dolt-sql-procedures).
|
||||
Dolt 通过类似 Git 的界面暴露版本控制功能。在命令行中,Dolt 命令与对应的 Git 命令一一映射,只是目标对象从文件变成了表。在 SQL 中,Dolt 将版本控制的读操作暴露为[系统表](https://dolthub.com/docs/sql-reference/version-control/dolt-system-tables),将版本控制的写操作暴露为[存储过程](https://dolthub.com/docs/sql-reference/version-control/dolt-sql-procedures).
|
||||
|
||||
The naming of the system tables and stored procedures follows the `dolt_<command>` pattern. So `dolt add` on the CLI becomes `dolt_add` as a stored procedure. Passing options also follows the command line model. For instance, to specify tables to add, send the table names in as options to the `dolt_add` procedure. For named arguments like sending a message into the `dolt_commit` command use two arguments in sequence like `('-m', 'This is a message')`. If you know Git, the version control procedures and system tables should feel familiar.
|
||||
系统表和存储过程的命名遵循 `dolt_<command>` 模式。因此,CLI 中的 `dolt add` 会变成存储过程 `dolt_add`。传递选项也遵循命令行模型。例如,要指定要添加的表,请将表名作为选项传给 `dolt_add` 存储过程。对于命名参数,例如向 `dolt_commit` 命令发送消息,请按顺序使用两个参数,如 `('-m', 'This is a message')`。如果你熟悉 Git,这些版本控制存储过程和系统表应该会感觉很熟悉。
|
||||
|
||||
So, we add and commit our new schema like so.
|
||||
那么,我们像这样添加并提交新 schema。
|
||||
|
||||
```
|
||||
mysql> call dolt_add('teams', 'employees', 'employees_teams');
|
||||
@@ -371,13 +349,13 @@ mysql> select * from dolt_log;
|
||||
2 rows in set (0.01 sec)
|
||||
```
|
||||
|
||||
There you have it. Your schema is created and you have a Dolt commit tracking the creation, as seen in the `dolt_log` system table.
|
||||
就是这样。你的 schema 已创建,并且有一个 Dolt commit 在跟踪这次创建,可以在 `dolt_log` 系统表中看到。
|
||||
|
||||
Note, a Dolt commit is different than a standard SQL transaction `COMMIT`. In this case, I am running the database with [`AUTOCOMMIT`](https://dev.mysql.com/doc/refman/5.6/en/innodb-autocommit-commit-rollback.html) on, so each SQL statement is automatically generating a transaction `COMMIT`. If you want system to generate a Dolt commit for every transaction use the system variable, [`@@dolt_transaction_commit`](https://dolthub.com/docs/sql-reference/version-control/dolt-sysvars#dolt_transaction_commit).
|
||||
请注意,Dolt commit 不同于标准 SQL 事务 `COMMIT`。在本例中,我启用了 [`AUTOCOMMIT`](https://dev.mysql.com/doc/refman/5.6/en/innodb-autocommit-commit-rollback.html) 运行数据库,因此每条 SQL 语句都会自动生成事务 `COMMIT`。如果你希望系统为每个事务生成 Dolt commit,请使用系统变量 [`@@dolt_transaction_commit`](https://dolthub.com/docs/sql-reference/version-control/dolt-sysvars#dolt_transaction_commit).
|
||||
|
||||
## Insert some data
|
||||
## 插入一些数据
|
||||
|
||||
Now, I'm going to populate the database with a few employees here at DoltHub. Then, I'll assign the employees to two teams: engineering and sales. The CEO wears many hats at a start up so he'll be assigned to multiple teams.
|
||||
现在,我要向数据库中填入 DoltHub 的几位员工。然后,我会把这些员工分配到两个团队:工程(engineering)和销售(sales)。在初创公司里,CEO 身兼数职,所以他会同时被分配到多个团队。
|
||||
|
||||
```
|
||||
mysql> insert into employees values
|
||||
@@ -410,7 +388,7 @@ mysql> insert into employees_teams values
|
||||
ERROR 1452 (HY000): cannot add or update a child row - Foreign key violation on fk: `rv9ek7ft`, table: `employees_teams`, referenced table: `teams`, key: `[2]`
|
||||
```
|
||||
|
||||
Oops, I violated a constraint. It looks like I created the table with teams before employees. You should always specify your columns when you insert, not rely on natural ordering. Serves me right! Dolt comes with the full power of a modern SQL relational database to ensure data integrity.
|
||||
哎呀,我违反了约束。看来我创建表时把 teams 放在 employees 前面了。插入时应该始终明确指定列,而不要依赖自然顺序。活该!Dolt 具备现代 SQL 关系型数据库的全部能力,可确保数据完整性。
|
||||
|
||||
```
|
||||
mysql> insert into employees_teams(employee_id, team_id) values
|
||||
@@ -435,11 +413,11 @@ mysql> select first_name, last_name, team_name from employees
|
||||
3 rows in set (0.00 sec)
|
||||
```
|
||||
|
||||
Looks like everything is inserted and correct. I was able to list the members of the engineering team using that three table `JOIN`. Dolt supports up to twelve table `JOIN`s. Again, Dolt is a modern SQL relational database paired with Git-style version control.
|
||||
看起来一切都已正确插入。我能够用那个三表 `JOIN` 列出工程团队的成员。Dolt 最多支持十二表 `JOIN`s。再说一次,Dolt 是现代 SQL 关系型数据库,并配有 Git 风格的版本控制。
|
||||
|
||||
## Examine the diff
|
||||
## 查看 diff
|
||||
|
||||
Now, what if you want to see what changed in your working set before you make a commit? You use the `dolt_status` and `dolt_diff_<tablename>` system tables.
|
||||
现在,如果你想在提交之前查看工作区里有哪些变更,可以使用 `dolt_status` 和 `dolt_diff_<tablename>` 系统表。
|
||||
|
||||
```
|
||||
mysql> select * from dolt_status;
|
||||
@@ -464,9 +442,9 @@ mysql> select * from dolt_diff_employees;
|
||||
4 rows in set (0.00 sec)
|
||||
```
|
||||
|
||||
As you can see from the diff I've added the correct values to the `employees` table. The values were previously `NULL` and now they are populated.
|
||||
从 diff 可以看出,我已向 `employees` 表添加了正确的值。这些值之前是 `NULL`,现在已填充完成。
|
||||
|
||||
Let's finish off with another Dolt commit this time adding all effected tables using `-am`.
|
||||
最后再来一次 Dolt 提交,这次用 `-am` 添加所有受影响的表。
|
||||
|
||||
```
|
||||
mysql> call dolt_commit('-am', 'Populated tables with data');
|
||||
@@ -478,7 +456,7 @@ mysql> call dolt_commit('-am', 'Populated tables with data');
|
||||
1 row in set (0.02 sec)
|
||||
```
|
||||
|
||||
You can inspect the log using `dolt_log` and see which tables changed in each commit using an unscoped `dolt_diff`. Unscoped `dolt_diff` tells you whether schema, data, or both changed in that particular commit for the table.
|
||||
你可以用 `dolt_log` 检查日志,并用不带作用域的 `dolt_diff` 查看每次提交中哪些表发生了变更。不带作用域的 `dolt_diff` 会告诉你该次提交中该表的 schema、data 或二者是否发生了变化。
|
||||
|
||||
```
|
||||
mysql> select * from dolt_log;
|
||||
@@ -505,9 +483,9 @@ mysql> select * from dolt_diff;
|
||||
6 rows in set (0.00 sec)
|
||||
```
|
||||
|
||||
## Oh no! I made a mistake.
|
||||
## 糟了!我犯了个错误。
|
||||
|
||||
Dolt supports undoing changes via `call dolt_reset()`. Let's imagine I accidentally drop a table.
|
||||
Dolt 支持通过 `call dolt_reset()` 撤销变更。假设我不小心删了一张表。
|
||||
|
||||
```
|
||||
mysql> drop table employees_teams;
|
||||
@@ -523,7 +501,7 @@ mysql> show tables;
|
||||
2 rows in set (0.00 sec)
|
||||
```
|
||||
|
||||
In a traditional database, this could be disastrous. In Dolt, you're one command away from getting your table back.
|
||||
在传统数据库中,这可能会带来灾难性后果。在 Dolt 中,你只需一条命令就能恢复表。
|
||||
|
||||
```
|
||||
mysql> call dolt_reset('--hard');
|
||||
@@ -545,26 +523,26 @@ mysql> show tables;
|
||||
3 rows in set (0.01 sec)
|
||||
```
|
||||
|
||||
Dolt makes operating databases less error prone. You can always back out changes you have in progress or rewind to a known good state. You also have the ability to undo specific commits using [`dolt_revert()`](https://dolthub.com/docs/sql-reference/version-control/dolt-sql-procedures#dolt_revert). Even if you accidentally run `drop database` on the wrong database, Dolt lets you undo that by calling the [`dolt_undrop()` stored procedure](https://dolthub.com/docs/sql-reference/version-control/dolt-sql-procedures#dolt_undrop).
|
||||
Dolt 让数据库运维更少出错。你随时可以回滚进行中的更改,或回溯到已知的良好状态。你还可以使用 [`dolt_revert()`](https://dolthub.com/docs/sql-reference/version-control/dolt-sql-procedures#dolt_revert). 撤销特定提交。即使你意外在错误的数据库上运行了 `drop database`,Dolt 也允许你通过调用 [`dolt_undrop()` stored procedure](https://dolthub.com/docs/sql-reference/version-control/dolt-sql-procedures#dolt_undrop). 来撤销该操作。
|
||||
|
||||
|
||||
## See the data in a SQL Workbench
|
||||
## 在 SQL Workbench 中查看数据
|
||||
|
||||
Hate the command line? Let's use [Tableplus](https://tableplus.com/) to make some modifications. Tableplus is a free SQL Workbench. Follow the installation instructions from their website.
|
||||
讨厌命令行?让我们使用 [Tableplus](https://tableplus.com/) 进行一些修改。Tableplus 是一款免费的 SQL Workbench。请按照其官网的安装说明进行操作。
|
||||
|
||||
Now, to connect you must select MySQL as the connection type. Then enter a name for your connection, `getting_started` as your database, and `root` as your user.
|
||||
现在,要连接数据库,你必须选择 MySQL 作为连接类型。然后为连接输入一个名称,将 `getting_started` 作为数据库,将 `root` 作为用户。
|
||||
|
||||

|
||||
|
||||
Click connect and you'll be presented with a familiar database workbench GUI.
|
||||
点击连接后,你将看到一个熟悉的数据库 workbench GUI。
|
||||
|
||||

|
||||
|
||||
## Make changes on a branch
|
||||
## 在分支上进行更改
|
||||
|
||||
To make changes on a branch, I use the `dolt_checkout()` stored procedure. Using the `-b` option creates a branch, just like in Git.
|
||||
要在分支上进行更改,我使用 `dolt_checkout()` 存储过程。使用 `-b` 选项会创建分支,就像在 Git 中一样。
|
||||
|
||||
Tableplus gives me the ability to enter a multiple line SQL script on the SQL tab. I entered the following SQL to checkout a branch, update, insert, delete, and finally Dolt commit my changes.
|
||||
Tableplus 让我可以在 SQL 选项卡中输入多行 SQL 脚本。我输入了以下 SQL,用于检出分支、更新、插入、删除,最后 Dolt commit 我的更改。
|
||||
|
||||
```SQL
|
||||
call dolt_checkout('-b','modifications');
|
||||
@@ -575,11 +553,11 @@ delete from employees_teams where employee_id=0 and team_id=1;
|
||||
call dolt_commit('-am', 'Modifications on a branch');
|
||||
```
|
||||
|
||||
Here's the result in Tableplus.
|
||||
以下是 Tableplus 中的结果。
|
||||
|
||||

|
||||
|
||||
Back in my terminal, I cannot see the table modifications made in Tableplus because they happened on a different branch than the one I have checked out in my session.
|
||||
回到终端后,我看不到在 Tableplus 中所做的表修改,因为这些更改发生在与我当前会话中检出的分支不同的分支上。
|
||||
|
||||
```
|
||||
mysql> select * from dolt_branches;
|
||||
@@ -611,7 +589,7 @@ mysql> select * from employees;
|
||||
4 rows in set (0.00 sec)
|
||||
```
|
||||
|
||||
I can query the branch no matter what I have checked out using SQL `as of` syntax.
|
||||
无论当前检出的是哪个分支,我都可以使用 SQL `as of` 语法查询该分支。
|
||||
|
||||
```
|
||||
mysql> select * from employees as of 'modifications';
|
||||
@@ -627,7 +605,7 @@ mysql> select * from employees as of 'modifications';
|
||||
5 rows in set (0.01 sec)
|
||||
```
|
||||
|
||||
If I'd like to see the diff between the two branches, I can use the `dolt_diff()` table function. It takes two branches and the table name as arguments.
|
||||
如果我想查看两个分支之间的 diff,可以使用 `dolt_diff()` 表函数。它接受两个分支和表名作为参数。
|
||||
|
||||
```
|
||||
mysql> select * from dolt_diff('main', 'modifications', 'employees');
|
||||
@@ -640,11 +618,11 @@ mysql> select * from dolt_diff('main', 'modifications', 'employees');
|
||||
2 rows in set (0.00 sec)
|
||||
```
|
||||
|
||||
As you can see, you have the full power of Git-style branches and diffs in a SQL database with Dolt.
|
||||
如你所见,借助 Dolt,你可以在 SQL 数据库中获得 Git 风格分支和 diff 的全部能力。
|
||||
|
||||
## Make a schema change on another branch
|
||||
## 在另一个分支上进行 schema 更改
|
||||
|
||||
I can also make schema changes on branches for isolated testing of new schema. I'm going to add a `start_date` column on a new branch and populate it.
|
||||
我也可以在分支上进行 schema 更改,以便对新 schema 进行隔离测试。我将在新分支上添加 `start_date` 列并填充数据。
|
||||
|
||||
```
|
||||
mysql> call dolt_checkout('-b', 'schema_changes');
|
||||
@@ -686,11 +664,11 @@ mysql> call dolt_commit('-am', 'Added start_date column to employees');
|
||||
1 row in set (0.01 sec)
|
||||
```
|
||||
|
||||
Changing schema on a branch gives you a new method for doing isolated integration testing of new schema changes.
|
||||
在分支上更改 schema 为你提供了一种对新 schema 更改进行隔离集成测试的新方法。
|
||||
|
||||
## Merge it all together
|
||||
## 全部合并
|
||||
|
||||
Let's assume all the testing of the new schema on the `schema_changes` branch and data on the `modifications` branch completed flawlessly. It's time to merge all our edits together onto `main`. This is done using the `dolt_merge` stored procedure.
|
||||
假设在 `schema_changes` 分支上对新 schema 的测试,以及在 `modifications` 分支上的数据测试都已顺利完成。是时候将所有编辑合并到 `main` 上了。这通过 `dolt_merge` 存储过程完成。
|
||||
|
||||
```
|
||||
mysql> call dolt_checkout('main');
|
||||
@@ -724,7 +702,7 @@ mysql> select * from employees;
|
||||
4 rows in set (0.00 sec)
|
||||
```
|
||||
|
||||
Schema change successful. We now have start dates. Data changes are next.
|
||||
Schema 变更成功。我们现在有了开始日期(start dates)。接下来进行数据变更。
|
||||
|
||||
```
|
||||
mysql> call dolt_merge('modifications');
|
||||
@@ -748,7 +726,7 @@ mysql> select * from employees;
|
||||
5 rows in set (0.00 sec)
|
||||
```
|
||||
|
||||
Data changes successful as well. As you can see, I am now "Timothy" instead of "Tim", Daylon is added, and we all have start dates except for Daylon who was added on a different branch.
|
||||
数据变更也成功了。如你所见,我现在是 "Timothy" 而不是 "Tim",Daylon 已被添加,我们所有人都有开始日期,除了 Daylon——他是在另一个分支上添加的。
|
||||
|
||||
```
|
||||
mysql> select first_name, last_name, team_name from employees
|
||||
@@ -763,9 +741,9 @@ mysql> select first_name, last_name, team_name from employees
|
||||
1 row in set (0.01 sec)
|
||||
```
|
||||
|
||||
I'm also gone from the Sales Team. Engineering is life.
|
||||
我也离开了 Sales Team。Engineering 才是王道。
|
||||
|
||||
I have to commit all my changes because the last merge was not a fast-forward merge.
|
||||
我必须提交所有更改,因为上次合并不是快进(fast-forward)合并。
|
||||
|
||||
```
|
||||
mysql> call dolt_commit('-m', 'Merged all branches');
|
||||
@@ -790,13 +768,13 @@ mysql> select * from dolt_log;
|
||||
6 rows in set (0.00 sec)
|
||||
```
|
||||
|
||||
Now, we have a database with all the schema and data changes merged and ready for use.
|
||||
现在,我们有了一个数据库,其中所有 schema 和数据变更都已合并,可以投入使用。
|
||||
|
||||
## Audit Cell Lineage
|
||||
## 审计单元格血缘(Cell Lineage)
|
||||
|
||||
Which commit changed my first name? With Dolt you have lineage for every cell in your database. Let's use the `dolt_history_<tablename>` and `dolt_diff_<tablename>` to explore the lineage features in Dolt.
|
||||
是哪个 commit 更改了我的名字?使用 Dolt,你可以追踪数据库中每个单元格的血缘。让我们使用 `dolt_history_<tablename>` 和 `dolt_diff_<tablename>` 来探索 Dolt 中的血缘功能。
|
||||
|
||||
`dolt_history_<tablename>` shows you the state of the row at every commit.
|
||||
`dolt_history_<tablename>` 会显示该行在每一个 commit 时的状态。
|
||||
|
||||
```
|
||||
mysql> select * from dolt_history_employees where id=0 order by commit_date;
|
||||
@@ -811,7 +789,7 @@ mysql> select * from dolt_history_employees where id=0 order by commit_date;
|
||||
4 rows in set (0.00 sec)
|
||||
```
|
||||
|
||||
`dolt_diff_<tablename>` allows you to filter the history down to only commits when the cell in question changed. In this case, I'm interested in the commits that are changing my first name. Note, there are two commits that changed my name because one is the original change and the second is the merge commit.
|
||||
`dolt_diff_<tablename>` 允许你将历史记录筛选为仅显示目标单元格发生变更的 commit。在这种情况下,我关心的是更改我名字的 commit。注意,有两个 commit 更改了我的名字,其中一个是原始变更,另一个是 merge commit。
|
||||
|
||||
```
|
||||
mysql> select to_commit,from_first_name,to_first_name from dolt_diff_employees
|
||||
@@ -827,23 +805,21 @@ mysql> select to_commit,from_first_name,to_first_name from dolt_diff_employees
|
||||
3 rows in set (0.01 sec)
|
||||
```
|
||||
|
||||
Dolt provides powerful data audit capabilities down to individual cells. When, how, and why has each cell in your database changed over time?
|
||||
Dolt 提供了强大的数据审计能力,可精确到单个单元格。数据库中的每个单元格随时间是如何、为何以及何时发生变更的?
|
||||
|
||||
# Additional Reading
|
||||
# 延伸阅读
|
||||
|
||||
Head over to [our documentation](https://dolthub.com/docs/introduction/what-is-dolt) now that you have a feel for Dolt. You can also read about what we've been working on in [our blog](https://www.dolthub.com/blog/).
|
||||
既然你已经对 Dolt 有了初步了解,请前往 [我们的文档](https://dolthub.com/docs/introduction/what-is-dolt)。你也可以在 [我们的博客](https://www.dolthub.com/blog/). 中了解我们一直在做什么。
|
||||
|
||||
# Security Policy
|
||||
# 安全策略
|
||||
|
||||
[Dolt's current security policy](https://github.com/dolthub/dolt/blob/main/SECURITY.md) is maintained in this repository. Please follow the disclosure instructions there. Please do not initially report security issues in this repository's public GitHub issues.
|
||||
[Dolt 当前的安全策略](https://github.com/dolthub/dolt/blob/main/SECURITY.md) 维护在本仓库中。请按照其中的披露说明操作。请勿在本仓库的公开 GitHub Issues 中初次报告安全问题。
|
||||
|
||||
# Credits and License
|
||||
# 致谢与许可
|
||||
|
||||
Dolt relies heavily on open source code and ideas from the
|
||||
[Noms](https://github.com/attic-labs/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 大量依赖来自
|
||||
[Noms](https://github.com/attic-labs/noms) 项目的开源代码和理念。我们非常感谢 Noms 团队免费提供这些代码,
|
||||
没有它们,我们无法如此快速地构建 Dolt。
|
||||
|
||||
Dolt is licensed under the Apache License, Version 2.0. See
|
||||
[LICENSE](https://github.com/dolthub/dolt/blob/master/LICENSE) for
|
||||
details.
|
||||
Dolt 采用 Apache License, Version 2.0 许可。详见
|
||||
[LICENSE](https://github.com/dolthub/dolt/blob/master/LICENSE)。
|
||||
|
||||
Reference in New Issue
Block a user