{"id":13435009,"url":"https://github.com/mysql-otp/mysql-otp","last_synced_at":"2025-05-14T09:08:59.107Z","repository":{"id":22535829,"uuid":"25876565","full_name":"mysql-otp/mysql-otp","owner":"mysql-otp","description":"MySQL/OTP – MySQL and MariaDB client for Erlang/OTP","archived":false,"fork":false,"pushed_at":"2025-03-16T21:45:21.000Z","size":1096,"stargazers_count":368,"open_issues_count":8,"forks_count":136,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-04-03T19:08:27.278Z","etag":null,"topics":["erlang","mariadb","mysql"],"latest_commit_sha":null,"homepage":"https://mysql-otp.github.io/mysql-otp/","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mysql-otp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-10-28T15:38:08.000Z","updated_at":"2025-03-16T21:45:18.000Z","dependencies_parsed_at":"2024-12-05T02:04:01.368Z","dependency_job_id":"27b39eef-7291-4d30-9729-d14797146318","html_url":"https://github.com/mysql-otp/mysql-otp","commit_stats":{"total_commits":225,"total_committers":31,"mean_commits":7.258064516129032,"dds":0.36,"last_synced_commit":"b97ef3dc1313b2e94ed489f41d735b8e4f769459"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysql-otp%2Fmysql-otp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysql-otp%2Fmysql-otp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysql-otp%2Fmysql-otp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysql-otp%2Fmysql-otp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mysql-otp","download_url":"https://codeload.github.com/mysql-otp/mysql-otp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248334969,"owners_count":21086485,"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":["erlang","mariadb","mysql"],"created_at":"2024-07-31T03:00:30.217Z","updated_at":"2025-04-11T03:27:16.310Z","avatar_url":"https://github.com/mysql-otp.png","language":"Erlang","funding_links":[],"categories":["ORM and Datamapping","数据库客户端"],"sub_categories":[],"readme":"MySQL/OTP\n=========\n\n :link: [Test coverage (EUnit)](//mysql-otp.github.io/mysql-otp/eunit.html)\n :link: [API documentation (EDoc)](//mysql-otp.github.io/mysql-otp/index.html)\n :link: [Hex package](//hex.pm/packages/mysql)\n\nMySQL/OTP is a driver for connecting Erlang/OTP applications to MySQL and\nMariaDB databases. It is a native implementation of the MySQL protocol in\nErlang.\n\nSome of the features:\n\n* Mnesia style transactions:\n  * Nested transactions are implemented using SQL savepoints.\n  * Transactions are automatically retried when deadlocks are detected.\n* Each connection is a gen_server, which makes it compatible with Poolboy (for\n  connection pooling) and ordinary OTP supervisors.\n* SSL.\n* Authentication methods `caching_sha2_password` (default from MySQL 8.0.4) and\n  `mysql_native_password` (default from MySQL 4.1).\n* Parametrized queries using cached unnamed prepared statements\n  ([What?](https://github.com/mysql-otp/mysql-otp/wiki/Parametrized-queries-using-cached-prepared-statements))\n* Slow queries are interrupted without killing the connection (MySQL version\n  ≥ 5.0.0)\n* Implements both protocols: the binary protocol for prepared statements and\n  the text protocol for plain queries.\n\nRequirements:\n\n* Erlang/OTP version 21 or later\n* MySQL database version 4.1 or later or MariaDB\n* GNU Make *or* Rebar or any other tool for building Erlang/OTP applications\n\nSynopsis\n--------\n\n```Erlang\n%% Connect (ssl is optional)\n{ok, Pid} = mysql:start_link([{host, \"localhost\"}, {user, \"foo\"},\n                              {password, \"hello\"}, {database, \"test\"},\n                              {ssl, [{server_name_indication, disable},\n                                     {cacertfile, \"/path/to/ca.pem\"}]}]),\n\n%% Select\n{ok, ColumnNames, Rows} =\n    mysql:query(Pid, \u003c\u003c\"SELECT * FROM mytable WHERE id = ?\"\u003e\u003e, [1]),\n\n%% Manipulate data\nok = mysql:query(Pid, \"INSERT INTO mytable (id, bar) VALUES (?, ?)\", [1, 42]),\n\n%% Separate calls to fetch more info about the last query\nLastInsertId = mysql:insert_id(Pid),\nAffectedRows = mysql:affected_rows(Pid),\nWarningCount = mysql:warning_count(Pid),\n\n%% Mnesia style transaction (nestable)\nResult = mysql:transaction(Pid, fun () -\u003e\n    ok = mysql:query(Pid, \"INSERT INTO mytable (foo) VALUES (1)\"),\n    throw(foo),\n    ok = mysql:query(Pid, \"INSERT INTO mytable (foo) VALUES (1)\")\nend),\ncase Result of\n    {atomic, ResultOfFun} -\u003e\n        io:format(\"Inserted 2 rows.~n\");\n    {aborted, Reason} -\u003e\n        io:format(\"Inserted 0 rows.~n\")\nend,\n\n%% Multiple queries and multiple result sets\n{ok, [{[\u003c\u003c\"foo\"\u003e\u003e], [[42]]}, {[\u003c\u003c\"bar\"\u003e\u003e], [[\u003c\u003c\"baz\"\u003e\u003e]]}]} =\n    mysql:query(Pid, \"SELECT 42 AS foo; SELECT 'baz' AS bar;\"),\n\n%% Graceful timeout handling: SLEEP() returns 1 when interrupted\n{ok, [\u003c\u003c\"SLEEP(5)\"\u003e\u003e], [[1]]} =\n    mysql:query(Pid, \u003c\u003c\"SELECT SLEEP(5)\"\u003e\u003e, 1000),\n\n%% Close the connection\nmysql:stop(Pid).\n```\n\nUsage as a dependency\n---------------------\n\nUsing *erlang.mk*:\n\n    DEPS = mysql\n    dep_mysql = git https://github.com/mysql-otp/mysql-otp 1.9.0\n\nUsing *rebar* (version 2 or 3):\n\n```erlang\n{deps, [\n  {mysql, \".*\", {git, \"https://github.com/mysql-otp/mysql-otp\",\n                {tag, \"1.9.0\"}}}\n]}.\n```\n\nUsing *mix*:\n\n```elixir\n{:mysql, git: \"https://github.com/mysql-otp/mysql-otp\", tag: \"1.9.0\"},\n```\n\nThere's also a Hex package called [mysql](//hex.pm/packages/mysql).\n\nTests\n-----\n\nEUnit tests are executed using `make tests` or `make eunit`.\n\nTo run individual test suites, use `make eunit t=SUITE` where SUITE is one of\n`mysql_encode_tests`, `mysql_protocol_tests`, `mysql_tests`, `ssl_tests` or\n`transaction_tests`.\n\nThe encode and protocol test suites does not require a\nrunning MySQL server on localhost.\n\nTo quickly setup MySQL or MariaDB runing in docker for testing,\nexecute `make tests-prep`, then execute `make tests`.\n\nSet environemt variable `MYSQL_IMAGE=mysql|mariadb` and `MYSQL_VERSION` to pick a flavor.\n\nTo test aginast MySQL or MariaDB running in localhost, follow the below steps:\n\n- Stop MySQL service\n- Generate SSL certificates by running `make -C test/ssl`\n- Copy `test/ssl/server-{cert,key}.pem` to `/etc/mysql/`\n- Copy `test/ssl/ca.pem` to `/etc/mysql/`\n- Change certificate file modes: `sudo chmod -R 660 /etc/mysql/*.pem`\n- Change certificate file owner: `sudo chown mysql:mysql /etc/mysql/*.pem`\n- Append SSL configs: `cat test/ssl/my-ssl.cnf | sudo tee -a /etc/mysql/conf.d/my-ssl.cnf`\n- Start MySQL service\n- Run `sudo ./scripts/init.sh` to prepare for test users.\n  The script connects to the database on localhost as root and creates users.\n  Alternatively, look into the script and perform the steps manually.\n- Run `make tests`.\n\nIf you run `make tests COVER=1` a coverage report will be generated. Open\n`cover/index.html` to see that any lines you have added or modified are covered\nby a test.\n\nContributing\n------------\n\nRun the tests and also dialyzer using `make dialyze`.\n\nLinebreak code to 80 characters per line and follow a coding style similar to\nthat of existing code.\n\nKeep commit messages short and descriptive. Each commit message should describe\nthe purpose of the commit, the feature added or bug fixed, so that the commit\nlog can be used as a comprehensive change log. [CHANGELOG.md](CHANGELOG.md) is\ngenerated from the commit messages.\n\nMaintaining\n-----------\n\nThis is for the project's maintainer(s) only.\n\nTagging a new version:\n\n1. Before tagging, update src/mysql.app.src and README.md with the new version.\n2. Tag and push tags using `git push --tags`.\n3. After tagging a new version:\n  * Update the changelog using `make CHANGELOG.md` and commit it.\n  * Update the online documentation and coverage reports using `make gh-pages`.\n    Then push the gh-pages branch using `git push origin gh-pages`.\n\nUpdating the Hex package (requires Mix):\n\n    make publish-hex\n\nLicense\n-------\n\nGNU Lesser General Public License (LGPL) version 3 or any later version.\nSince the LGPL is a set of additional permissions on top of the GPL, both\nlicense texts are included in the files [COPYING](COPYING) and\n[COPYING.LESSER](COPYING.LESSER) respectively.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmysql-otp%2Fmysql-otp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmysql-otp%2Fmysql-otp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmysql-otp%2Fmysql-otp/lists"}