diff --git a/src/sql/db_connection_pool/mysqlpool.rs b/src/sql/db_connection_pool/mysqlpool.rs index cd5932df..118f4e3a 100644 --- a/src/sql/db_connection_pool/mysqlpool.rs +++ b/src/sql/db_connection_pool/mysqlpool.rs @@ -57,6 +57,13 @@ pub struct MySQLConnectionPool { join_push_down: JoinPushDown, } +const SETUP_QUERIES: [&str; 4] = [ + "SET time_zone = '+00:00'", + "SET character_set_results = 'utf8mb4'", + "SET character_set_client = 'utf8mb4'", + "SET character_set_connection = 'utf8mb4'", +]; + impl MySQLConnectionPool { /// Creates a new instance of `MySQLConnectionPool`. /// @@ -160,6 +167,8 @@ impl MySQLConnectionPool { connection_string = connection_string.ssl_opts(ssl_opts); + connection_string = connection_string.setup(SETUP_QUERIES.to_vec()); + let opts = mysql_async::Opts::from(connection_string); verify_mysql_opts(&opts).await?; @@ -209,13 +218,7 @@ impl MySQLConnectionPool { /// Returns an error if there is a problem creating the connection pool. pub async fn connect_direct(&self) -> super::Result { let pool = Arc::clone(&self.pool); - let mut conn = pool.get_conn().await.context(MySQLConnectionSnafu)?; - - // Set MySQL session default time zone to UTC to match Datafusion - let _: Vec = conn - .exec("SET time_zone = '+00:00'", Params::Empty) - .await - .context(MySQLConnectionSnafu)?; + let conn = pool.get_conn().await.context(MySQLConnectionSnafu)?; Ok(MySQLConnection::new(conn)) } @@ -279,13 +282,7 @@ impl DbConnectionPool for MySQ ) -> super::Result>> { let pool = Arc::clone(&self.pool); - let mut conn = pool.get_conn().await.context(MySQLConnectionSnafu)?; - - // Set MySQL session default time zone to UTC to match Datafusion - let _: Vec = conn - .exec("SET time_zone = '+00:00'", Params::Empty) - .await - .context(MySQLConnectionSnafu)?; + let conn = pool.get_conn().await.context(MySQLConnectionSnafu)?; Ok(Box::new(MySQLConnection::new(conn))) }