open static method
Future<MysqlDatabase>
open({
- required String host,
- int port = 3306,
- required String database,
- required String username,
- required String password,
- bool useTls = true,
- SecurityContext? tlsContext,
- bool allowPublicKeyRetrieval = false,
- Duration connectTimeout = const Duration(seconds: 10),
- String collation = 'utf8mb4_general_ci',
- int preparedStatementCacheSize = 32,
Opens and owns one MySQL or MariaDB connection.
TLS is enabled by default and always rejects an invalid certificate. Disable it only for an explicitly trusted transport, such as a local development socket or tunnel.
Implementation
static Future<MysqlDatabase> open({
required String host,
int port = 3306,
required String database,
required String username,
required String password,
bool useTls = true,
SecurityContext? tlsContext,
bool allowPublicKeyRetrieval = false,
Duration connectTimeout = const Duration(seconds: 10),
String collation = 'utf8mb4_general_ci',
int preparedStatementCacheSize = 32,
}) async {
_validateConnectionOptions(
port: port,
connectTimeout: connectTimeout,
collation: collation,
preparedStatementCacheSize: preparedStatementCacheSize,
);
return MysqlDatabase._connection(
await _openConnection(
host: host,
port: port,
database: database,
username: username,
password: password,
useTls: useTls,
tlsContext: tlsContext,
allowPublicKeyRetrieval: allowPublicKeyRetrieval,
connectTimeout: connectTimeout,
collation: collation,
preparedStatementCacheSize: preparedStatementCacheSize,
),
);
}