Databases 4 min read

Essential MySQL Commands Cheat Sheet: Manage Databases, Tables, Users & More

This guide provides a comprehensive collection of essential MySQL commands covering database creation, table schema management, data manipulation, user permissions, performance monitoring, and backup/restore procedures, offering a practical reference for developers and administrators.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Essential MySQL Commands Cheat Sheet: Manage Databases, Tables, Users & More

Database Management

Commands to view, create, delete, and switch databases.

SHOW DATABASES;
CREATE DATABASE shop_db;
DROP DATABASE test_db;
USE shop_db;
SHOW TABLES;
SHOW CREATE DATABASE shop_db;
ALTER DATABASE shop_db CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
SELECT DATABASE();

Table Structure Management

Commands to create, drop, describe tables and modify schema.

CREATE TABLE users (
    id INT PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR(50),
    age INT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
DROP TABLE users;
DESC users;
SHOW CREATE TABLE users;
ALTER TABLE users ADD email VARCHAR(100);
ALTER TABLE users DROP COLUMN age;
RENAME TABLE users TO user_info;

Data Operations

Insert, query, update, delete and truncate data.

INSERT INTO users (name, age, email) VALUES ('Alice', 25, '[email protected]');
SELECT * FROM users;
UPDATE users SET age = 30 WHERE name = 'Alice';
DELETE FROM users WHERE id = 3;
TRUNCATE TABLE users;
SELECT * FROM users LIMIT 5;
SELECT * FROM users ORDER BY age DESC;

User and Permission Management

Create users, grant privileges, view grants and drop users.

CREATE USER 'dev_user'@'localhost' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON shop_db.* TO 'dev_user'@'localhost';
SHOW GRANTS FOR 'dev_user'@'localhost';
DROP USER 'dev_user'@'localhost';

Performance Monitoring

Inspect running queries, thread status and configuration variables.

SHOW PROCESSLIST;
SHOW STATUS LIKE 'Threads%';
SHOW VARIABLES LIKE 'max_connections';

Backup and Restore

Export and import databases using mysqldump and mysql.

mysqldump -u root -p shop_db > /backup/shop_db.sql
mysql -u root -p shop_db < /backup/shop_db.sql
SHOW BINARY LOGS;
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

SQLdatabasePerformance MonitoringmysqlBackupUser Managementcommands
Mike Chen's Internet Architecture
Written by

Mike Chen's Internet Architecture

Over ten years of BAT architecture experience, shared generously!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.