{"id":13461482,"url":"https://github.com/dolthub/go-mysql-server","last_synced_at":"2025-05-13T17:13:58.682Z","repository":{"id":36978681,"uuid":"193784341","full_name":"dolthub/go-mysql-server","owner":"dolthub","description":"A MySQL-compatible relational database with a storage agnostic query engine. Implemented in pure Go.","archived":false,"fork":false,"pushed_at":"2025-05-12T07:19:55.000Z","size":64053,"stargazers_count":2439,"open_issues_count":34,"forks_count":222,"subscribers_count":22,"default_branch":"main","last_synced_at":"2025-05-12T08:42:00.197Z","etag":null,"topics":["database","mysql","mysql-server","query-engine","relational-database","sql","sql-engine","sql-server"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dolthub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":"SUPPORTED_CLIENTS.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"dolthub"}},"created_at":"2019-06-25T21:15:20.000Z","updated_at":"2025-05-12T07:19:55.000Z","dependencies_parsed_at":"2023-09-22T02:20:36.678Z","dependency_job_id":"55872066-4ddd-4e93-8bf4-4135bcdf8013","html_url":"https://github.com/dolthub/go-mysql-server","commit_stats":{"total_commits":8129,"total_committers":120,"mean_commits":67.74166666666666,"dds":0.8232254889900357,"last_synced_commit":"63e9bc2e8e5217031f49881cd89e7a4006a1feff"},"previous_names":["liquidata-inc/go-mysql-server"],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dolthub%2Fgo-mysql-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dolthub%2Fgo-mysql-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dolthub%2Fgo-mysql-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dolthub%2Fgo-mysql-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dolthub","download_url":"https://codeload.github.com/dolthub/go-mysql-server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253990498,"owners_count":21995776,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","mysql","mysql-server","query-engine","relational-database","sql","sql-engine","sql-server"],"created_at":"2024-07-31T11:00:40.280Z","updated_at":"2025-05-13T17:13:53.667Z","avatar_url":"https://github.com/dolthub.png","language":"Go","funding_links":["https://github.com/sponsors/dolthub"],"categories":["Go","开源类库","Open source library","database","\u003ca name=\"Go\"\u003e\u003c/a\u003eGo"],"sub_categories":["数据库","Database"],"readme":"\u003cimg height=\"240\" src=\"./mascot.png\"/\u003e\n\n# A MySQL compatible database engine written in pure Go\n\n**go-mysql-server** is a data-source agnostic SQL engine and server\nwhich runs queries on data sources you provide, using the MySQL\ndialect and wire protocol. A simple in-memory database implementation\nis included, and you can query any data source you want by\nimplementing your own backend.\n\n[Dolt](https://www.doltdb.com), a SQL database with Git-style\nversioning, is the main production database implementation of this\npackage.  [Check\nout](https://docs.dolthub.com/introduction/what-is-dolt) that project\nfor a reference implementation. Or, hop into the Dolt Discord server\n[here](https://discord.com/invite/RFwfYpu) if you want to talk to the\n[core developers](https://www.dolthub.com/team) behind\n**go-mysql-server** and Dolt.\n\n## Compatibility\n\nWith the exception of specific limitations (see below),\n**go-mysql-server** is a drop-in replacement for MySQL. Any client\nlibrary, tool, query, SQL syntax, SQL function, etc. that works with\nMySQL should also work with **go-mysql-server**. If you find a gap in\nfunctionality, please file an issue.\n\nFor full MySQL compatibility documentation, see the [Dolt\ndocs](https://docs.dolthub.com/sql-reference/sql-support) on this\ntopic.\n\n## Scope of this project\n\n- SQL server and engine to query your data sources.\n- In-memory database backend implementation suitable for use in tests.\n- Interfaces you can use to implement new backends to query your own\n  data sources.\n- With a few caveats and using a full database implementation, a\n  drop-in MySQL database replacement.\n\n**go-mysql-server** has two primary uses case:\n\n1. Stand-in for MySQL in a golang test environment, using the built-in\n   `memory` database implementation.\n\n2. Providing access to arbitrary data sources with SQL queries by\n   implementing a handful of interfaces. The most complete real-world\n   implementation is [Dolt](https://github.com/dolthub/dolt).\n\n## Installation\n\nAdd **go-mysql-server** as a dependency to your project. In the\ndirectory with the `go.mod` file, run:\n\n```\ngo get github.com/dolthub/go-mysql-server@latest\n```\n\n## Using the in-memory test server\n\nThe in-memory test server can replace a real MySQL server in\ntests. Start the server using the code in the [_example\ndirectory](_example/main.go), also reproduced below.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/dolthub/vitess/go/vt/proto/query\"\n\n\tsqle \"github.com/dolthub/go-mysql-server\"\n\t\"github.com/dolthub/go-mysql-server/memory\"\n\t\"github.com/dolthub/go-mysql-server/server\"\n\t\"github.com/dolthub/go-mysql-server/sql\"\n\t\"github.com/dolthub/go-mysql-server/sql/types\"\n)\n\n// This is an example of how to implement a MySQL server.\n// After running the example, you may connect to it using the following:\n//\n// \u003e mysql --host=localhost --port=3306 --user=root mydb --execute=\"SELECT * FROM mytable;\"\n// +----------+-------------------+-------------------------------+----------------------------+\n// | name     | email             | phone_numbers                 | created_at                 |\n// +----------+-------------------+-------------------------------+----------------------------+\n// | Jane Deo | janedeo@gmail.com | [\"556-565-566\",\"777-777-777\"] | 2022-11-01 12:00:00.000001 |\n// | Jane Doe | jane@doe.com      | []                            | 2022-11-01 12:00:00.000001 |\n// | John Doe | john@doe.com      | [\"555-555-555\"]               | 2022-11-01 12:00:00.000001 |\n// | John Doe | johnalt@doe.com   | []                            | 2022-11-01 12:00:00.000001 |\n// +----------+-------------------+-------------------------------+----------------------------+\n//\n// The included MySQL client is used in this example, however any MySQL-compatible client will work.\n\nvar (\n\tdbName    = \"mydb\"\n\ttableName = \"mytable\"\n\taddress   = \"localhost\"\n\tport      = 3306\n)\n\nfunc main() {\n\tpro := createTestDatabase()\n\tengine := sqle.NewDefault(pro)\n\n\tsession := memory.NewSession(sql.NewBaseSession(), pro)\n\tctx := sql.NewContext(context.Background(), sql.WithSession(session))\n\tctx.SetCurrentDatabase(dbName)\n\n\t// This variable may be found in the \"users_example.go\" file. Please refer to that file for a walkthrough on how to\n\t// set up the \"mysql\" database to allow user creation and user checking when establishing connections. This is set\n\t// to false for this example, but feel free to play around with it and see how it works.\n\tif enableUsers {\n\t\tif err := enableUserAccounts(ctx, engine); err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t}\n\n\tconfig := server.Config{\n\t\tProtocol: \"tcp\",\n\t\tAddress:  fmt.Sprintf(\"%s:%d\", address, port),\n\t}\n\ts, err := server.NewServer(config, engine, memory.NewSessionBuilder(pro), nil)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tif err = s.Start(); err != nil {\n\t\tpanic(err)\n\t}\n}\n\nfunc createTestDatabase() *memory.DbProvider {\n\tdb := memory.NewDatabase(dbName)\n\tdb.BaseDatabase.EnablePrimaryKeyIndexes()\n\n\tpro := memory.NewDBProvider(db)\n\tsession := memory.NewSession(sql.NewBaseSession(), pro)\n\tctx := sql.NewContext(context.Background(), sql.WithSession(session))\n\n\ttable := memory.NewTable(db, tableName, sql.NewPrimaryKeySchema(sql.Schema{\n\t\t{Name: \"name\", Type: types.Text, Nullable: false, Source: tableName, PrimaryKey: true},\n\t\t{Name: \"email\", Type: types.Text, Nullable: false, Source: tableName, PrimaryKey: true},\n\t\t{Name: \"phone_numbers\", Type: types.JSON, Nullable: false, Source: tableName},\n\t\t{Name: \"created_at\", Type: types.MustCreateDatetimeType(query.Type_DATETIME, 6), Nullable: false, Source: tableName},\n\t}), db.GetForeignKeyCollection())\n\tdb.AddTable(tableName, table)\n\n\tcreationTime := time.Unix(0, 1667304000000001000).UTC()\n\t_ = table.Insert(ctx, sql.NewRow(\"Jane Deo\", \"janedeo@gmail.com\", types.MustJSON(`[\"556-565-566\", \"777-777-777\"]`), creationTime))\n\t_ = table.Insert(ctx, sql.NewRow(\"Jane Doe\", \"jane@doe.com\", types.MustJSON(`[]`), creationTime))\n\t_ = table.Insert(ctx, sql.NewRow(\"John Doe\", \"john@doe.com\", types.MustJSON(`[\"555-555-555\"]`), creationTime))\n\t_ = table.Insert(ctx, sql.NewRow(\"John Doe\", \"johnalt@doe.com\", types.MustJSON(`[]`), creationTime))\n\n\treturn pro\n}\n```\n\nThis example populates the database by creating `memory.Database` and\n`memory.Table` objects via golang code, but you can also populate it\nby issuing `CREATE DATABASE`, `CREATE TABLE`, etc. statements to the\nserver once it's running.\n\nOnce the server is running, connect with any MySQL client, including\nthe golang MySQL connector and the `mysql` shell.\n\n```bash\n\u003e mysql --host=localhost --port=3306 --user=root mydb --execute=\"SELECT * FROM mytable;\"\n+----------+-------------------+-------------------------------+----------------------------+\n| name     | email             | phone_numbers                 | created_at                 |\n+----------+-------------------+-------------------------------+----------------------------+\n| Jane Deo | janedeo@gmail.com | [\"556-565-566\",\"777-777-777\"] | 2022-11-01 12:00:00.000001 |\n| Jane Doe | jane@doe.com      | []                            | 2022-11-01 12:00:00.000001 |\n| John Doe | john@doe.com      | [\"555-555-555\"]               | 2022-11-01 12:00:00.000001 |\n| John Doe | johnalt@doe.com   | []                            | 2022-11-01 12:00:00.000001 |\n+----------+-------------------+-------------------------------+----------------------------+\n```\n\n## Limitations of the in-memory database implementation\n\nThe in-memory database implementation included with this package is\nintended for use in tests. It has specific limitations that we know\nof:\n\n- [Not\n  threadsafe](https://github.com/dolthub/go-mysql-server/issues/1306). To\n  avoid concurrency issues, limit DDL and DML statements (`CREATE\n  TABLE`, `INSERT`, etc.) to a single goroutine.\n- [No transaction\n  support](https://github.com/dolthub/go-mysql-server/issues/1506). Statements\n  like `START TRANSACTION`, `ROLLBACK`, and `COMMIT` are no-ops.\n- [Non-performant index\n  implementation](https://github.com/dolthub/go-mysql-server/issues/1347). Indexed\n  lookups and joins perform full table scans on the underlying tables.\n\n## Custom backend implementations\n\nYou can create your own backend to query your own data sources by\nimplementing some interfaces. For detailed instructions, see the\n[backend guide](./BACKEND.md).\n\n## Technical documentation for contributors and backend developers\n\n- [Architecture](./ARCHITECTURE.md) is an overview of the various\n  packages of the project and how they fit together.\n- [Contribution guide](./CONTRIBUTING.md) for new contributors,\n  including instructions for how to get your PR merged.\n\n## Powered by go-mysql-server\n\n* [dolt](https://github.com/dolthub/dolt)\n* [gitbase](https://github.com/src-d/gitbase) (defunct)\n\nAre you building a database backend using **go-mysql-server**? We\nwould like to hear from you and include you in this list.\n\n## Security Policy\n\n[go-mysql-server's security\npolicy](https://github.com/dolthub/go-mysql-server/blob/main/SECURITY.md) is\nmaintained in this repository. Please follow the disclosure instructions there.\nPlease do not initially report security issues in this repository's public\nGitHub issues.\n\n## Acknowledgements\n\n**go-mysql-server** was originally developed by the `{source-d}`\norganzation, and this repository was originally forked from\n[src-d](https://github.com/src-d/go-mysql-server). We want to thank\nthe entire `{source-d}` development team for their work on this\nproject, especially Miguel Molina (@erizocosmico) and Juanjo Álvarez\nMartinez (@juanjux).\n\n## License\n\nApache License 2.0, see [LICENSE](/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdolthub%2Fgo-mysql-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdolthub%2Fgo-mysql-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdolthub%2Fgo-mysql-server/lists"}