10 Essential MySQL Development Rules Every DBA and Developer Should Follow
This article outlines ten practical MySQL development guidelines—from using InnoDB tables and simple data types to avoiding SELECT * and unnecessary ENUMs—helping DBAs and developers collaborate more efficiently and write cleaner, faster SQL.
1. Use InnoDB storage engine for tables
Since MySQL 8.0 the MyISAM engine is deprecated; every table should use InnoDB and include an auto‑increment primary key ID.
2. Choose simple, small data types
Prefer
intfor IPv4 addresses (convert with functions) and store monetary values as integers in cents. Use
datetimeinstead of
timestampfor a larger range and smaller storage (5 bytes).
<code>mysql> select inet_aton('192.168.56.132');
+-----------------------------+
| inet_aton('192.168.56.132') |
+-----------------------------+
| 3232249988 |
+-----------------------------+
mysql> select inet_ntoa(3232249988);
+-----------------------+
| inet_ntoa(3232249988) |
+-----------------------+
| 192.168.56.132 |
+-----------------------+
1 row in set (0.00 sec)</code>3. Use lowercase names with underscores
Database, table, and column names should be lowercase and separated by underscores; set
lower_case_table_namesto 1 for case‑insensitive storage.
4. Avoid ENUM and large text/blob columns
Replace
ENUMwith
TINYINTand keep
TEXT/
BLOBout of business tables unless absolutely necessary.
5. Use UTF‑8 (or UTF‑8 mb4) character set
UTF‑8 is more universal than GBK or latin1; switch to
utf8mb4when you need to store emojis.
6. Select only required columns, avoid SELECT *
Fetching specific columns reduces bandwidth and can enable covering indexes.
7. Define columns as NOT NULL by default
Non‑null columns make
COUNT()results more accurate because NULL values are excluded.
8. Do not index low‑cardinality columns
Columns like
sexor
statushave low selectivity; generally keep the number of indexes per table under 4‑5.
9. Minimize use of OR and prefer UNION ALL
Let the application handle logical branching instead of the database, and use
UNION ALLto avoid costly deduplication.
10. Continuously monitor production SQL
Use tools such as Percona Toolkit to capture and analyze live queries.
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.