### Minimal Feature Installation Source: https://github.com/blackbeam/mysql_async/blob/master/README.md Install with the 'minimal' feature to enable only necessary components, including a zlib backend for compression. ```toml [dependencies] mysql_async = { version = "*", default-features = false, features = ["minimal"] } ``` -------------------------------- ### Basic Installation Source: https://github.com/blackbeam/mysql_async/blob/master/README.md Add the mysql_async crate to your Cargo.toml file with the desired version. ```toml [dependencies] mysql_async = "" ``` -------------------------------- ### Minimal Rust Backend Installation Source: https://github.com/blackbeam/mysql_async/blob/master/README.md Use the 'minimal-rust' feature for a minimal installation with a Rust-based flate2 backend. ```toml [dependencies] mysql_async = { version = "*", default-features = false, features = ["minimal-rust"] } ``` -------------------------------- ### Full MySQL Async Example Source: https://github.com/blackbeam/mysql_async/blob/master/README.md Demonstrates creating a temporary table, batch inserting data, and loading it back with type inference. Ensure the database URL is correctly configured. ```rust use mysql_async::prelude::*; #[derive(Debug, PartialEq, Eq, Clone)] struct Payment { customer_id: i32, amount: i32, account_name: Option, } #[tokio::main] async fn main() -> Result<()> { let payments = vec![ Payment { customer_id: 1, amount: 2, account_name: None }, Payment { customer_id: 3, amount: 4, account_name: Some("foo".into()) }, Payment { customer_id: 5, amount: 6, account_name: None }, Payment { customer_id: 7, amount: 8, account_name: None }, Payment { customer_id: 9, amount: 10, account_name: Some("bar".into()) }, ]; let database_url = /* ... */ # get_opts(); let pool = mysql_async::Pool::new(database_url); let mut conn = pool.get_conn().await?; // Create a temporary table r"CREATE TEMPORARY TABLE payment ( customer_id int not null, amount int not null, account_name text )".ignore(&mut conn).await?; // Save payments r"INSERT INTO payment (customer_id, amount, account_name) VALUES (:customer_id, :amount, :account_name)" .with(payments.iter().map(|payment| params! { "customer_id" => payment.customer_id, "amount" => payment.amount, "account_name" => payment.account_name.as_ref(), })) .batch(&mut conn) .await?; // Load payments from the database. Type inference will work here. let loaded_payments = "SELECT customer_id, amount, account_name FROM payment" .with(()) .map(&mut conn, |(customer_id, amount, account_name)| Payment { customer_id, amount, account_name }) .await?; // Dropped connection will go to the pool drop(conn); // The Pool must be disconnected explicitly because // it's an asynchronous operation. pool.disconnect().await?; assert_eq!(loaded_payments, payments); // the async fn returns Result, so Ok(()) } ``` -------------------------------- ### Native TLS Installation Source: https://github.com/blackbeam/mysql_async/blob/master/README.md Install the crate with the 'native-tls-tls' feature to enable TLS support using the native-tls library. ```toml [dependencies] mysql_async = { version = "*", default-features = false, features = ["minimal", "native-tls-tls"] } ``` -------------------------------- ### Run MySQL Test Server with Docker Source: https://github.com/blackbeam/mysql_async/blob/master/README.md Use this command to start a MySQL Docker container for testing. Ensure necessary parameters like max allowed packet and binary logging are configured. Mounts the current directory to /root inside the container. ```sh docker run -d --name container \ -v `pwd`:/root \ -p 3307:3306 \ -e MYSQL_ROOT_PASSWORD=password \ mysql:8.0 \ --max-allowed-packet=36700160 \ --local-infile \ --log-bin=mysql-bin \ --log-slave-updates \ --gtid_mode=ON \ --enforce_gtid_consistency=ON \ --server-id=1 ``` -------------------------------- ### Rustls TLS Installation with Ring Provider Source: https://github.com/blackbeam/mysql_async/blob/master/README.md Enable rustls TLS backend with the 'ring' provider by specifying 'rustls-tls' and 'ring' features. ```toml [dependencies] mysql_async = { version = "*", default-features = false, features = ["minimal-rust", "rustls-tls", "ring"] } ``` -------------------------------- ### Setup LOCAL INFILE Handler and Load Data Source: https://github.com/blackbeam/mysql_async/blob/master/README.md Demonstrates setting up a one-time local infile handler for LOAD DATA LOCAL operations. This handler provides data as a stream of Bytes. It also includes error handling for common MySQL errors related to this command. ```rust let pool = mysql_async::Pool::new(database_url); let mut conn = pool.get_conn().await?; "CREATE TEMPORARY TABLE tmp (id INT, val TEXT)".ignore(&mut conn).await?; // We are going to call `LOAD DATA LOCAL` so let's setup a one-time handler. conn.set_infile_handler(async move { // We need to return a stream of `io::Result` Ok(stream::iter([Bytes::from("1,a\r\n"), Bytes::from("2,b\r\n3,c")]).map(Ok).boxed()) }); let result = r#"LOAD DATA LOCAL INFILE 'whatever'\n INTO TABLE `tmp`\n FIELDS TERMINATED BY ',' ENCLOSED BY '"'\n LINES TERMINATED BY '\r\n'"#.ignore(&mut conn).await; match result { Ok(()) => (), Err(Error::Server(ref err)) if err.code == 1148 => { // The used command is not allowed with this MySQL version return Ok(()) }, Err(Error::Server(ref err)) if err.code == 3948 => { // Loading local data is disabled; // this must be enabled on both the client and the server return Ok(()) } e @ Err(_) => e.unwrap(), } // Now let's verify the result let result: Vec<(u32, String)> = conn.query("SELECT * FROM tmp ORDER BY id ASC").await?; assert_eq!( result, vec![(1, "a".into()), (2, "b".into()), (3, "c".into())] ); drop(conn); pool.disconnect().await?; ``` -------------------------------- ### Binlog Feature Source: https://github.com/blackbeam/mysql_async/blob/master/README.md Enable the 'binlog' feature to include binlog-related functionality, which also enables the 'binlog' feature in the mysql_common crate. ```toml [dependencies] mysql_async = { version = "*", features = ["binlog"] } ``` -------------------------------- ### Tracing Instrumentation Source: https://github.com/blackbeam/mysql_async/blob/master/README.md Enable the 'tracing' feature to add instrumentation for monitoring operations at various levels. ```toml [dependencies] mysql_async = { version = "*", features = ["tracing"] } ``` -------------------------------- ### Default Features with Rustls TLS (Ring Provider) Source: https://github.com/blackbeam/mysql_async/blob/master/README.md Configure default features with TLS support via rustls, specifically using the 'ring' provider. ```toml [dependencies] mysql_async = { version = "*", default-features = false, features = ["default-rustls-ring"] } ``` -------------------------------- ### Default Features with Rustls TLS Source: https://github.com/blackbeam/mysql_async/blob/master/README.md Enable default features along with TLS support provided by rustls (using aws-lc-rs). ```toml [dependencies] mysql_async = { version = "*", default-features = false, features = ["default-rustls"] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.