MySQL 8.4 cheatsheet

MySQL 8.4: Inspecting the database

7 common MySQL 8.4 tasks.

List databases

Show the databases you have access to.

SHOW DATABASES;

Switch database

Make a database the default for the following statements.

USE mydb;

List tables

Show the tables in the current database.

SHOW TABLES;

Describe a table

Show a table's columns, types and keys.

DESCRIBE users;

Show the CREATE TABLE statement

Print the statement that would recreate a table, including indexes and constraints.

SHOW CREATE TABLE users;

List a table's indexes

Show each index and the columns it covers.

SHOW INDEX FROM users;

Check database sizes

Add up data and index sizes for each database, in MB.

SELECT table_schema, ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) AS size_mb FROM information_schema.tables GROUP BY table_schema;

Was this page helpful?