The situation is this, there is a script, a python script that runs on several servers. on one installed MySql on the other MariaDB.

you need to determine from the script to which database the script is connected.

How can I do that? by request.

ideally using sqlalchemy.

    1 answer 1

    Try using the SHOW VARIABLES LIKE "%version%"; command SHOW VARIABLES LIKE "%version%";

    On mysql, it gives the following result:

     mysql> SHOW VARIABLES LIKE "%version%"; +-------------------------+-------------------------+ | Variable_name | Value | +-------------------------+-------------------------+ | innodb_version | 5.7.13 | | protocol_version | 10 | | slave_type_conversions | | | tls_version | TLSv1,TLSv1.1 | | version | 5.7.13-0ubuntu0.16.04.2 | | version_comment | (Ubuntu) | | version_compile_machine | x86_64 | | version_compile_os | Linux | +-------------------------+-------------------------+ 

    And on mariadb the following:

     MariaDB [(none)]> SHOW VARIABLES LIKE "%version%"; +-------------------------+----------------------------------+ | Variable_name | Value | +-------------------------+----------------------------------+ | innodb_version | 5.6.29-76.2 | | protocol_version | 10 | | slave_type_conversions | | | version | 10.0.25-MariaDB-0ubuntu0.16.04.1 | | version_comment | Ubuntu 16.04 | | version_compile_machine | x86_64 | | version_compile_os | debian-linux-gnu | | version_malloc_library | bundled jemalloc | +-------------------------+----------------------------------+ 

    Accordingly, the difference is that in the version field there is an entry for MariaDB .

    Through sqlalchemy, you can perform a raw query like this:

     result = db.engine.execute("<ваш sql>")