[−][src]Struct sqlx::MySqlConnection
feature="mysql"
only.An asynchronous connection to a MySql database.
The connection string expected by [Connection::open] should be a MySQL connection string, as documented at https://dev.mysql.com/doc/refman/8.0/en/connecting-using-uri-or-key-value-pairs.html#connecting-using-uri
TLS Support (requires tls
feature)
This connection type supports some of the same flags as the mysql
CLI application for SSL
connections, but they must be specified via the query segment of the connection string
rather than as program arguments.
The same options for --ssl-mode
are supported as the ssl-mode
query parameter:
https://dev.mysql.com/doc/refman/8.0/en/connection-options.html#option_general_ssl-mode
mysql://<user>[:<password>]@<host>[:<port>]/<database>[?ssl-mode=<ssl-mode>[&ssl-ca=<path>]]
where
ssl-mode = DISABLED | PREFERRED | REQUIRED | VERIFY_CA | VERIFY_IDENTITY
path = percent (URL) encoded path on the local machine
If the tls
feature is not enabled, ssl-mode=DISABLED
and ssl-mode=PREFERRED
are no-ops and
ssl-mode=REQUIRED
, ssl-mode=VERIFY_CA
and ssl-mode=VERIFY_IDENTITY
are forbidden
(attempting to connect with these will return an error).
If the tls
feature is enabled, an upgrade to TLS is attempted on every connection by default
(equivalent to ssl-mode=PREFERRED
). If the server does not support TLS (because --ssl=0
was
passed to the server or an invalid certificate or key was used:
https://dev.mysql.com/doc/refman/8.0/en/using-encrypted-connections.html)
then it falls back to an unsecured connection and logs a warning.
Add ssl-mode=REQUIRED
to your connection string to emit an error if the TLS upgrade fails.
However, like with mysql
the server certificate is not checked for validity by default.
Specifying ssl-mode=VERIFY_CA
will cause the TLS upgrade to verify the server's SSL
certificate against a local CA root certificate; this is not the system root certificate
but is instead expected to be specified as a local path with the ssl-ca
query parameter
(percent-encoded so the URL remains valid).
If you're running MySQL locally it might look something like this (for VERIFY_CA
):
mysql://root:password@localhost/my_database?ssl-mode=VERIFY_CA&ssl-ca=%2Fvar%2Flib%2Fmysql%2Fca.pem
%2F
is the percent-encoding for forward slash (/
). In the example we give /var/lib/mysql/ca.pem
as the CA certificate path, which is generated by the MySQL server automatically if
no certificate is manually specified. Note that the path may vary based on the default my.cnf
packaged with MySQL for your Linux distribution. Also note that unlike MySQL, MariaDB does not
generate certificates automatically and they must always be passed in to enable TLS.
If ssl-ca
is not specified or the file cannot be read, then an error is returned.
ssl-ca
implies ssl-mode=VERIFY_CA
so you only actually need to specify the former
but you may prefer having both to be more explicit.
If ssl-mode=VERIFY_IDENTITY
is specified, in addition to checking the certificate as with
ssl-mode=VERIFY_CA
, the hostname in the connection string will be verified
against the hostname in the server certificate, so they must be the same for the TLS
upgrade to succeed. ssl-ca
must still be specified.
Methods
impl MySqlConnection
[src]
pub fn open<T>(
url: T
) -> Pin<Box<dyn Future<Output = Result<MySqlConnection, Error>> + 'static + Send>> where
T: TryInto<Url, Error = Error>,
MySqlConnection: Sized,
[src]
url: T
) -> Pin<Box<dyn Future<Output = Result<MySqlConnection, Error>> + 'static + Send>> where
T: TryInto<Url, Error = Error>,
MySqlConnection: Sized,
please use 'connect' instead
feature="mysql"
only.Trait Implementations
impl Connect for MySqlConnection
[src]
type Connection = MySqlConnection
fn connect<T>(
url: T
) -> Pin<Box<dyn Future<Output = Result<MySqlConnection, Error>> + 'static + Send>> where
T: TryInto<Url, Error = Error>,
MySqlConnection: Sized,
[src]
url: T
) -> Pin<Box<dyn Future<Output = Result<MySqlConnection, Error>> + 'static + Send>> where
T: TryInto<Url, Error = Error>,
MySqlConnection: Sized,
impl Connection for MySqlConnection
[src]
fn close(
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send>>
[src]
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send>>
fn ping(&mut self) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
[src]
impl Executor for MySqlConnection
[src]
type Database = MySql
fn send<'e, 'q>(
&'e mut self,
query: &'q str
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'e + Send>> where
'q: 'e,
[src]
&'e mut self,
query: &'q str
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'e + Send>> where
'q: 'e,
fn execute<'e, 'q>(
&'e mut self,
query: &'q str,
args: MySqlArguments
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + 'e + Send>> where
'q: 'e,
[src]
&'e mut self,
query: &'q str,
args: MySqlArguments
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + 'e + Send>> where
'q: 'e,
fn fetch<'e, 'q>(
&'e mut self,
query: &'q str,
args: MySqlArguments
) -> Pin<Box<dyn Stream<Item = Result<MySqlRow, Error>> + 'e + Send>> where
'q: 'e,
[src]
&'e mut self,
query: &'q str,
args: MySqlArguments
) -> Pin<Box<dyn Stream<Item = Result<MySqlRow, Error>> + 'e + Send>> where
'q: 'e,
fn describe<'e, 'q>(
&'e mut self,
query: &'q str
) -> Pin<Box<dyn Future<Output = Result<Describe<<MySqlConnection as Executor>::Database>, Error>> + 'e + Send>> where
'q: 'e,
[src]
&'e mut self,
query: &'q str
) -> Pin<Box<dyn Future<Output = Result<Describe<<MySqlConnection as Executor>::Database>, Error>> + 'e + Send>> where
'q: 'e,
fn fetch_optional<'e, 'q>(
&'e mut self,
query: &'q str,
args: <Self::Database as Database>::Arguments
) -> Pin<Box<dyn Future<Output = Result<Option<<Self::Database as Database>::Row>, Error>> + 'e + Send>> where
'q: 'e,
[src]
&'e mut self,
query: &'q str,
args: <Self::Database as Database>::Arguments
) -> Pin<Box<dyn Future<Output = Result<Option<<Self::Database as Database>::Row>, Error>> + 'e + Send>> where
'q: 'e,
fn fetch_one<'e, 'q>(
&'e mut self,
query: &'q str,
args: <Self::Database as Database>::Arguments
) -> Pin<Box<dyn Future<Output = Result<<Self::Database as Database>::Row, Error>> + 'e + Send>> where
'q: 'e,
[src]
&'e mut self,
query: &'q str,
args: <Self::Database as Database>::Arguments
) -> Pin<Box<dyn Future<Output = Result<<Self::Database as Database>::Row, Error>> + 'e + Send>> where
'q: 'e,
Auto Trait Implementations
impl RefUnwindSafe for MySqlConnection
impl Send for MySqlConnection
impl Sync for MySqlConnection
impl Unpin for MySqlConnection
impl UnwindSafe for MySqlConnection
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<'_, T, DB> HasSqlType<&'_ T> for DB where
DB: HasSqlType<T>,
T: ?Sized,
[src]
DB: HasSqlType<T>,
T: ?Sized,
impl<T, DB> HasSqlType<Option<T>> for DB where
DB: HasSqlType<T>,
[src]
DB: HasSqlType<T>,
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,