Connecting from an application
The two ways an application reaches Raft DB (a stock MySQL or MariaDB driver, or a Raft DB connector) and what was verified with which driver.
There are two routes.
| Route | Use it when | Port |
|---|---|---|
A stock MySQL or MariaDB driver talking to raftdb-mysql | The application already speaks MySQL or MariaDB (PHP, Python, Node, Java, .NET, Go, Ruby, ORMs, tools). Nothing changes in the application except the host and port. | listen of raftdb-mysql (default 3307) |
A Raft DB connector talking to raftdb-server | You want the JSON-native API: documents, filters, strict schemas, the binary protocol. | addr of raftdb-server (default 7480) |
The connectors have their own chapter: connectors. The connector packages on the Download page have a library for C, C++, C#, Dart, Elixir, Go, Java, Lua, Node, OCaml, Perl, PHP, Python, R, Ruby and Rust. The rule for a connector is that all of its 24 conformance scenarios pass against a running Raft DB server before it ships.
A stock driver#
Use the host and port of raftdb-mysql, the user and password of a user = line (or a CREATE USER account), and, unless you configured TLS on the front-end, no TLS.
| Driver | Connection string |
|---|---|
| MySQL Connector/J | jdbc:mysql://127.0.0.1:3307/shop?useSSL=false |
| MariaDB Connector/J | jdbc:mariadb://127.0.0.1:3308/shop (against the dialect = mariadb process) |
PHP mysqli | new mysqli('127.0.0.1', 'app', 'secret', 'shop', 3307) |
Python (mysql-connector, PyMySQL) | host 127.0.0.1, port 3307, user, password, database shop |
What was verified with real drivers (from the decision log):
- MySQL Connector/J: a prepared-statement test program (binary protocol, batches, generated keys, long data, typed getters, error cases) gives output identical to MySQL 9.7; a metadata test program (
DatabaseMetaDataas ORMs use it) is identical for the catalog calls. - MariaDB Connector/J 3.5: a probe program run against real MariaDB and Raft DB; MariaDB's driver detects MariaDB by the word in the version string and sends
set sql_mode=...,NAMES utf8mb4on connect, both of whichraftdb-mysqlhandles. - Applications: the decision log records WordPress, PrestaShop, phpMyAdmin and SQLyog being run against Raft DB and compared with real MySQL (D60, D61), and a 15 MB application dump loading and round-tripping (D64). The comparisons are not a promise that every version of every application works.
Things an application must know:
| Topic | What to do |
|---|---|
| Transactions | They are atomic and isolated one table at a time (READ-COMMITTED: a session that writes a table holds it until the end). Do not rely on SELECT ... FOR UPDATE to serialise access: it locks nothing of its own. |
| Connection pool | Up to max_connections (500) sessions. Each session can hold several connections to the server in the two-process mode; see Resource use and tuning. |
| Character set | Send UTF-8. Text that is not valid UTF-8 in a COM_QUERY is refused with error 1366; send binary data as hexadecimal or _binary literals, or as prepared-statement parameters. |
| Unsupported statements | They fail with error 1235 and the name of the feature; see What is not there yet. |
| TLS | Configure ssl_cert / ssl_key on the front-end and require it in the driver (sslMode=REQUIRED or VERIFY_CA). Without TLS on the front-end, switch it off in the driver (useSSL=false, --skip-ssl, ssl-mode=DISABLED) and use a tunnel across untrusted networks. |
SQL Server and PostgreSQL drivers#
An application written for SQL Server connects with its usual driver (ODBC, JDBC, .NET SqlClient, pyodbc, node-mssql) to port 1433, and one written for PostgreSQL connects with its usual driver (libpq, JDBC, psycopg, node-postgres, Npgsql) to port 5432. As with MySQL, only the host, port and account change. See the SQL Server and PostgreSQL chapters for what is supported.
The native API#
A connector holds a connection to raftdb-server and logs in with NAME and PASSWORD (an account given by --user), a shared token, or nothing on an open server. The Rust reference client is raftdb-client. The native API chapter describes requests, filters and errors: native API.