36 Strategies of MySQL Operation and Maintenance


Number 1, say important things three times: backup, backup, backup, regular full backup + incremental backup/differential backup, and open binlog
Number 2, if you write Mysql, mySQL, MySql, I don't think MySQL is suitable for you, so use something else
Count 3. If you still insist that MyISAM is better than InnoDB tables, please stop using MySQL
Count 4. It’s not enough to just do a backup, but also to do a recovery test and check the validity of the data
Count 5. The database password must be compliant. A weak password means no password. If you don’t have a password, you will be blackmailed.
Count 6, management users and business users have different rights and roles, and business users must not be authorized too much
Count 7, SLAVE standby database remember to close the write permission (read_only=1)
Count 8. Stored procedures, triggers, and table partitions can be used if you want, and you can use them well. If there are performance bottlenecks, optimization is
The ninth plan, never monitor the public network IP, and use a firewall to block non-external connections to reduce the risk of being invaded
Count 10, InnoDB tables must use self-incrementing columns or columns with incremental attributes as the primary key (the column is preferably without business meaning), which can effectively improve InnoDB table performance and avoid master-slave data replication delays
Count 11. Always create appropriate indexes, otherwise InnoDB row locks will be upgraded to similar table-level locks
12. For columns with low cardinality, it is strongly not recommended to create an index separately (it can be placed in a joint index)
Count 13. In the joint index, the column with high cardinality is placed in the front, and the column with low cardinality is placed in the back
The 14th plan is to ensure that the data will not be lost when the machine is down. Burning incense and worshipping Buddha does not work. It is reliable to set double 1 (innodb_flush_log_at_trx_commit=1 & sync_binlog=1)
Item 15. When writing SQL under the command line, write the WHERE condition first, or write all of them and confirm them before submitting for execution.
Count 16, focus on type=All/Index in EXPLAIN results, or use temporary and Using filesort in Extra and optimize
17. During performance and stress testing, the test machine client must be separated from the server side
18. When the number of connections is full, the maximum number of connections should be lowered instead of higher, and the thread pool should be used as soon as possible
The 19th, SHOW PROCESSLIST results focus on frequently occurring Sending data, Sorting result, Copying to tmp table, Copying to tmp table on disk, Creating sort index, Waiting for xx lock
Count 20. If you don't want MySQL to die quickly, just close the tasteless Query Cache (query_cache_type=0)
21. Autocommit is turned on by default; when a large amount of data needs to be written at one time, autocommit should be turned off, and finally submitted manually
Count 22. Monitor InnoDB table space fragmentation rate: actual size of ibd file/(Data_length+Index_length), and decide whether to reorganize table space
23. One of the environment initialization: turn on the CPU maximum performance mode
Count 24, the second environment initialization: turn off NUMA
Count 25, environment initialization third: use xfs/ext4 file system, and deadline/noop io scheduler
Count 26, mysqld process occupies CPU %user suddenly soars, 99.99% is due to improper indexing
The 27th, priority to solve the slow query with the highest frequency, followed by the slow query during the peak hours of the core business
No. 28, create_time and update_time fields are added to each table, which is very helpful for DB operation and maintenance
Count 29. Add quotation marks to each SQL condition and force type conversion on user input to avoid SQL injection and implicit type conversion risks
Count 30, only SELECT necessary fields, don't always SELECT *, avoid extra I/O reads
Count 31, it is advisable to set innodb_buffer_pool_size to 50%~70% of physical memory
32. Suspected SQL injection will generally call the SLEEP() function, or access the view under information_schema, which will kill you every time you see it
Count 33, do not delete the data table directly, but RENAME first; it is more efficient to delete large tables with hard links
Count 34. Pay special attention to monitoring whether there is a memory leak problem, and eliminate the risk as soon as possible
35. The core goal of optimization is to improve I/O efficiency, whether it is increasing memory, replacing high-performance I/O devices, or improving CPU performance, increasing indexes, etc.
The 36th count, use less large object columns such as TEXT/BLOB, and try not to exceed half of the innodb_data_page_size in bytes of the length of each row



[url]http://www.ywadmin.com [/url]

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326124279&siteId=291194637
Recommended