Struct sqlx::mysql::MySqlConnectOptions[][src]

pub struct MySqlConnectOptions { /* fields omitted */ }
This is supported on crate feature mysql only.

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

impl MySqlConnectOptions[src]

pub fn new() -> MySqlConnectOptions[src]

Creates a new, default set of options ready for configuration

pub fn host(self, host: &str) -> MySqlConnectOptions[src]

Sets the name of the host to connect to.

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

pub fn port(self, port: u16) -> MySqlConnectOptions[src]

Sets the port to connect to at the server host.

The default port for MySQL is 3306.

pub fn socket(self, path: impl AsRef<Path>) -> MySqlConnectOptions[src]

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

By default set to None.

pub fn username(self, username: &str) -> MySqlConnectOptions[src]

Sets the username to connect as.

pub fn password(self, password: &str) -> MySqlConnectOptions[src]

Sets the password to connect with.

pub fn database(self, database: &str) -> MySqlConnectOptions[src]

Sets the database name.

pub fn ssl_mode(self, mode: MySqlSslMode) -> MySqlConnectOptions[src]

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);

pub fn ssl_ca(self, file_name: impl AsRef<Path>) -> MySqlConnectOptions[src]

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");

pub fn ssl_ca_from_pem(
    self,
    pem_certificate: Vec<u8, Global>
) -> MySqlConnectOptions
[src]

Sets PEM encoded list of trusted SSL Certificate Authorities.

Example

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

pub fn statement_cache_capacity(self, capacity: usize) -> MySqlConnectOptions[src]

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.

pub fn charset(self, charset: &str) -> MySqlConnectOptions[src]

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.

pub fn collation(self, collation: &str) -> MySqlConnectOptions[src]

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

impl Clone for MySqlConnectOptions[src]

impl ConnectOptions for MySqlConnectOptions[src]

type Connection = MySqlConnection

impl Debug for MySqlConnectOptions[src]

impl Default for MySqlConnectOptions[src]

impl From<MySqlConnectOptions> for AnyConnectOptions[src]

impl FromStr for MySqlConnectOptions[src]

type Err = Error

The associated error which can be returned from parsing.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,