Common Commands Cheat Sheet

MySQL / Redis / Nginx / Docker / K8s / Git / Linux / npm / Vim / Maven / Python / HTTP status codes

📌 For MySQL 8.0+

Service Management

sudoLinux Start MySQL Service
sudo systemctl start mysql
Start the MySQL service with systemd (Linux)
sudoLinux Stop MySQL Service
sudo systemctl stop mysql
Stop the MySQL service
sudoLinux Restart MySQL Service
sudo systemctl restart mysql
Restart the MySQL service
sudoLinux Check MySQL Status
sudo systemctl status mysql
Check whether the MySQL service is running
macOS Start with Homebrew (macOS)
brew services start mysql
Start MySQL via Homebrew on macOS

Backup & Restore

Back Up All Databases
mysqldump -u root -p --all-databases > backup.sql
Export all databases to an SQL file
⚠️ Large backups may take a long time
Back Up a Database
mysqldump -u root -p database_name > db_backup.sql
Export the specified database
Restore a Database
mysql -u root -p database_name < backup.sql
Restore a database from an SQL file
Back Up a Single Table
mysqldump -u root -p database_name table_name > table_backup.sql
Export the data and structure of the specified table

User Management

Create a New User
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
Create a new MySQL user
Grant All Privileges
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';
Grant the user all privileges on all databases
⚠️ Use the least-privilege principle in production
Flush Privileges
FLUSH PRIVILEGES;
Reload the privilege tables to apply changes
Delete a User
DROP USER 'username'@'localhost';
Delete the specified user

Performance Monitoring

View Running Queries
SHOW FULL PROCESSLIST;
Show all current connection queries
Check Slow Query Log
SHOW VARIABLES LIKE 'slow_query_log';
Check whether the slow query log is enabled
View Database Size
SELECT table_schema AS 'Database', ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS 'Size (MB)' FROM information_schema.tables GROUP BY table_schema;
Count the size of each database
📚 More references: MySQL official docs

How to Use

Click a category tab to switch command groups, or use the search box for a fuzzy search. Click the Copy button to copy a command to the clipboard. Commands marked with ⚠️ should be verified in a test environment first, and the <parameter> placeholders in commands should be replaced with real values.

FAQ

Can the commands be copied straight into a terminal?

Yes. Each command has a "Copy" button that copies it to the clipboard. Note, however, that some commands use example formats (placeholders such as <your_password>, <database>), so replace them with real values before running; commands marked ⚠️ (e.g. rm -rf, DROP DATABASE) are risky, so make sure you understand them before running them carefully.

Which tech stacks are covered?

This cheat sheet covers 12 categories of tech stack: MySQL, Redis, Nginx, Docker, Docker Compose, Kubernetes (kubectl), Git, basic Linux commands, npm/npx, the Vim editor, Maven and Python/pip commands, plus common HTTP status codes. Each category is grouped by function and supports cross-category keyword search.

How do I handle the <parameter> placeholders in commands?

Anything wrapped in angle brackets (e.g. <database>, <table>) is a placeholder you need to replace. For example, in the MySQL command `SELECT * FROM <table> WHERE id = <id>;` you should substitute the real table name and ID value. Some parameters are optional (such as --flag options after a command); not every parameter has to be filled in.