Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

sql.mysql.schema

import sql.mysql.schema

sql does not re-export this module, so it is reached only by importing it directly.

Introspection for MySQL, through information_schema.

A schema is a database

MySQL has no layer between the server and a database: what the SQL standard calls a schema is what MySQL calls a database, and information_schema.table_schema holds the database name. So the schema argument every method here takes names a database, and leaving it out means the one the connection is using.

Why nothing is grouped by the server

An index over several columns arrives as one row per column, and the obvious group_concat would gather them server side. It also truncates silently at group_concat_max_len, which is a kilobyte by default, so a wide index would come back missing columns with nothing to say it had. The rows are grouped here instead.

Classes

MySqlSchema

class sql.mysql.schema.MySqlSchema < SchemaAdapter

Answers introspection questions about a MySQL database.

Constructor

sql.mysql.schema.MySqlSchema(connection)

Parameters

  • connection (MySqlConnection)

MySqlSchema.tables()

sql.mysql.schema.MySqlSchema.tables(schema) -> list[string]

The tables the application created.

Parameters

  • schema (string|nil) — The database to look in, or nil for the one in use.

Returns list[string]

MySqlSchema.views()

sql.mysql.schema.MySqlSchema.views(schema) -> list[string]

The views.

Parameters

  • schema (string|nil)

Returns list[string]

MySqlSchema.columns()

sql.mysql.schema.MySqlSchema.columns(table: string, schema) -> list[dict]

The columns of table, in order.

The type is the one the table was declared with, varchar(64) rather than varchar, since on MySQL the width is frequently the part worth knowing.

Parameters

  • table (string)
  • schema (string|nil)

Returns list[dict]

MySqlSchema.primary_key_columns()

sql.mysql.schema.MySqlSchema.primary_key_columns(table: string, schema) -> list[string]

The primary key columns, in key order.

MySQL names every primary key PRIMARY, whatever the table.

Parameters

  • table (string)
  • schema (string|nil)

Returns list[string]

MySqlSchema.indexes()

sql.mysql.schema.MySqlSchema.indexes(table: string, schema) -> list[dict]

The indexes on table, each { name, columns, unique }.

The primary key is among them, under the name MySQL gives it.

Parameters

  • table (string)
  • schema (string|nil)

Returns list[dict]

MySqlSchema.foreign_keys()

sql.mysql.schema.MySqlSchema.foreign_keys(table: string, schema) -> list[dict]

The foreign keys declared on table.

Parameters

  • table (string)
  • schema (string|nil)

Returns list[dict]


2026, Richard Ore and Zuri contributors