- Enabling query caching, optimizing the query.
explain
Yourselect
queries, which can help you analyze performance bottlenecks in your query or table structure.EXPLAIN
The results will also tell you your index primary key is how to use, how your table is searched and sorted.- When using a single line of data
limit 1
,MySQL
the database engine will stop the search after finding a piece of data, rather than continue to check back next line with less data record. - Indexed for the search field.
- Use
ENUM
insteadVARCHAR
. If you have a field, such as "sex", "state" or "Department", you know the values of these fields is limited and fixed, then you should useENUM
insteadVARCHAR。
Prepared Statements
, Precompiled statementPrepared Statements
like stored procedures, run in the background of aSQL
set of statements, we can use from theprepared statements
get a lot of benefits, whether it is performance problems or security issues.Prepared Statements
You can check some good bind variables, so you can protect your program will not be "SQL
injection" attack.- Vertical table;
- According to business needs, choose the right storage engine.
Transfer: https://xushanxiang.com/2019/11/mysql-optimization-tips.html