1. Index the WHERE condition after the query operation select and the Sort field
2. On-demand query, which field you need to check which field, prohibit the use of "select *"
3. The database engine is best chosen InnoDB, less with myisam,myisam suitable for more queries, InnoDB suitable for inserting and updating more operations
4. Learn to analyze slow query logs
Show slow query log base information: Show variables like ' slow_query% ';
Show slow query log time: Show global variables like ' long_query_time ';
Turn on slow query log: Set global slow_query_log= ' on ';
Set the slow query log storage location: Set global slow_query_log_file= '/usr/local/mysql/data/slow.log ';
Set the query to record more than 10 seconds: set global long_query_time=1;
In the MySQL configuration file, configure the following:
[Mysqld]
Slow_query_log = On
Slow_query_log_file =/usr/local/mysql/data/slow.log
Long_query_time = 1
5. Learn to analyze Bin-log logs
Writes a log of a specific time period to the development file:
Mysqlbinlog--no-defaults--base64-output=decode-rows-v-v--start-datetime= ' 2018-05-09 09:31:30 '--stop-datetime= ' 2018-05-09 09:33:00 ' mysql-bin.000008 > demo.txt;
6. Querying information for all tables in a particular database that the database storage engine is InnoDB
Show table status from Mmj_main where engine= ' InnoDB ';
7. Modify the table's database storage engine to InnoDB
ALTER TABLE Sdb_freeze_logs ENGINE=INNODB;
MySQL performance optimizations and common commands