{"id":1407,"date":"2024-05-08T10:19:12","date_gmt":"2024-05-08T02:19:12","guid":{"rendered":"http:\/\/oneai.eu.org\/?p=1407"},"modified":"2024-05-08T10:21:23","modified_gmt":"2024-05-08T02:21:23","slug":"mysql%e6%b7%bb%e5%8a%a0%e7%ae%a1%e7%90%86%e5%91%98","status":"publish","type":"post","link":"https:\/\/oneai.eu.org\/?p=1407","title":{"rendered":"mysql\u6027\u80fd\u8c03\u4f18\u5316\u6307\u5357"},"content":{"rendered":"<p>Mysql \u6570\u636e\u5e93\u672c\u8eab\u53c2\u6570\u4f18\u5316\uff1a\uff08my.ini\uff09<br \/>\nMysql \u67e5\u8be2\u7cfb\u7edf\u53d8\u91cf\uff1a<br \/>\nshow variables like \u53d8\u91cf\u540d<br \/>\n\uff1ashow variables like 's_ow_query_log%'<br \/>\n\u53c2\u6570\u4f18\u5316\uff1a<br \/>\ninnodb_buffer_pool_size = Gb\/MB       \/\/\u7f13\u51b2\u533a\u5927\u5c0f\u4e00\u822c\u4e3a\u6574\u673a\u5185\u5b58\u768470~80%<br \/>\ninnodb_buffer_pool_instances=8           \/\/\u5185\u5b58\u7f13\u51b2\u6c60\uff08\u5c06\u4e0a\u9762\u914d\u7f6e\u7684\u5185\u5b58\u5206\u6210\u591a\u5c11\u4efd\uff0c\u9ad8IO\u65f6\uff0c\u9700\u8981\u914d\u7f6e\u591a\u4e2a\uff08\u4e00\u822c\u503c&lt;=CPU\u7684\u4e2a\u6570\uff09\uff0c\u8ba9\u6570\u636e\u7f13\u5b58\u5728\u5185\u5b58\u53ef\u5e76\u53d1\u64cd\u4f5c\uff09<br \/>\nmax_connections = 2000               \/\/\u6700\u5927\u8fde\u63a5\u6570<br \/>\nmax_user_connections=1000        \/\/\u6307\u5b9a\u7684mysql\u7528\u6237\u7684\u6700\u5927\u8fde\u63a5\u6570<br \/>\ninnodb_log_buffer_size =64M       \/\/\u65e5\u5fd7\u7f13\u51b2\u533a\u5927\u5c0f,\u4e00\u822c\u4e0d\u7528\u8bbe\u7f6e\u592a\u5927\uff0c\u80fd\u5b58\u4e0b1\u79d2\u949f\u64cd\u4f5c\u7684\u6570\u636e\u5c31\u884c\u4e86\u3002<br \/>\ninnodb_flush_log_at_trx_commit  \uff08\u8fd9\u4e2a\u5f88\u5173\u952e\uff09\u4e00\u822c\u914d\u7f6e\u4e3a2\uff0c\u53d6\u503c0,1,2<br \/>\n0:\u6570\u636e\u64cd\u4f5c\u65f6\uff0c\u76f4\u63a5\u5199\u5185\u5b58\uff0c\u5e76\u4e0d\u540c\u65f6\u5199\u5165\u78c1\u76d8<br \/>\n2:\u6570\u636e\u64cd\u4f5c\u65f6\uff0c\u76f4\u63a5\u5199\u5185\u5b58\uff0c\u5e76\u4e0d\u540c\u65f6\u5199\u5165\u78c1\u76d8<br \/>\n1:\u5c31\u6bcf\u4e2a\u4e8b\u52a1\u63d0\u4ea4\u5c31\u4f1a\u8981\u5237\u65b0\u5230\u78c1\u76d8\u540e\u624d\u7b97\u63d0\u4ea4\u5b8c\u6210,\u8fd9\u79cd\u60c5\u51b5\u662f\u4fdd\u8bc1\u4e86\u4e8b\u52a1\u7684\u4e00\u81f4\u6027,\u4f46\u6027\u80fd\u4f1a\u6709\u5f88\u5927\u7684\u5f71\u54cd...<br \/>\n0\u4e0e2\u7684\u533a\u522b\uff1a<br \/>\n0\uff1a\u5f53mysql\u6302\u4e86\u4e4b\u540e\uff0c\u53ef\u80fd\u4f1a\u635f\u5931\u524d\u4e00\u79d2\u7684\u4e8b\u52a1\u4fe1\u606f<br \/>\n2\uff1a\u5f53mysql\u6302\u4e86\u4e4b\u540e\uff0c\u5982\u679c\u7cfb\u7edf\u6587\u4ef6\u7cfb\u7edf\u6ca1\u6302\uff0c\u4e0d\u4f1a\u6709\u4e8b\u52a1\u4e22\u5931<br \/>\ninnodb_read_io_threads = 16 \/\/\u8bfbIO\u8fdb\u7a0b\u6570<br \/>\ninnodb_write_io_threads = 16 \/\/\u5199IO\u8fdb\u7a0b\u6570<\/p>\n<p>innodb file per table=\uff080|1\uff09        \/\/\u6bcf\u4e00\u4e2a\u8868\u662f\u5426\u4f7f\u7528\u72ec\u7acb\u7684\u6570\u636e\u8868\u7a7a\u95f4\uff0c\u9ed8\u8ba4\u4e3aOFF\uff08\u4f7f\u7528\u5171\u4eab\u8868\u7a7a\u95f4\uff09\uff0c\u4e00\u822c\u5efa\u8bae\u914d\u7f6e\u4e3a1\u3002<br \/>\n0\uff1a\u5173\u95ed\u72ec\u7acb\u7684\u8868\u7a7a\u95f4<br \/>\n1\uff1a\u6253\u5f00\u72ec\u7acb\u8868\u7a7a\u95f4<br \/>\n\u8bf4\u660e\uff08InnoDB \u9ed8\u8ba4\u4f1a\u5c06\u6240\u6709\u7684\u6570\u636e\u5e93InnoDB\u5f15\u64ce\u7684\u8868\u6570\u636e\u5b58\u50a8\u5728\u4e00\u4e2a\u5171\u4eab\u7a7a\u95f4\u4e2d\uff1aibdata1\uff0c\u8fd9\u6837\u5c31\u611f\u89c9\u4e0d\u723d\uff0c\u589e\u5220\u6570\u636e\u5e93\u7684\u65f6\u5019\uff0cibdata1\u6587\u4ef6\u4e0d\u4f1a\u81ea\u52a8\u6536\u7f29\uff0c<br \/>\n\u5355\u4e2a\u6570\u636e\u5e93\u7684\u5907\u4efd\u4e5f\u5c06\u6210\u4e3a\u95ee\u9898\u3002\u901a\u5e38\u53ea\u80fd\u5c06\u6570\u636e\u4f7f\u7528mysqldump \u5bfc\u51fa\uff0c\u7136\u540e\u518d\u5bfc\u5165\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<br \/>\n\u5171\u4eab\u8868\u7a7a\u95f4\u5728Insert\u64cd\u4f5c\u4e0a\u5c11\u6709\u4f18\u52bf\u3002\u5176\u5b83\u90fd\u6ca1\u72ec\u7acb\u8868\u7a7a\u95f4\u8868\u73b0\u597d\uff09<br \/>\ninnodb_stats_on_metadata=\uff08\uff09 \/\/\u662f\u5426\u52a8\u6001\u5173\u95ed\u7edf\u8ba1\u4fe1\u606f(\u4e00\u822c\u5173\u95ed\uff0c\u627e\u4e2a\u65f6\u95f4\u624b\u52a8\u5237\u65b0\uff0c\u6216\u5b9a\u65f6\u5237\u65b0)<br \/>\ninnodb_purge_batch_size   \/\/---<\/p>\n<p>innodb_purge_threads   \/\/\u6e05\u9664\u64cd\u4f5c\u662f\u5426\u4f7f\u7528\u5355\u72ec\u7684\u7ebf\u7a0b  1:\u662f 0\uff1a\u5426\uff08\u4e0d\u652f\u6301\u52a8\u6001\u4fee\u6539\uff0c \u9700\u8981\u6dfb\u52a0\u5230 my.cnf \u91cc\u4fee\u6539\uff0c\u9700\u8981\u7ed3\u5408 innodb_purge_batch_size \u53c2\u6570\u6765\u4f7f\u7528 \uff0c \u9ed8\u8ba4\u503c\u662f 20\uff0c \u6700<br \/>\n\u5927\u53ef\u8bbe\u7f6e\u4e3a 5000\uff0c \u8fd9\u4e2a\u53c2\u6570\u4e00\u822c\u4e0d\u7528 \u8c03\u6574\uff0c \u4f7f\u7528 \u9ed8\u8ba4\u7684\u5373\u53ef\u3002\uff09<\/p>\n<p>innodb_change_buffering   \/\/\u63a7\u5236\u5220\u9664\u7f13\u51b2\u548c\u65e2\u6709\u63d2\u5165\u7f13\u51b2\u529f\u80fd\uff0c \u9ed8\u8ba4\u662f all\uff0c \u6b64\u53c2\u6570\u652f\u6301\u52a8\u6001\u8bbe\u7f6e<br \/>\nSET GLOBAL innodb_change_buffering = all;<br \/>\ninnodb_spin_wait_delay=10    \/\/\u63a7\u5236CPU\u8f6e\u5faa\u95f4\u9694 \uff08\u53c2\u6570\u7684\u503c\u9ed8\u8ba4\u662f 6\uff0c \u53ef\u52a8\u6001\u8c03\u6574\uff09<\/p>\n<p>innodb_lock_wait_timeout=30     \/\/\u4fee\u6539\u9501\u7684\u8d85\u65f6\u65f6\u95f4  \uff08 \u9ed8\u8ba450 \u79d2\uff09<\/p>\n<p>slow_query_log                   \/\/\u6162\u67e5\u8be2\u65e5\u5fd7\u76d1\u63a7\u5f00\u5173<br \/>\nslow_query_log_file             \/\/\u6162\u67e5\u8be2\u76d1\u63a7\u65e5\u5fd7\u6587\u4ef6<br \/>\nlong_query_time              | 10.000000             \/\/\u6162\u67e5\u8be2\u65f6\u95f4\u8bbe\u7f6e (\u5355\u4f4d\uff1aS)<\/p>\n<p>--------------mysql \u7d22\u5f15\u4f18\u5316--------------<br \/>\n\u67e5\u770b\u7d22\u5f15\u4fe1\u606f\uff1ashow index from tablename;<br \/>\n\u6267\u884c\u8ba1\u5212\uff1a<br \/>\nexplain sql\u8bed\u53e5\uff1a<br \/>\nmysql&gt; explain select <em> from test; \u6216\uff1aexplain select <\/em> from test  \\G;<br \/>\n+----+-------------+-------+------+---------------+------+---------+------+------+-------+<br \/>\n| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra |<br \/>\n+----+-------------+-------+------+---------------+------+---------+------+------+-------+<br \/>\n|  1 | SIMPLE      | test  | ALL  | NULL          | NULL | NULL    | NULL |   82 | NULL  |<br \/>\n+----+-------------+-------+------+---------------+------+---------+------+------+-------+<br \/>\n--\u5b57\u6bb5\u89e3\u91ca\uff1a<br \/>\n\u8f93\u5165 explain select * from customer; \u540e\uff0c\u51fa\u73b0\u4e00\u5f20\u8868\uff0c\u4e2a\u884c\u7684\u610f\u601d\u5982\u4e0b\uff1a<br \/>\ntable\uff0d\u663e\u793a\u6b64\u884c\u6570\u636e\u5c5e\u4e8e\u54ea\u5f20\u8868\uff1b<br \/>\ntype\uff0d\u91cd\u8981\u7684\u4e00\u5217\uff0c\u663e\u793a\u4f7f\u7528\u4e86\u4f55\u79cd\u8fde\u63a5\uff0c\u4ece\u597d\u5230\u5dee\u4f9d\u6b21\u4e3aconst\u3001eq_ref\u3001ref\u3001range\u3001index\u3001all\uff0c\u4e0b\u9762\u4f1a\u8be6\u7ec6\u8bf4\u660e\uff1b<br \/>\ntype\u7684\u63cf\u8ff0\uff1a<br \/>\nsystem\uff0d\u8868\u53ea\u6709\u4e00\u884c\uff0c\u8fd9\u662fconst\u8fde\u63a5\u7c7b\u578b\u7684\u7279\u4f8b\uff1b<br \/>\nconst\uff0d\u8868\u4e2d\u4e00\u4e2a\u8bb0\u5f55\u7684\u6700\u5927\u503c\u80fd\u591f\u5339\u914d\u8fd9\u4e2a\u67e5\u8be2(\u7d22\u5f15\u53ef\u4ee5\u662f\u4e3b\u952e\u6216\u552f\u4e00\u7d22\u5f15)\u3002\u56e0\u4e3a\u53ea\u6709\u4e00\u884c\uff0c\u8fd9\u4e2a\u503c\u5b9e\u9645\u5c31\u662f\u5e38\u6570\uff0c\u56e0\u4e3amysql\u5148\u8bfb\u8fd9\u4e2a\u503c\uff0c\u518d\u628a\u5b83\u5f53\u4f5c\u5e38\u6570\u5bf9\u5f85\uff1b<br \/>\neq_ref\uff0d\u4ece\u524d\u9762\u7684\u8868\u4e2d\uff0c\u5bf9\u6bcf\u4e00\u4e2a\u8bb0\u5f55\u7684\u8054\u5408\u90fd\u4ece\u8868\u4e2d\u8bfb\u53d6\u4e00\u4e2a\u8bb0\u5f55\u3002\u5728\u67e5\u8be2\u4f7f\u7528\u7d22\u5f15\u4e3a\u4e3b\u952e\u6216\u552f\u4e00\u7d22\u5f15\u7684\u5168\u90e8\u65f6\u4f7f\u7528\uff1b<br \/>\nref\uff0d\u53ea\u6709\u4f7f\u7528\u4e86\u4e0d\u662f\u4e3b\u952e\u6216\u552f\u4e00\u7d22\u5f15\u7684\u90e8\u5206\u65f6\u53d1\u751f\u3002\u5bf9\u4e8e\u524d\u9762\u8868\u7684\u6bcf\u4e00\u884c\u8054\u5408\uff0c\u5168\u90e8\u8bb0\u5f55\u90fd\u5c06\u4ece\u8868\u4e2d\u8bfb\u51fa\uff0c\u8fd9\u4e2a\u8fde\u63a5\u7c7b\u578b\u4e25\u91cd\u4f9d\u8d56\u7d22\u5f15\u5339\u914d\u8bb0\u5f55\u7684\u591a\u5c11\uff0d\u8d8a\u5c11\u8d8a\u597d\uff1b<br \/>\nrange\uff0d\u4f7f\u7528\u7d22\u5f15\u8fd4\u56de\u4e00\u4e2a\u8303\u56f4\u4e2d\u7684\u884c\uff0c\u6bd4\u5982\u4f7f\u7528&gt;\u6216&lt;\u67e5\u627e\u65f6\u53d1\u751f\uff1b<br \/>\nindex\uff0d\u8fd9\u4e2a\u8fde\u63a5\u7c7b\u578b\u5bf9\u524d\u9762\u7684\u8868\u4e2d\u7684\u6bcf\u4e00\u4e2a\u8bb0\u5f55\u8054\u5408\u8fdb\u884c\u5b8c\u5168\u626b\u63cf(\u6bd4all\u597d\uff0c\u56e0\u4e3a\u7d22\u5f15\u4e00\u822c\u5c0f\u4e8e\u8868\u6570\u636e)\uff1b<br \/>\nall\uff0d\u8fd9\u4e2a\u8fde\u63a5\u7c7b\u578b\u591a\u524d\u9762\u7684\u8868\u4e2d\u7684\u6bcf\u4e00\u4e2a\u8bb0\u5f55\u8054\u5408\u8fdb\u884c\u5b8c\u5168\u626b\u63cf\uff0c\u8fd9\u4e2a\u6bd4\u8f83\u7cdf\u7cd5\uff0c\u5e94\u8be5\u5c3d\u91cf\u907f\u514d\u3002<\/p>\n<h2>possible_keys\uff0d\u53ef\u4ee5\u5e94\u7528\u5728\u8fd9\u5f20\u8868\u4e2d\u7684\u7d22\u5f15\uff0c\u5982\u679c\u4e3anull\uff0c\u5219\u8868\u793a\u6ca1\u6709\u53ef\u7528\u7d22\u5f15\uff1b<br \/>\nkey\uff0d\u5b9e\u9645\u4f7f\u7528\u7684\u7d22\u5f15\uff0c\u5982\u4e3anull\uff0c\u8868\u793a\u6ca1\u6709\u7528\u5230\u7d22\u5f15\uff1b<br \/>\nkey_len\uff0d\u7d22\u5f15\u7684\u957f\u5ea6\uff0c\u5728\u4e0d\u635f\u5931\u7cbe\u786e\u5ea6\u7684\u60c5\u51b5\u4e0b\uff0c\u8d8a\u77ed\u8d8a\u597d\uff1b<br \/>\nref\uff0d\u663e\u793a\u7d22\u5f15\u7684\u54ea\u4e00\u5217\u88ab\u4f7f\u7528\u4e86\uff0c\u5982\u679c\u53ef\u80fd\u7684\u8bdd\uff0c\u662f\u4e2a\u5e38\u6570\uff1b<br \/>\nrows\uff0d\u8fd4\u56de\u8bf7\u6c42\u6570\u636e\u7684\u884c\u6570\uff1b<br \/>\nextra\uff0d\u5173\u4e8emysql\u5982\u4f55\u89e3\u6790\u67e5\u8be2\u7684\u989d\u5916\u4fe1\u606f\uff0c\u4e0b\u9762\u4f1a\u8be6\u7ec6\u8bf4\u660e\u3002<br \/>\nextra\u884c\u7684\u63cf\u8ff0\uff1a<br \/>\ndistinct\uff0dmysql\u627e\u5230\u4e86\u57df\u884c\u8054\u5408\u5339\u914d\u7684\u884c\uff0c\u5c31\u4e0d\u518d\u641c\u7d22\u4e86\uff1b<br \/>\nnot exists\uff0dmysql\u4f18\u5316\u4e86left join\uff0c\u4e00\u65e6\u627e\u5230\u4e86\u5339\u914dleft join\u7684\u884c\uff0c\u5c31\u4e0d\u518d\u641c\u7d22\u4e86\uff1b<br \/>\nrange checked for each\uff0d\u6ca1\u627e\u5230\u7406\u60f3\u7684\u7d22\u5f15\uff0c\u4e00\u6b21\u5bf9\u4e8e\u4ece\u524d\u9762\u8868\u4e2d\u6765\u7684\u6bcf\u4e00\u4e2a\u884c\u7ec4\u5408\uff1b<br \/>\nrecord(index map: #)\uff0d\u68c0\u67e5\u4f7f\u7528\u54ea\u4e2a\u7d22\u5f15\uff0c\u5e76\u7528\u5b83\u4ece\u8868\u4e2d\u8fd4\u56de\u884c\uff0c\u8fd9\u662f\u4f7f\u7528\u7d22\u5f15\u6700\u6162\u7684\u4e00\u79cd\uff1b<br \/>\nusing filesort\uff0d\u770b\u5230\u8fd9\u4e2a\u5c31\u9700\u8981\u4f18\u5316\u67e5\u8be2\u4e86\uff0cmysql\u9700\u8981\u989d\u5916\u7684\u6b65\u9aa4\u6765\u53d1\u73b0\u5982\u4f55\u5bf9\u8fd4\u56de\u7684\u884c\u6392\u5e8f\u3002\u4ed6\u6839\u636e\u8fde\u63a5\u7c7b\u578b\u4ee5\u53ca\u5b58\u50a8\u6392\u5e8f\u952e\u503c\u548c\u5339\u914d\u6761\u4ef6\u7684\u5168\u90e8\u884c\u7684\u884c\u6307\u9488\u6765\u6392\u5e8f\u5168\u90e8\u884c.<br \/>\nusing index\uff0d\u5217\u6570\u636e\u662f\u4ece\u5355\u4f7f\u7528\u4e86\u7d22\u5f15\u4e2d\u7684\u4fe1\u606f\u800c\u6ca1\u6709\u8bfb\u53d6\u5b9e\u9645\u884c\u7684\u8868\u8fd4\u56de\u7684\uff0c\u8fd9\u53d1\u751f\u5728\u5bf9\u8868\u7684\u5168\u90e8\u7684\u8bf7\u6c42\u5217\u90fd\u662f\u540c\u4e00\u4e2a\u7d22\u5f15\u65f6\uff1b<br \/>\nusing temporary\uff0d\u770b\u5230\u8fd9\u4e2a\u5c31\u9700\u8981\u4f18\u5316\u67e5\u8be2\u4e86\uff0cmysql\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u8868\u6765\u67e5\u8be2\u5b58\u50a8\u7ed3\u679c\uff0c\u8fd9\u901a\u5e38\u53d1\u751f\u5728\u591a\u4e0d\u540c\u7684\u5217\u8868\u8fdb\u884corder by\u65f6\uff0c\u800c\u4e0d\u662fgroup by\uff1b<br \/>\nwhere used\uff0d\u4f7f\u7528\u4e86where\u4ece\u53e5\u6765\u9650\u5236\u54ea\u4e9b\u884c\u5c06\u4e0e\u4e0b\u4e00\u5f20\u8868\u5339\u914d\u6216\u662f\u8fd4\u56de\u7ed9\u7528\u6237\u3002\u5982\u4e0d\u60f3\u8fd4\u56de\u8868\u4e2d\u7528\u7684\u5168\u90e8\u884c\uff0c\u5e76\u8fde\u63a5\u7c7b\u578b\u662fall\u6216index\uff0c\u8fd9\u5c31\u4f1a\u53d1\u751f\uff0c\u4e5f\u53ef\u80fd\u662f\u67e5\u8be2\u6709\u95ee\u9898\u3002<\/h2>\n<h2>SQL\u8bed\u53e5\u4f18\u5316\uff1a\u6ce8\u610fSQL\u8bed\u53e5\u7684\u4e66\u5199\u89c4\u5219\uff0cwhere\u6761\u4ef6\uff0corder by ,group by ,having , in ,like ,jion on,\u8868\u987a\u5e8f\uff0c\u805a\u5408\u51fd\u6570\u7684\u4f7f\u7528\uff0c\u5b50\u67e5\u8be2\u7b49<\/h2>\n<h2>\u7d22\u5f15\u4f18\u5316\uff1a<br \/>\n1\u3002\u662f\u5426\u6709\u65e0\u91cd\u590d\u7d22\u5f15<br \/>\n2\u3002\u7d22\u5f15\u5b57\u6bb5\u7c7b\u578b\uff0c\u987a\u5e8f\u662f\u5426\u5408\u7406<br \/>\n3\u3002\u662f\u5426\u6709\u65e0\u7528\u7d22\u5f15<br \/>\n4\u3002\u7d22\u5f15\u5229\u7528\u7387<\/h2>\n<p>\u8868\u7ed3\u6784\u4f18\u5316\uff1a<br \/>\n1.\u8868\u7684\u5b57\u6bb5\u7c7b\u578b\u662f\u5426\u5408\u7406<br \/>\n2\u3002\u6570\u636e\u662f\u5426\u5197\u4f59<br \/>\n3\u3002\u6839\u636e\u4e1a\u52a1\u89c4\u5219\u5efa\u7acb\u5408\u7406\u7684\u7ea6\u675f<br \/>\n4\u3002\u5efa\u8868\u65f6\uff0c\u5c3d\u91cf\u4f7f\u5b57\u6bb5\u503c\u4e0d\u4e3a\u7a7a(\u52a0not null\u7ea6\u675f)\uff0c\u7d22\u5f15\u5217\u503c\u5c3d\u91cf\u79bb\u6563\uff08\u4e0d\u91cd\u590d\uff09<br \/>\n5\u3002\u4e0d\u5e38\u7528\u7684\u5b57\u6bb5\u5217\u53ef\u9002\u5f53\u8003\u8651\u6298\u5206\u8868<br \/>\n6\u3002\u6570\u636e\u91cf\u8f83\u5927\u7684\u8868\uff0c\u6709\u5b58\u50a8\u65f6\u95f4\uff0cIP\u5730\u5740\u6570\u636e\u65f6\uff0c\u8f6c\u4e3aint ,bigint<\/p>\n<h2>INT\u7c7b\u578b\u7684\u65f6\u95f4\u6570\u636e\u8f6c\u6362\uff1a<br \/>\nUNIX_TIMESTAMP('2015-01-10 12:00:00') \u8f6cint\uff08\u63d2\u5165\u6570\u636e\u65f6\uff09<br \/>\nFROM_UNIXTIME(\u65f6\u95f4\u5b57\u6bb5)     \u53d6\u65f6\u95f4\u5b57\u6bb5\u7684\u503c<br \/>\nIP\u5730\u5740\u6570\u636e\u64cd\u4f5c\u8f6c\u6362\uff1a<br \/>\nINET_ATON  :IP\u5730\u5740\u8f6cbigint   \uff08inet_aton(192.168.1.1)\uff09<br \/>\nINET_NTOA :BIGINT\u8f6cIP\u5730\u5740\uff08inet_ntoa(ip\u5730\u5740\u5b57\u6bb5)\uff09<br \/>\n---\u5728mysql\u4e2dint ,\u6bd4varchar\u5904\u7406\u8981\u7b80\u5355\uff0c\u5c3d\u91cf\u5c11\u4f7f\u7528text\u7c7b\u578b<\/h2>\n<h2>\u6570\u636e\u5e93\u4e3b\u673a\u53c2\u6570\u4f18\u5316\uff1a<br \/>\n\u7f51\u7edc\uff1a<br \/>\nnet.ipv4.tcp_keepalive_time = 1200 \u8868\u793a\u5f53keepalive\u8d77\u7528\u7684\u65f6\u5019\uff0cTCP\u53d1\u9001keepalive\u6d88\u606f\u7684\u9891\u5ea6\u3002\u7f3a\u7701\u662f2\u5c0f\u65f6\uff0c\u6539\u4e3a20\u5206\u949f\u3002<br \/>\nnet.ipv4.ip_local_port_range = 10000 65000  \u8868\u793a\u7528\u4e8e\u5411\u5916\u8fde\u63a5\u7684\u7aef\u53e3\u8303\u56f4,\u4e00\u822c\u4f4e\u4f4d\u7aef\u53e3\u4e0d\u8981\u8bbe\u7f6e\u592a\u4f4e\uff0c\u6709\u53ef\u80fd\u4f1a\u7528\u5230\u5176\u5b83\u7a0b\u5e8f\u56fa\u5b9a\u7684\u7aef\u53e3<br \/>\nnet.ipv4.tcp_max_syn_backlog = 65535                \u8868\u793aSYN\u961f\u5217\u7684\u957f\u5ea6\uff0c\u9ed8\u8ba4\u4e3a1024\uff0c\u52a0\u5927\u961f\u5217\u957f\u5ea6\u4e3a65535\uff0c\u53ef\u4ee5\u5bb9\u7eb3\u66f4\u591a\u7b49\u5f85\u8fde\u63a5\u7684\u7f51\u7edc\u8fde\u63a5\u6570\u3002<br \/>\nnet.ipv4.tcp_max_tw_buckets = 5000                \u793a\u7cfb\u7edf\u540c\u65f6\u4fdd\u6301TIME_WAIT\u7684\u6700\u5927\u6570\u91cf\uff0c\u5982\u679c\u8d85\u8fc7\u8fd9\u4e2a\u6570\u5b57\uff0cTIME_WAIT\u5c06\u7acb\u523b\u88ab\u6e05\u9664\u5e76\u6253\u5370\u8b66\u544a\u4fe1\u606f\u3002\u9ed8 \u8ba4\u4e3a180000\uff0c\u907f\u514d\u88ab\u5927\u91cf\u7684timewait\u62d6\u6b7b\u3002<br \/>\nnet.ipv4.tcp_syncookies = 1 \u8868\u793a\u5f00\u542fSYN Cookies<br \/>\nnet.ipv4.tcp_tw_reuse=1                         \u8868\u793a\u5f00\u542f\u91cd\u7528,\u5141\u8bb8\u5c06TIME-WAIT sockets\u91cd\u65b0\u7528\u4e8e\u65b0\u7684TCP\u8fde\u63a5<br \/>\nnet.ipv4.tcp_recycle=1                        \u8868\u793a\u5f00\u542fTCP\u8fde\u63a5\u4e2dTIME-WAIT sockets\u7684\u5feb\u901f\u56de\u6536\uff0c\u9ed8\u8ba4\u4e3a0\uff0c\u8868\u793a\u5173\u95ed\uff1b<br \/>\nnet.ipv4.tcp_fin_timeout=10        \u4fee\u6539\u7cfb\u7d71\u9ed8\u8ba4\u7684 TIMEOUT \u65f6\u95f4\u3002<\/h2>\n<h2>limit.conf\u5185\u6838\u76f8\u5173\u53c2\u6570\u4f18\u5316\uff1a<br \/>\n\u8be6\u89c1\u7b14\u8bb0\uff1a\u300alimits.conf\u8be6\u89e3\u300b<\/h2>\n<p>\u8868\u7684\u788e\u7247\u6574\u7406\uff1a<br \/>\n\u67e5\u8be2\uff1ashow table status from \u5e93\u540d where name=\u2018\u8868\u540d\u2019\u4e0d\u52a0where\u6761\u4ef6\uff0c\u8868\u793a\u67e5\u8be2\u6574\u4e2a\u5e93\u6bcf\u4e2a\u8868\u7684\u72b6\u6001<br \/>\n\u5f53data_free\u5b57\u6bb5\u4e0d\u4e3a\u7a7a\u65f6\uff0c\u8868\u793a\u6709\u788e\u7247<br \/>\n\u6574\u7406\uff1aOPTIMIZE [LOCAL | NO_WRITE_TO_BINLOG] TABLE \u8868\u540d<\/p>\n<hr \/>\n<p>\u4e0b\u9762\u662fmysql\u7684\u914d\u7f6e\u6587\u4ef6\u5b9e\u4f8b\uff08my.ini\uff09\uff1a<br \/>\n[mysqld] <\/p>\n<p>gdb <\/p>\n<p>innodb_file_per_table = true <\/p>\n<p>innodb_data_file_path = ibdata1:100M:autoextend <\/p>\n<p>innodb_flush_method = O_DIRECT <\/p>\n<p>innodb_log_buffer_size = 256M <\/p>\n<p>innodb_flush_log_at_trx_commit = 1 <\/p>\n<p>innodb_buffer_pool_size = 125G <\/p>\n<p>innodb_buffer_pool_instances=8 <\/p>\n<p>innodb_log_file_size = 4G <\/p>\n<p>innodb_log_files_in_group = 2 <\/p>\n<h5>plugin options<\/h5>\n<p>innodb_read_io_threads = 16 <\/p>\n<p>innodb_write_io_threads = 16 <\/p>\n<p>innodb_io_capacity = 20000 <\/p>\n<p>innodb_io_capacity_max = 40000 <\/p>\n<h1>not innodb options (fixed)<\/h1>\n<p>port = 3306 <\/p>\n<p>back_log = 50 <\/p>\n<p>max_connections = 2000 <\/p>\n<p>max_prepared_stmt_count=500000 <\/p>\n<p>max_connect_errors = 10 <\/p>\n<p>table_open_cache = 2048 <\/p>\n<p>max_allowed_packet = 16M <\/p>\n<p>binlog_cache_size = 16M <\/p>\n<p>max_heap_table_size = 64M <\/p>\n<p>sort_buffer_size = 4M <\/p>\n<p>join_buffer_size = 4M <\/p>\n<p>thread_cache_size = 1000 <\/p>\n<p>query_cache_size = 0 <\/p>\n<p>query_cache_type = 0 <\/p>\n<p>ft_min_word_len = 4 <\/p>\n<p>thread_stack = 192K <\/p>\n<p>tmp_table_size = 64M <\/p>\n<p>server-id = 10 <\/p>\n<h1>*** MyISAM Specific options<\/h1>\n<p>key_buffer_size = 8M <\/p>\n<p>read_buffer_size = 1M <\/p>\n<p>read_rnd_buffer_size = 4M <\/p>\n<p>bulk_insert_buffer_size = 8M <\/p>\n<p>myisam_sort_buffer_size = 8M <\/p>\n<p>myisam_max_sort_file_size = 10G <\/p>\n<p>myisam_repair_threads = 1 <\/p>\n<p>myisam_recover <\/p>\n<p>user=root <\/p>\n<h2>skip-grant-tables <\/h2>\n<p>innodb_buffer_pool_size = 1024M<br \/>\ninnodb_buffer_pool_instances = 4<br \/>\nmax_connections = 2000<\/p>\n<h1>innodb_log_buffer_size = 64M<\/h1>\n<p>max_user_connections = 1000<br \/>\ninnodb_flush_log_at_trx_commit = 2<br \/>\ninnodb_write_io_threads = 16<\/p>\n<h1>innodb_read_threads = 16<\/h1>\n<h1>innodb file per table = 1<\/h1>\n<h1>innodb_stats_on_metadata = OFF<\/h1>\n<h1>innodb_spin_wait_delay = 10<\/h1>\n<h1>innodb_lock_wait_timeout = 30<\/h1>\n<h1>default-storage-engine=INNODB \/\/\u8bbe\u7f6e\u9ed8\u8ba4\u6570\u636e\u5e93\u5f15\u64ce<\/h1>\n","protected":false},"excerpt":{"rendered":"<p>Mysql \u6570\u636e\u5e93\u672c\u8eab\u53c2\u6570\u4f18\u5316\uff1a\uff08my.ini\uff09 Mysql \u67e5\u8be2\u7cfb\u7edf\u53d8\u91cf\uff1a show variables like \u53d8\u91cf\u540d \uff1ashow variables like &#8216;s_ow_query_log%&#8217; \u53c2\u6570\u4f18\u5316\uff1a innodb_buffer_pool_size = Gb\/MB \/\/\u7f13\u51b2\u533a\u5927\u5c0f\u4e00\u822c\u4e3a\u6574\u673a\u5185\u5b58\u768470~80% innodb_buffer_pool_instances=8 \/\/\u5185\u5b58\u7f13\u51b2\u6c60\uff08\u5c06\u4e0a\u9762\u914d\u7f6e\u7684\u5185\u5b58\u5206\u6210\u591a\u5c11\u4efd\uff0c\u9ad8IO\u65f6\uff0c\u9700\u8981\u914d\u7f6e\u591a\u4e2a\uff08\u4e00\u822c\u503c&lt;=CPU\u7684\u4e2a\u6570\uff09\uff0c\u8ba9\u6570\u636e\u7f13\u5b58\u5728\u5185\u5b58\u53ef\u5e76\u53d1\u64cd\u4f5c\uff09 max_connections = 2000 \/\/\u6700\u5927\u8fde\u63a5\u6570 max_user_connections=1000 \/\/\u6307\u5b9a\u7684mysql\u7528\u6237\u7684\u6700\u5927\u8fde\u63a5\u6570 innodb_log_buffer_size =64M \/\/\u65e5\u5fd7\u7f13\u51b2\u533a\u5927\u5c0f,\u4e00\u822c\u4e0d\u7528\u8bbe\u7f6e\u592a\u5927\uff0c\u80fd\u5b58\u4e0b1\u79d2\u949f\u64cd\u4f5c\u7684\u6570\u636e\u5c31\u884c\u4e86\u3002 innodb_flush_log_at_trx_commit \uff08\u8fd9\u4e2a\u5f88\u5173\u952e\uff09\u4e00\u822c\u914d\u7f6e\u4e3a2\uff0c\u53d6\u503c0,1,2 0:\u6570\u636e\u64cd\u4f5c\u65f6\uff0c\u76f4\u63a5\u5199\u5185\u5b58\uff0c\u5e76\u4e0d\u540c\u65f6\u5199\u5165\u78c1\u76d8 2:\u6570\u636e\u64cd\u4f5c\u65f6\uff0c\u76f4\u63a5\u5199\u5185\u5b58\uff0c\u5e76\u4e0d\u540c\u65f6\u5199\u5165\u78c1\u76d8 1:\u5c31\u6bcf\u4e2a\u4e8b\u52a1\u63d0\u4ea4\u5c31\u4f1a\u8981\u5237\u65b0\u5230\u78c1\u76d8\u540e\u624d\u7b97\u63d0\u4ea4\u5b8c\u6210,\u8fd9\u79cd\u60c5\u51b5\u662f\u4fdd\u8bc1\u4e86\u4e8b\u52a1\u7684\u4e00\u81f4\u6027,\u4f46\u6027\u80fd\u4f1a\u6709\u5f88\u5927\u7684\u5f71\u54cd&#8230; 0\u4e0e2\u7684\u533a\u522b\uff1a 0\uff1a\u5f53mysql\u6302\u4e86\u4e4b\u540e\uff0c\u53ef\u80fd\u4f1a\u635f\u5931\u524d\u4e00\u79d2\u7684\u4e8b\u52a1\u4fe1\u606f 2\uff1a\u5f53mysql\u6302\u4e86\u4e4b\u540e\uff0c\u5982\u679c\u7cfb\u7edf\u6587\u4ef6\u7cfb\u7edf\u6ca1\u6302\uff0c\u4e0d\u4f1a\u6709\u4e8b\u52a1\u4e22\u5931 innodb_read_io_threads = 16 \/\/\u8bfbIO\u8fdb\u7a0b\u6570 innodb_write_io_threads = 16 \/\/\u5199IO\u8fdb\u7a0b\u6570 innodb file per table=\uff080|1\uff09 \/\/\u6bcf\u4e00\u4e2a\u8868\u662f\u5426\u4f7f\u7528\u72ec\u7acb\u7684\u6570\u636e\u8868\u7a7a\u95f4\uff0c\u9ed8\u8ba4\u4e3aOFF\uff08\u4f7f\u7528\u5171\u4eab\u8868\u7a7a\u95f4\uff09\uff0c\u4e00\u822c\u5efa\u8bae\u914d\u7f6e\u4e3a1\u3002 0\uff1a\u5173\u95ed\u72ec\u7acb\u7684\u8868\u7a7a\u95f4 1\uff1a\u6253\u5f00\u72ec\u7acb\u8868\u7a7a\u95f4 \u8bf4\u660e\uff08InnoDB \u9ed8\u8ba4\u4f1a\u5c06\u6240\u6709\u7684\u6570\u636e\u5e93InnoDB\u5f15\u64ce\u7684\u8868\u6570\u636e\u5b58\u50a8\u5728\u4e00\u4e2a\u5171\u4eab\u7a7a\u95f4\u4e2d\uff1aibdata1\uff0c\u8fd9\u6837\u5c31\u611f\u89c9\u4e0d\u723d\uff0c\u589e\u5220\u6570\u636e\u5e93\u7684\u65f6\u5019\uff0cibdata1\u6587\u4ef6\u4e0d\u4f1a\u81ea\u52a8\u6536\u7f29\uff0c \u5355\u4e2a\u6570\u636e\u5e93\u7684\u5907\u4efd\u4e5f\u5c06\u6210\u4e3a\u95ee\u9898\u3002\u901a\u5e38\u53ea\u80fd\u5c06\u6570\u636e\u4f7f\u7528mysqldump \u5bfc\u51fa\uff0c\u7136\u540e\u518d\u5bfc\u5165\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002 \u5171\u4eab\u8868\u7a7a\u95f4\u5728Insert\u64cd\u4f5c\u4e0a\u5c11\u6709\u4f18\u52bf\u3002\u5176\u5b83\u90fd\u6ca1\u72ec\u7acb\u8868\u7a7a\u95f4\u8868\u73b0\u597d\uff09 innodb_stats_on_metadata=\uff08\uff09 \/\/\u662f\u5426\u52a8\u6001\u5173\u95ed\u7edf\u8ba1\u4fe1\u606f(\u4e00\u822c\u5173\u95ed\uff0c\u627e\u4e2a\u65f6\u95f4\u624b\u52a8\u5237\u65b0\uff0c\u6216\u5b9a\u65f6\u5237\u65b0) innodb_purge_batch_size \/\/&#8212; innodb_purge_threads \/\/\u6e05\u9664\u64cd\u4f5c\u662f\u5426\u4f7f\u7528\u5355\u72ec\u7684\u7ebf\u7a0b 1:\u662f 0\uff1a\u5426\uff08\u4e0d\u652f\u6301\u52a8\u6001\u4fee\u6539\uff0c \u9700\u8981\u6dfb\u52a0\u5230 my.cnf \u91cc\u4fee\u6539\uff0c\u9700\u8981\u7ed3\u5408 innodb_purge_batch_size \u53c2\u6570\u6765\u4f7f\u7528 \uff0c \u9ed8\u8ba4\u503c\u662f 20\uff0c \u6700 \u5927\u53ef\u8bbe\u7f6e\u4e3a 5000\uff0c \u8fd9\u4e2a\u53c2\u6570\u4e00\u822c\u4e0d\u7528 \u8c03\u6574\uff0c \u4f7f\u7528 \u9ed8\u8ba4\u7684\u5373\u53ef\u3002\uff09 innodb_change_buffering \/\/\u63a7\u5236\u5220\u9664\u7f13\u51b2\u548c\u65e2\u6709\u63d2\u5165\u7f13\u51b2\u529f\u80fd\uff0c \u9ed8\u8ba4\u662f all\uff0c \u6b64\u53c2\u6570\u652f\u6301\u52a8\u6001\u8bbe\u7f6e SET GLOBAL innodb_change_buffering = all; innodb_spin_wait_delay=10 \/\/\u63a7\u5236CPU\u8f6e\u5faa\u95f4\u9694 \uff08\u53c2\u6570\u7684\u503c\u9ed8\u8ba4\u662f 6\uff0c \u53ef\u52a8\u6001\u8c03\u6574\uff09 innodb_lock_wait_timeout=30 \/\/\u4fee\u6539\u9501\u7684\u8d85\u65f6\u65f6\u95f4 \uff08 \u9ed8\u8ba450 \u79d2\uff09 slow_query_log \/\/\u6162\u67e5\u8be2\u65e5\u5fd7\u76d1\u63a7\u5f00\u5173 slow_query_log_file \/\/\u6162\u67e5\u8be2\u76d1\u63a7\u65e5\u5fd7\u6587\u4ef6 long_query_time | 10.000000 \/\/\u6162\u67e5\u8be2\u65f6\u95f4\u8bbe\u7f6e (\u5355\u4f4d\uff1aS) &#8212;&#8212;&#8212;&#8212;&#8211;mysql \u7d22\u5f15\u4f18\u5316&#8212;&#8212;&#8212;&#8212;&#8211; \u67e5\u770b\u7d22\u5f15\u4fe1\u606f\uff1ashow index from tablename; \u6267\u884c\u8ba1\u5212\uff1a explain sql\u8bed\u53e5\uff1a mysql&gt; explain select from test; \u6216\uff1aexplain select from test \\G; +&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;-+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;-+ | 1 | SIMPLE | test | ALL | NULL | NULL | NULL | NUL&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","footnotes":""},"categories":[82,100,101],"tags":[],"class_list":["post-1407","post","type-post","status-publish","format-standard","hentry","category-82","category-100","category-101"],"_links":{"self":[{"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1407","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1407"}],"version-history":[{"count":2,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1407\/revisions"}],"predecessor-version":[{"id":1409,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1407\/revisions\/1409"}],"wp:attachment":[{"href":"https:\/\/oneai.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}