pub struct MySqlConnectOptions { /* private fields */ }
Expand description

Options and flags which can be used to configure a MySQL connection.

A value of MySqlConnectOptions can be parsed from a connection URI, as described by MySQL.

The generic format of the connection URL:

mysql://[host][/database][?properties]

Properties

ParameterDefaultDescription
ssl-modePREFERREDDetermines whether or with what priority a secure SSL TCP/IP connection will be negotiated. See MySqlSslMode.
ssl-caNoneSets the name of a file containing a list of trusted SSL Certificate Authorities.
statement-cache-capacity100The maximum number of prepared statements stored in the cache. Set to 0 to disable.
socketNonePath to the unix domain socket, which will be used instead of TCP if set.

Example

// URI connection string
let conn = MySqlConnection::connect("mysql://root:password@localhost/db").await?;

// Manually-constructed options
let conn = MySqlConnectOptions::new()
    .host("localhost")
    .username("root")
    .password("password")
    .database("db")
    .connect().await?;

Implementations

Creates a new, default set of options ready for configuration

Sets the name of the host to connect to.

The default behavior when the host is not specified, is to connect to localhost.

Sets the port to connect to at the server host.

The default port for MySQL is 3306.

Pass a path to a Unix socket. This changes the connection stream from TCP to UDS.

By default set to None.

Sets the username to connect as.

Sets the password to connect with.

Sets the database name.

Sets whether or with what priority a secure SSL TCP/IP connection will be negotiated with the server.

By default, the SSL mode is Preferred, and the client will first attempt an SSL connection but fallback to a non-SSL connection on failure.

Example
let options = MySqlConnectOptions::new()
    .ssl_mode(MySqlSslMode::Required);

Sets the name of a file containing a list of trusted SSL Certificate Authorities.

Example
let options = MySqlConnectOptions::new()
    .ssl_mode(MySqlSslMode::VerifyCa)
    .ssl_ca("path/to/ca.crt");

Sets PEM encoded list of trusted SSL Certificate Authorities.

Example
let options = MySqlConnectOptions::new()
    .ssl_mode(MySqlSslMode::VerifyCa)
    .ssl_ca_from_pem(vec![]);

Sets the capacity of the connection’s statement cache in a number of stored distinct statements. Caching is handled using LRU, meaning when the amount of queries hits the defined limit, the oldest statement will get dropped.

The default cache capacity is 100 statements.

Sets the character set for the connection.

The default character set is utf8mb4. This is supported from MySQL 5.5.3. If you need to connect to an older version, we recommend you to change this to utf8.

Sets the collation for the connection.

The default collation is derived from the charset. Normally, you should only have to set the charset.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Establish a new database connection with the options specified by self.

Log executed statements with the specified level

Log executed statements with a duration above the specified duration at the specified level. Read more

Entirely disables statement logging (both slow and regular).

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Converts to this type from the input type.

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.