You will never remember every statement. Good developers know where to look.
1. The built-in HELP command
The mysql client can show the syntax of any statement:
HELP 'SELECT';
Name: 'SELECT'
Description:
Syntax:
SELECT
[ALL | DISTINCT | DISTINCTROW ]
...
HELP contents shows a topic list. This works offline, but the descriptions can be short, and it needs the help tables to be loaded on the server.
2. Ask the server about itself
MySQL describes its own contents. This is more reliable than memory.
CREATE TABLE books (id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(100) NOT NULL, price DECIMAL(6,2));
SHOW CREATE TABLE books\G
*************************** 1. row ***************************
Table: books
Create Table: CREATE TABLE `books` (
`id` int NOT NULL AUTO_INCREMENT,
`title` varchar(100) NOT NULL,
`price` decimal(6,2) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
| Command | Shows |
|---|---|
SHOW DATABASES; | All databases you may see |
SHOW TABLES; | Tables of the current database |
DESCRIBE books; | Columns of a table |
SHOW CREATE TABLE books; | The exact statement that rebuilds the table |
SHOW INDEX FROM books; | Indexes |
SHOW VARIABLES LIKE 'sql_mode'; | A server setting |
SHOW STATUS LIKE 'Threads%'; | Server counters |
SELECT table_name, engine FROM information_schema.tables WHERE table_schema = 'learn';
+------------+--------+
| TABLE_NAME | ENGINE |
+------------+--------+
| books | InnoDB |
+------------+--------+
1 row in set
INFORMATION_SCHEMA is a set of read-only views, in standard SQL, that describe databases, tables, columns and more. You can use ordinary SELECT on them.
3. The official reference manual
The MySQL Reference Manual at dev.mysql.com/doc is the final answer. Tips:
- Choose your version at the top of the page (8.4, 9.x, or 8.0). The same statement can differ.
- Search the statement name, for example
INSERT statement. - Read the syntax box at the top, then the examples further down.
- In the box,
[ ]means optional,|means “one of”, and...means “can repeat”. - Use the “What’s new” and “Differences from MariaDB” sections when you upgrade or switch servers.
4. Asking for help well
When you ask on a forum or a team chat, give:
- Your MySQL version (
SELECT VERSION();). - The table definition (
SHOW CREATE TABLE). - A few sample rows.
- The exact query, the result you get and the result you expect.
- The full error text, including the number.
A good question has a good answer within minutes. “It does not work” has none.
Build a small test table
learn database and try it. Two minutes of experiment beats ten minutes of guessing.