1、connect(参数)
  Connection = Connect(*args, **kwargs)
  Establish a connection to the MySQL database. Accepts several
  arguments:

  host: Host where the database server is located
  user: Username to log in as
  password: Password to use.
  database: Database to use, None to not use a particular one.
  port: MySQL port to use, default is usually OK. (default: 3306)
  bind_address: 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.
  unix_socket: Optionally, you can use a unix socket rather than TCP/IP.
  charset: Charset you want to use.
  sql_mode: Default SQL_MODE to use.
  read_default_file:
  Specifies my.cnf file to read these parameters from under the [client] section.

2、db(数据库连接对象)的方法
  1、db.close():断开连接
  2、db.commit():提交到数据库执行
  3、db.cursor():创建游标
  4、db.rollback():回滚
3、cursor游标对象的方法
  1、execute(SQL命令):执行SQL命令
  2、close():关闭游标对象
  3、fetchone():获取查询结果的第1条数据
  4、fetchmany(n):获取n条数据
  5、fetchall():获取所有的数据
  ##fetchmany(n)和fetchall()得到的结果一定是一个大元组套着小元组((),(),()...)

相关文章:

  • 2021-08-11
  • 2021-09-02
  • 2021-06-05
  • 2021-09-24
  • 2021-12-05
  • 2021-06-23
  • 2021-12-27
猜你喜欢
  • 2022-02-09
  • 2021-07-01
  • 2021-12-01
  • 2021-08-15
  • 2021-05-24
  • 2022-12-23
  • 2021-09-17
相关资源
相似解决方案