Skip to content

MySQL connection creation should not have default behavior #2389

@daiguadaidai

Description

@daiguadaidai

Version: 0.6.2

mysql connection create have default behavior.
default execute

SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION')),time_zone='+00:00',NAMES utf8mb4 COLLATE utf8mb4_unicode_ci

The above settings will change the default behavior of the database, which is undesirable for programmers and DBAs. From the perspective of DBAs, the default parameters of the database are optimized and fixed Programmers only need to use the default one You can customize it if you really need it For example, use after_connect function.

Describe the solution you'd like
You can add new function to provide options Whether to use default behavior.
such as

        let pool = MySqlPoolOptions::new()
            .max_connections(4)
            .min_connections(0)
            .connect_timeout(Duration::from_secs(5))
            .max_lifetime(Duration::from_secs(3600))
            .idle_timeout(Duration::from_secs(600))
            // .after_connect_use_default_behavior(true) // you can add new function, like this
            .after_connect(|conn| {
                Box::pin(async move {
                    let _ = conn
                        .execute("SET time_zone='SYSTEM'; SET system_time_zone='CST'")
                        .await;
                    Ok(())
                })
            })
            .connect("mysql://HH:[email protected]:3306/employees")
            .await?;

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions