dolthub/go-mysql-server
dolthub/go-mysql-server has 2,665 GitHub stars and 303 forks. GitHot measured 0 stars in 24 hours, 0 in 7 days, and +3 in 15 days. Last checked 2026-11-12 18:23 UTC. Last push 2026-10-30.
A MySQL-compatible relational database with a storage agnostic query engine. Implemented in Go.
측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- +3
- in 1 month
- 업데이트 지연
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Original
A MySQL compatible database engine written in Go
go-mysql-server is a data-source agnostic SQL engine and server which runs queries on data sources you provide, using the MySQL dialect and wire protocol. A simple in-memory database implementation is included, and you can query any data source you want by implementing your own backend.
Dolt, a SQL database with Git-style versioning, is the main production database implementation of this package. Check out that project for a reference implementation. Or, hop into the Dolt Discord server here if you want to talk to the core developers behind go-mysql-server and Dolt.
Compatibility
With the exception of specific limitations (see below), go-mysql-server is a drop-in replacement for MySQL. Any client library, tool, query, SQL syntax, SQL function, etc. that works with MySQL (including the MariaDB Java client) should also work with go-mysql-server. If you find a gap in functionality, please file an issue.
For full MySQL compatibility documentation, see the Dolt docs on this topic.
Scope of this project
- SQL server and engine to query your data sources.
- In-memory database backend implementation suitable for use in tests.
- Interfaces you can use to implement new backends to query your own data sources.
- With a few caveats and using a full database implementation, a drop-in MySQL database replacement.
go-mysql-server has two primary uses case:
Stand-in for MySQL in a golang test environment, using the built-in
memorydatabase implementation.Providing access to arbitrary data sources with SQL queries by implementing a handful of interfaces. The most complete real-world implementation is Dolt.
Installation
Add go-mysql-server as a dependency to your project. In the
directory with the go.mod file, run:
go get github.com/dolthub/go-mysql-server@latest
To implement ICU-compatible regexes, go-mysql-server has a dependency on
go-icu-regex, which has a Cgo dependency on
ICU4C. To build a project
which depends on go-mysql-server, you should have a C/C++ toolchain, you
should build with Cgo enabled, and you should have libicu-dev, or the
equivalent for your environment, installed and available to your C++ toolchain.
For convenience, go-mysql-server also includes a non-compatible regex
implementation based on the Go standard library regex.Regex. To build against
that, instead of the go-icu-regex implementation, you must compile with
-tags=gms_pure_go. Please note that some of go-mysql-server's tests do not
pass with -tags=gms_pure_go and in general gms_pure_go is not recommended
for users seeking MySQL compatibility.
Using the in-memory test server
The in-memory test server can replace a real MySQL server in tests. Start the server using the code in the _example directory, also reproduced below.
package main
import (
"context"
"fmt"
"time"
"github.com/dolthub/vitess/go/vt/proto/query"
sqle "github.com/dolthub/go-mysql-server"
"github.com/dolthub/go-mysql-server/memory"
"github.com/dolthub/go-mysql-server/server"
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/analyzer"
"github.com/dolthub/go-mysql-server/sql/types"
"github.com/dolthub/go-mysql-server/sql/variables"
)
// This is an example of how to implement a MySQL server.
// After running the example, you may connect to it using the following:
//
// > mysql --host=localhost --port=3306 --user=root mydb --execute="SELECT * FROM mytable;"
// +----------+-------------------+-------------------------------+----------------------------+
// | name | email | phone_numbers | created_at |
// +----------+-------------------+-------------------------------+----------------------------+
// | Jane Deo | [email protected] | ["556-565-566","777-777-777"] | 2022-11-01 12:00:00.000001 |
// | Jane Doe | [email protected] | [] | 2022-11-01 12:00:00.000001 |
// | John Doe | [email protected] | ["555-555-555"] | 2022-11-01 12:00:00.000001 |
// | John Doe | [email protected] | [] | 2022-11-01 12:00:00.000001 |
// +----------+-------------------+-------------------------------+----------------------------+
//
// The included MySQL client is used in this example, however any MySQL-compatible client will work.
var (
dbName = "mydb"
tableName = "mytable"
address = "localhost"
port = 3306
)
func main() {
vars := variables.NewEngineVariables()
pro := createTestDatabase(vars)
engine := sqle.New(analyzer.NewDefault(pro), &sqle.Config{EngineVariables: vars})
session := memory.NewSession(sql.NewBaseSessionWithVariables(vars), pro)
ctx := engine.NewContext(context.Background(), sql.WithSession(session))
ctx.SetCurrentDatabase(dbName)
// This variable may be found in the "users_example.go" file. Please refer to that file for a walkthrough on how to
// set up the "mysql" database to allow user creation and user checking when establishing connections. This is set
// to false for this example, but feel free to play around with it and see how it works.
if enableUsers {
if err := enableUserAccounts(ctx, engine); err != nil {
panic(err)
}
}
config := server.Config{
Protocol: "tcp",
Address: fmt.Sprintf("%s:%d", address, port),
}
s, err := server.NewServer(config, engine, sql.ContextFactoryWithVariables(vars), memory.NewSessionBuilderWithVariables(pro, vars), nil)
if err != nil {
panic(err)
}
if err = s.Start(); err != nil {
panic(err)
}
}
func createTestDatabase(vars *sql.EngineVariables) *memory.DbProvider {
db := memory.NewDatabase(dbName)
pro := memory.NewDBProvider(db)
session := memory.NewSession(sql.NewBaseSessionWithVariables(vars), pro)
ctx := sql.NewContextWithVariables(context.Background(), vars, sql.WithSession(session))
table := memory.NewTable(ctx, db, tableName, sql.NewPrimaryKeySchema(sql.Schema{
{Name: "name", Type: types.Text, Nullable: false, Source: tableName, PrimaryKey: true},
{Name: "email", Type: types.Text, Nullable: false, Source: tableName, PrimaryKey: true},
{Name: "phone_numbers", Type: types.JSON, Nullable: false, Source: tableName},
{Name: "created_at", Type: types.MustCreateDatetimeType(query.Type_DATETIME, 6), Nullable: false, Source: tableName},
}), db.GetForeignKeyCollection())
db.AddTable(tableName, table)
creationTime := time.Unix(0, 1667304000000001000).UTC()
_ = table.Insert(ctx, sql.NewRow("Jane Deo", "[email protected]", types.MustJSON(`["556-565-566", "777-777-777"]`), creationTime))
_ = table.Insert(ctx, sql.NewRow("Jane Doe", "[email protected]", types.MustJSON(`[]`), creationTime))
_ = table.Insert(ctx, sql.NewRow("John Doe", "[email protected]", types.MustJSON(`["555-555-555"]`), creationTime))
_ = table.Insert(ctx, sql.NewRow("John Doe", "[email protected]", types.MustJSON(`[]`), creationTime))
return pro
}
This example populates the database by creating memory.Database and
memory.Table objects via golang code, but you can also populate it
by issuing CREATE DATABASE, CREATE TABLE, etc. statements to the
server once it's running.
Once the server is running, connect with any MySQL client, including
the golang MySQL connector and the mysql shell.
> mysql --host=localhost --port=3306 --user=root mydb --execute="SELECT * FROM mytable;"
+----------+-------------------+-------------------------------+----------------------------+
| name | email | phone_numbers | created_at |
+----------+-------------------+-------------------------------+----------------------------+
| Jane Deo | [email protected] | ["556-565-566","777-777-777"] | 2022-11-01 12:00:00.000001 |
| Jane Doe | [email protected] | [] | 2022-11-01 12:00:00.000001 |
| John Doe | [email protected] | ["555-555-555"] | 2022-11-01 12:00:00.000001 |
| John Doe | [email protected] | [] | 2022-11-01 12:00:00.000001 |
+----------+-------------------+-------------------------------+----------------------------+
Limitations of the in-memory database implementation
The in-memory database implementation included with this package is intended for use in tests. It has specific limitations that we know of:
- Not
threadsafe. To
avoid concurrency issues, limit DDL and DML statements (
CREATE TABLE,INSERT, etc.) to a single goroutine. - No transaction
support. Statements
like
START TRANSACTION,ROLLBACK, andCOMMITare no-ops. - Non-performant index implementation. Indexed lookups and joins perform full table scans on the underlying tables.
Custom backend implementations
You can create your own backend to query your own data sources by implementing some interfaces. For detailed instructions, see the backend guide.
Technical documentation for contributors and backend developers
- Architecture is an overview of the various packages of the project and how they fit together.
- Contribution guide for new contributors, including instructions for how to get your PR merged.
Powered by go-mysql-server
Are you building a database backend using go-mysql-server? We would like to hear from you and include you in this list.
Security Policy
go-mysql-server's security policy 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.
Acknowledgements
go-mysql-server was originally developed by the {source-d}
organzation, and this repository was originally forked from
src-d. We want to thank
the entire {source-d} development team for their work on this
project, especially Miguel Molina (@erizocosmico) and Juanjo Álvarez
Martinez (@juanjux).
License
Apache License 2.0, see LICENSE
The Go gopher was designed by Renee French, licensed under CC BY 4.0. The mascot image is based on work by Takuya Ueda, licensed under CC BY 3.0, with modifications.
관련 프로젝트 살펴보기
Asabeneh/30-Days-Of-Python
30 Days of Python 프로그래밍 챌린지는 Python 프로그래밍 언어를 30일 동안 배우기 위한 단계별 가이드입니다. 이 챌린지는 100일 이상 걸릴 수 있습니다. 자신의 속도에 맞춰 진행하세요. 다음 동영상도 도움이 될 수 있습니다: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,673 스타grafana/grafana
개방적이고 조합 가능한 옵저버빌리티 및 데이터 시각화 플랫폼입니다. Prometheus, Loki, Elasticsearch, InfluxDB, Postgres 등 여러 소스의 메트릭, 로그, 트레이스를 시각화합니다.
77,876 스타redis/redis
실시간 데이터 기반 애플리케이션을 구축하는 개발자에게 Redis는 가장 선호되고, 가장 빠르며, 기능이 가장 풍부한 캐시, 데이터 구조 서버이자 문서 및 벡터 쿼리 엔진입니다.
77,485 스타apache/superset
Apache Superset는 데이터 시각화 및 데이터 탐색 플랫폼입니다.
75,509 스타