https://github.com/dolthub/go-mysql-server Skip to content Toggle navigation Sign in * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Resources + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} dolthub / go-mysql-server Public * * Notifications * Fork 179 * Star 1.9k * A MySQL-compatible relational database with a storage agnostic query engine. Implemented in pure Go. License Apache-2.0 license 1.9k stars 179 forks Branches Tags Activity Star Notifications * Code * Issues 26 * Pull requests 3 * Actions * Projects 0 * Security * Insights Additional navigation options * Code * Issues * Pull requests * Actions * Projects * Security * Insights dolthub/go-mysql-server This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main BranchesTags Go to file Code Folders and files Name Name Last commit Last commit message date Latest commit History 10,264 Commits .github .github _example _example _integration _integration driver driver enginetest enginetest eventscheduler eventscheduler internal internal memory memory optgen optgen server server sql sql test test .gitattributes .gitattributes .gitignore .gitignore ARCHITECTURE.md ARCHITECTURE.md BACKEND.md BACKEND.md CONTRIBUTING.md CONTRIBUTING.md LICENSE LICENSE MAINTAINERS MAINTAINERS Makefile Makefile README.md README.md SECURITY.md SECURITY.md SUPPORTED_CLIENTS.md SUPPORTED_CLIENTS.md check_repo.sh check_repo.sh engine.go engine.go engine_test.go engine_test.go format_repo.sh format_repo.sh go.mod go.mod go.sum go.sum log.go log.go mascot.png mascot.png processlist.go processlist.go processlist_test.go processlist_test.go tools.go tools.go View all files Repository files navigation * README * Apache-2.0 license * Security [mascot] A MySQL compatible database engine written in pure 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 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: 1. Stand-in for MySQL in a golang test environment, using the built-in memory database implementation. 2. 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 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/types" ) // 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 | janedeo@gmail.com | ["556-565-566","777-777-777"] | 2022-11-01 12:00:00.000001 | // | Jane Doe | jane@doe.com | [] | 2022-11-01 12:00:00.000001 | // | John Doe | john@doe.com | ["555-555-555"] | 2022-11-01 12:00:00.000001 | // | John Doe | johnalt@doe.com | [] | 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() { pro := createTestDatabase() engine := sqle.NewDefault(pro) session := memory.NewSession(sql.NewBaseSession(), pro) ctx := sql.NewContext(context.Background(), sql.WithSession(session)) ctx.SetCurrentDatabase("test") // 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, memory.NewSessionBuilder(pro), nil) if err != nil { panic(err) } if err = s.Start(); err != nil { panic(err) } } func createTestDatabase() *memory.DbProvider { db := memory.NewDatabase(dbName) db.BaseDatabase.EnablePrimaryKeyIndexes() pro := memory.NewDBProvider(db) session := memory.NewSession(sql.NewBaseSession(), pro) ctx := sql.NewContext(context.Background(), sql.WithSession(session)) table := memory.NewTable(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", "janedeo@gmail.com", types.MustJSON(`["556-565-566", "777-777-777"]`), creationTime)) _ = table.Insert(ctx, sql.NewRow("Jane Doe", "jane@doe.com", types.MustJSON(`[]`), creationTime)) _ = table.Insert(ctx, sql.NewRow("John Doe", "john@doe.com", types.MustJSON(`["555-555-555"]`), creationTime)) _ = table.Insert(ctx, sql.NewRow("John Doe", "johnalt@doe.com", 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 | janedeo@gmail.com | ["556-565-566","777-777-777"] | 2022-11-01 12:00:00.000001 | | Jane Doe | jane@doe.com | [] | 2022-11-01 12:00:00.000001 | | John Doe | john@doe.com | ["555-555-555"] | 2022-11-01 12:00:00.000001 | | John Doe | johnalt@doe.com | [] | 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, and COMMIT are 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 * dolt * gitbase (defunct) 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 Alvarez Martinez (@juanjux). License Apache License 2.0, see LICENSE About A MySQL-compatible relational database with a storage agnostic query engine. Implemented in pure Go. Topics mysql sql sql-server database mysql-server query-engine relational-database sql-engine Resources Readme License Apache-2.0 license Security policy Security policy Activity Custom properties Stars 1.9k stars Watchers 23 watching Forks 179 forks Report repository Releases 13 Q2 2024 Release Patch Latest Apr 9, 2024 + 12 releases Sponsor this project Sponsor Learn more about GitHub Sponsors Packages 0 No packages published Used by 108 * @qzip * @go-cinch * @BuxOrg * @emarifer * @tengattack * @protosio * @matheusgomes28 * @a-company-jp + 100 Contributors 82 * * * * * * * * * * * * * * + 68 contributors Languages * Go 100.0% * Python 0.0% * Shell 0.0% * Java 0.0% * Makefile 0.0% * C 0.0% Footer (c) 2024 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact * Manage cookies * Do not share my personal information You can't perform that action at this time.