在autoTestSchem内只需要定义了如下参数,即可使用Mysql类执行sql语句

  1. # config/test.toml
  2. [test.sql]
  3. host = "172.0.0.1"
  4. user = "root"
  5. password = "xxxx"
  6. port = 3306

config定义说明

入参见:pymysql.Connect,以下截取pymysql.Connect说明**:param** host: Host where the database server is located
**:param** user: Username to log in as
**:param** password: Password to use.
**:param** database: Database to use, None to not use a particular one.
**:param** port: MySQL port to use, default is usually OK. (default: 3306)
**:param** bindaddress: When the client has multiple network interfaces, specify
the interface from which to connect to the host. Argument can be
a hostname or an IP address.
:param unix_socket: Optionally, you can use a unix socket rather than TCP/IP.
:param read_timeout: The timeout for reading from the connection in seconds (default: None - no timeout)
:param write_timeout: The timeout for writing to the connection in seconds (default: None - no timeout)
:param charset: Charset you want to use.
:param sql_mode: Default SQL_MODE to use.
:param read_default_file:
Specifies my.cnf file to read these parameters from under the [client] section.
:param conv:
Conversion dictionary to use instead of the default one.
This is used to provide custom marshalling and unmarshalling of types.
See converters.
:param use_unicode:
Whether or not to default to unicode strings.
This option defaults to true.
:param client_flag: Custom flags to send to MySQL. Find potential values in constants.CLIENT.
:param cursorclass: Custom cursor class to use.
:param init_command: Initial SQL statement to run when connection is established.
:param connect_timeout: Timeout before throwing an exception when connecting.
(default: 10, min: 1, max: 31536000)
:param ssl:
A dict of arguments similar to mysql_ssl_set()’s parameters.
:param ssl_ca: Path to the file that contains a PEM-formatted CA certificate
:param ssl_cert: Path to the file that contains a PEM-formatted client certificate
:param ssl_disabled: A boolean value that disables usage of TLS
:param ssl_key: Path to the file that contains a PEM-formatted private key for the client certificate
:param ssl_verify_cert: Set to true to check the validity of server certificates
:param ssl_verify_identity: Set to true to check the server’s identity
:param read_default_group: Group to read from in the configuration file.
:param autocommit: Autocommit mode. None means use server default. (default: False)
:param local_infile: Boolean to enable the use of LOAD DATA LOCAL command. (default: False)
:param max_allowed_packet: Max size of packet sent to server in bytes. (default: 16MB)
Only used to limit size of “LOAD LOCAL INFILE” data packet smaller than default (16KB).
:param defer_connect: Don’t explicitly connect on construction - wait for connect call.
(default: False)
:param auth_plugin_map: A dict of plugin names to a class that processes that plugin.
The class will take the Connection object as the argument to the constructor.
The class needs an authenticate method taking an authentication packet as
an argument. For the dialog plugin, a prompt(echo, prompt) method can be used
(if no authenticate method) for returning a string from the user. (experimental)
:param server_public_key: SHA256 authentication plugin public key value. (default: None)
:param binary_prefix: Add _binary prefix on bytes and bytearray. (default: False)
:param compress: Not supported
:param named_pipe: Not supported
:param db: DEPRECATED Alias for database.
:param_ passwd: DEPRECATED Alias for password.

See Connection <https://www.python.org/dev/peps/pep-0249/#connection-objects> in the
specification.

使用方式:

  1. class MySql(object):
  2. def excute(self, sql_str, is_excute=False, is_logger=True):
  3. """
  4. 执行sql语句
  5. :param sql_str: 执行命令
  6. :param is_excute: 是否为执行语句
  7. :param is_logger: 是否打印日志
  8. :return: 返回执行结果列表,如[{'a':'2', 'b':'3'}]
  9. """