{"id":213933,"date":"2021-03-28T09:06:56","date_gmt":"2021-03-28T01:06:56","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=213933"},"modified":"2021-03-22T10:07:22","modified_gmt":"2021-03-22T02:07:22","slug":"mysql-mariadb-variable","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/mysql-mariadb-variable.html","title":{"rendered":"mysql\/mariadb\uff1a\u6570\u636e\u5e93\u53d8\u91cf\uff08\u53c2\u6570\uff09\u7ba1\u7406"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5982\u679c\u6211\u4eec\u60f3\u8981\u67e5\u770bmysql\u7684\u67d0\u4e9b\u5c5e\u6027\u6216\u72b6\u6001\uff0c\u6211\u4eec\u53ef\u4ee5\u67e5\u770bmysql\u7684\u53d8\u91cf\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u901a\u8fc7\u6539\u53d8\u8fd9\u4e9b\u53d8\u91cf\u7684\u503c\uff0c\u6765\u8bbe\u7f6emysql\u7684\u5de5\u4f5c\u5c5e\u6027\uff0c\u6211\u4eec\u53ef\u4ee5\u628amysql\u53d8\u91cf\u7406\u89e3\u6210mysql\u7684\u53c2\u6570\uff0c\u6216\u8005\u8bf4\u5c5e\u6027\u503c\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

mysql\u4e2d\u53d8\u91cf\u53ef\u4ee5\u5206\u4e3a\u7cfb\u7edf\u53d8\u91cf\u4e0e\u72b6\u6001\u53d8\u91cf\u3002<\/p>\n

\u7cfb\u7edf\u53d8\u91cf\u914d\u7f6e\u4e86mysql\u7684\u8fd0\u884c\u73af\u5883\u5c5e\u6027\u3002<\/p>\n

\u72b6\u6001\u53d8\u91cf\u663e\u793a\u4e86mysql\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u7684\u72b6\u6001\u4fe1\u606f\u3002<\/p>\n

\u800c\u7cfb\u7edf\u53d8\u91cf\u4ece\u4f5c\u7528\u57df\u5212\u5206\uff0c\u53c8\u53ef\u4ee5\u5206\u4e3a\u5168\u5c40\u53d8\u91cf\u548c\u4f1a\u8bdd\u53d8\u91cf\u3002<\/p>\n

\u5168\u5c40\u7ea7\u522b\u7684\u53d8\u91cf\uff1agolbal variables\uff0c\u4f5c\u7528\u57df\u4e3a\u6574\u4e2amysql\u670d\u52a1\u5668\u3002<\/p>\n

\u4f1a\u8bdd\u7ea7\u522b\u7684\u53d8\u91cf\uff1asession variables\uff0c\u4f5c\u7528\u57df\u4e3a\u5f53\u524d\u4f1a\u8bdd\u3002<\/p>\n

\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u8fd9\u4e9b\u7cfb\u7edf\u53d8\u91cf\u8fbe\u5230\u8bbe\u7f6emysql\u5c5e\u6027\u7684\u76ee\u7684\u3002<\/p>\n

\u72b6\u6001\u53d8\u91cf\u4e5f\u5206\u4e3a\u5168\u5c40\u7ea7\u522b\u4e0e\u4f1a\u8bdd\u7ea7\u522b\uff0c\u4f46\u662f\u7528\u6237\u65e0\u6cd5\u8bbe\u7f6e\u72b6\u6001\u53d8\u91cf\uff0c\u53ea\u80fd\u67e5\u770b\u3002<\/p>\n

\u6211\u4eec\u603b\u7ed3\u4e00\u4e9b\u600e\u6837\u67e5\u770b\u8fd9\u4e9b\u53d8\u91cf\uff0c\u4ee5\u53ca\u600e\u6837\u8bbe\u7f6e\u8fd9\u4e9b\u53d8\u91cf\u3002<\/p>\n

\u67e5\u770b\u53d8\u91cf\u65b9\u6cd5\u5982\u4e0b<\/strong><\/span><\/div>\n

\u6211\u4eec\u5148\u6765\u770b\u770b\u600e\u6837\u67e5\u770b\u5168\u5c40\u7ea7\u522b\u7684\u7cfb\u7edf\u53d8\u91cf\u503c\u3002<\/p>\n

\r\nshow global variables \\G;\r\n<\/pre>\n

\u4ece\u4e0b\u56fe\u53ef\u4ee5\u770b\u51fa\uff0c\u6211\u901a\u8fc7\u4e0a\u8ff0\u547d\u4ee4\uff0c\u80fd\u591f\u67e5\u8be2\u51fa419\u4e2a\u7cfb\u7edf\u53d8\u91cf\u3002<\/p>\n

\"\"<\/p>\n

\u6839\u636e\u53d8\u91cf\u540d\u67e5\u770b\u53d8\u91cf\u503c\uff0c\u6bd4\u5982\u6211\u60f3\u67e5\u770b\u6240\u6709\u8ddf\u201d\u7248\u672c\u201d\u76f8\u5173\u7684\u5c5e\u6027\u503c<\/p>\n

\r\nshow global variables like \u2018%version%\u2019 \\G;\r\n<\/pre>\n

\u6bd4\u5982\u60f3\u8981\u67e5\u770b\u5b57\u7b26\u96c6\u76f8\u5173\u7684\u5168\u5c40\u8bbe\u7f6e\u3002<\/p>\n

\r\nshow global variables where variable_name like \u2018character%\u2019;\r\n<\/pre>\n

\u6bd4\u5982\u60f3\u8981\u67e5\u770b\u67d0\u4e9b\u65e5\u5fd7\u662f\u5426\u5f00\u542f\u6216\u5173\u95ed\u3002<\/p>\n

\r\nshow global variables where variable_name like \u2018%log%\u2019 and value=\u2019off\u2019;\r\n<\/pre>\n

\u67e5\u770b\u4f1a\u8bdd\u7ea7\u522b\u7684\u6240\u6709\u53d8\u91cf\u3002<\/p>\n

\u4f1a\u8bdd\u7ea7\u522b\u7684\u6240\u6709\u53c2\u6570\u5f80\u5f80\u6bd4\u5168\u5c40\u7684\u66f4\u591a\uff0c\u56e0\u4e3a\u5b83\u4e0d\u4ec5\u7ee7\u627f\u4e86\u5168\u5c40\u7684\u90e8\u5206\u53c2\u6570\uff0c\u53ef\u80fd\u8fd8\u6709\u4e00\u4e9b\u989d\u5916\u7684\u53c2\u6570\u503c\u3002<\/p>\n

\u4f7f\u7528\u5982\u4e0b\u8bed\u53e5\u67e5\u770b\u4f1a\u8bdd\u7ea7\u522b\u7684\u53c2\u6570\u503c\u3002<\/p>\n

\r\nshow session variables \\G;\r\n<\/pre>\n

\"\"<\/p>\n

\u5f53\u7136\uff0c\u4f7f\u7528\u65b9\u6cd5\u4e0e\u5168\u5c40\u7684\u6ca1\u6709\u4efb\u4f55\u533a\u522b\uff0c\u53ea\u662f\u5c06global\u5173\u952e\u5b57\u6539\u4e3a\u4e86session\u5173\u952e\u5b57\u3002<\/p>\n

\u6ce8\u610f\uff1a\u6709\u4e9b\u53d8\u91cf\u53ea\u5b58\u5728\u4e8e\u5168\u5c40\u7ea7\u522b\u4e2d\uff0c\u6709\u4e9b\u53d8\u91cf\u53ea\u5b58\u5728\u4e8e\u4f1a\u8bdd\u7ea7\u522b\u4e2d\u3002<\/p>\n

\u5982\u679c\u4e0d\u6307\u660eglobal\u6216\u8005session\uff0c\u5219\u8868\u793a\u67e5\u770b\u4f1a\u8bdd\u7ea7\u522b\u7684\u53d8\u91cf\u503c\uff0c\u5982\u4e0b\u8bed\u53e5\u8868\u793a\u663e\u793a\u4f1a\u8bdd\u7ea7\u522b\u7684\u53d8\u91cf\u3002<\/p>\n

\r\nshow variables;\r\n<\/pre>\n

\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528\u53e6\u4e00\u79cd\u8bed\u6cd5\uff0c\u67e5\u770b\u5355\u4e2a\u5168\u5c40\u7cfb\u7edf\u53d8\u91cf\u6216\u8005\u4f1a\u8bdd\u7cfb\u7edf\u53d8\u91cf\u3002<\/p>\n

\r\nSELECT @@[global.|session.]system_var_name\r\n<\/pre>\n

\u4f46\u662f\u4f7f\u7528\u4e0a\u8ff0\u8bed\u6cd5\uff0c\u9700\u8981\u51c6\u786e\u7684\u6307\u660e\u53d8\u91cf\u540d\u79f0\uff0c\u6bd4\u5982\u67e5\u770b\u5168\u5c40\u7cfb\u7edf\u53d8\u91cfpid_file\u7684\u503c\uff0c\u793a\u4f8b\u5982\u4e0b\u3002<\/p>\n

\r\nselect @@global.pid_file;\r\n<\/pre>\n

\"\"<\/p>\n

\u6216\u8005\u67e5\u770b\u4f1a\u8bdd\u53d8\u91cfwarning_count\u7684\u503c\uff0c\u793a\u4f8b\u8bed\u53e5\u5982\u4e0b\u3002<\/p>\n

\r\nselect @@session.warning_count;\r\n<\/pre>\n

\"\"<\/p>\n

\u4f46\u662f\uff0c\u6211\u4eec\u4e0d\u80fd\u5728\u6307\u660e\u8981\u67e5\u770b\u5168\u5c40\u53d8\u91cf\u65f6\uff0c\u5374\u6307\u5b9a\u4f1a\u8bdd\u7ea7\u522b\u72ec\u6709\u7684\u53d8\u91cf\uff0c\u6bd4\u5982\u4e0a\u4f8b\u4e2d\u7684warning_count\u53d8\u91cf\u53ea\u5b58\u5728\u4e8e\u4f1a\u8bdd\u7ea7\u522b\uff0c\u4f46\u662f\u6211\u4eec\u504f\u504f\u5374\u8981\u4f7f\u7528\u5982\u4e0b\u65b9\u6cd5\u67e5\u770b\uff0c\u5219\u4f1a\u62a5\u9519\u3002<\/p>\n

\"\"<\/p>\n

\u53cd\u4e4b\u4ea6\u7136<\/p>\n

\"\"<\/p>\n

\u56e0\u4e3a\u6211\u4eec\u8bf4\u8fc7\uff0c\u6709\u4e9b\u53d8\u91cf\u53ea\u5b58\u5728\u4e8e\u5168\u5c40\u7ea7\u522b\uff0c\u6709\u4e9b\u53d8\u91cf\u53ea\u5b58\u5728\u4e8e\u4f1a\u8bdd\u7ea7\u522b\u3002<\/p>\n

\u5982\u679c\u4f60\u5e76\u4e0d\u6e05\u695a\u4f60\u8981\u67e5\u8be2\u7684\u53d8\u91cf\u5177\u4f53\u5c5e\u4e8e\u54ea\u4e2a\u7ea7\u522b\uff0c\u53ef\u4ee5\u4e0d\u6307\u660eglobal\u6216\u8005session\uff0c\u5982\u679c\u4e0d\u6307\u660e\u53d8\u91cf\u6240\u5728\u7ea7\u522b\uff0c\u5219\u8868\u793a\u4f18\u5148\u4ece\u4f1a\u8bdd\u7ea7\u522b\u67e5\u627e\u5bf9\u5e94\u7684\u53d8\u91cf\uff0c\u5982\u679c\u5bf9\u5e94\u53d8\u91cf\u5b58\u5728\uff0c\u5219\u663e\u793a\u5176\u503c\uff0c\u5982\u679c\u5728\u4f1a\u8bdd\u7ea7\u522b\u4e2d\u5bf9\u5e94\u7684\u53d8\u91cf\u4e0d\u5b58\u5728\uff0c\u5219\u56de\u53bb\u5168\u5c40\u7ea7\u522b\u4e2d\u67e5\u627e\u5bf9\u5e94\u7684\u53d8\u91cf\u503c\uff0c\u793a\u4f8b\u5982\u4e0b\u3002<\/p>\n

\"\"<\/p>\n

\u5728\u5199\u5b58\u50a8\u8fc7\u7a0b\u65f6\uff0c\u5982\u679c\u9700\u8981\u8c03\u7528\u7cfb\u7edf\u53d8\u91cf\u7684\u503c\uff0c\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u65b9\u6cd5\u8c03\u7528\u3002<\/p>\n

\r\n@@GLOBAL.var_name\r\n\r\n@@SESSION.var_name\r\n<\/pre>\n

\u540c\u6837 @@var_name \u8868\u793a\u4f18\u5148\u4ece\u4f1a\u8bdd\u7ea7\u522b\u83b7\u53d6\u53d8\u91cf\u503c\u3002<\/p>\n

\u4e0a\u8ff0\u793a\u4f8b\u4e2d\u7684\u65b9\u6cd5\u4e3a\u600e\u6837\u67e5\u770b\u7cfb\u7edf\u53d8\u91cf\u3002<\/p>\n

\u6211\u4eec\u8fd8\u53ef\u4ee5\u67e5\u8be2mysql\u8fd0\u884c\u4e2d\u7684\u7edf\u8ba1\u4fe1\u606f\u6216\u72b6\u6001\u6570\u636e\uff0c\u4f7f\u7528\u5982\u4e0b\u8bed\u53e5\u5373\u53ef\u67e5\u770b\u72b6\u6001\u53d8\u91cf\u3002<\/p>\n

\r\nshow status;\r\n<\/pre>\n

\u67e5\u8be2\u51fa\u7684\u7ed3\u679c\u5c31\u662f\u4e00\u4e2a\u5217\u8868\uff0c\u6613\u8bfb\u6027\u8f83\u9ad8\u3002<\/p>\n

\"\"<\/p>\n

\u540c\u7406\uff0c\u4e5f\u80fd\u591f\u901a\u8fc7like\u8fc7\u6ee4\u51fa\u6211\u4eec\u60f3\u8981\u67e5\u627e\u7684\u53d8\u91cf\u540d\u79f0\u3002<\/p>\n

\u800c\u4e14\u72b6\u6001\u53d8\u91cf\u4e5f\u5206\u4e3a\u5168\u5c40\u7ea7\u522b\u4e0e\u4f1a\u8bdd\u7ea7\u522b\u3002<\/p>\n

\"\"<\/p>\n

\u4fee\u6539\u53d8\u91cf\u503c\/\u8bbe\u5b9a\u53d8\u91cf\u503c \u65b9\u6cd5\u5982\u4e0b<\/p>\n

\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e24\u79cd\u65b9\u6cd5\u4fee\u6539\u6570\u636e\u5e93\u53d8\u91cf\uff1a<\/p>\n

\u8fd0\u884c\u65f6\u4fee\u6539\uff0c\u5982\u679c\u662f\u8fd0\u884c\u65f6\u4fee\u6539\uff0c\u4fee\u6539\u662f\u5426\u7acb\u5373\u751f\u6548\u53d6\u51b3\u4e8e\u4fee\u6539\u7684\u53d8\u91cf\u7c7b\u578b\uff1a<\/p>\n

\u8fd0\u884c\u65f6\u4fee\u6539global\u7ea7\u522b\u7684\u53d8\u91cf\uff1a\u5bf9\u4fee\u6539\u4e4b\u524d\u5efa\u7acb\u7684\u4f1a\u8bdd\u6ca1\u6709\u5f71\u54cd\uff0c\u4ec5\u5bf9\u4fee\u6539\u540e\u65b0\u5efa\u7acb\u7684\u4f1a\u8bdd\u6709\u6548\uff1b<\/p>\n

\u8fd0\u884c\u65f6\u4fee\u6539session\u7ea7\u522b\u7684\u53d8\u91cf\uff1a\u4ec5\u5bf9\u5f53\u524d\u4f1a\u8bdd\u6709\u6548\uff0c\u4e14\u7acb\u5373\u751f\u6548\uff1b<\/p>\n

\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u4fee\u6539\uff1a\u9700\u91cd\u542f\u540e\u751f\u6548\uff0c\u4f46\u662f\u6c38\u4e45\u6709\u6548\u3002<\/p>\n

\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7set\u547d\u4ee4\uff0c\u8fd0\u884c\u65f6\u4fee\u6539\u5bf9\u5e94\u7684\u53d8\u91cf\u3002<\/p>\n

\u6bd4\u5982\uff0c\u6211\u4eec\u5148\u67e5\u770b\u4e00\u4e0bsession\u7ea7\u522b\u7684\u67d0\u4e2a\u53d8\u91cf\u3002<\/p>\n

\"\"<\/p>\n

\u4f1a\u8bdd\u7ea7\u522b\u4e2dautocommit\u53d8\u91cf\u7684\u503c\u4e3a1\uff0c\u6211\u4eec\u73b0\u5728\u5c06\u4f1a\u8bdd\u7ea7\u522b\u4e2d\u7684autocommit\u53d8\u91cf\u7684\u503c\u6539\u4e3a0<\/p>\n

\"\"<\/p>\n

\u6211\u4eec\u5c06\u8bbe\u7f6e\u7cfb\u7edf\u53d8\u91cf\u7684\u8bed\u6cd5\u603b\u7ed3\u5982\u4e0b\uff1a<\/p>\n

\r\nSET GLOBAL var_name = value;\r\n\r\nSET @@GLOBAL.var_name = value;\r\n\r\nSET SESSION var_name = value;\r\n\r\nSET @@SESSION.var_name = value;\r\n<\/pre>\n

\u4e0d\u6307\u5b9a\u7ea7\u522b\u8868\u793a\u9ed8\u8ba4\u4e3a\u8bbe\u7f6e\u4f1a\u8bdd\u7ea7\u522b\u7684\u53d8\u91cf\u3002<\/p>\n

\r\nSET var_name = value;\r\n<\/pre>\n

\u72b6\u6001\u53d8\u91cf\u5bf9\u4e8e\u7528\u6237\u6765\u8bf4\u662f\u53ea\u8bfb\u7684\uff0c\u6240\u4ee5\uff0c\u6211\u4eec\u53ea\u8981\u5b66\u4f1a\u4fee\u6539\u7cfb\u7edf\u53d8\u91cf\u5373\u53ef\u3002<\/p>\n

\u5728\u4fee\u6539\u7cfb\u7edf\u53d8\u91cf\u65f6\u8981\u8bb0\u4f4f\u5982\u4e0b\u6ce8\u610f\u70b9\u3002 <\/p>\n

\u8fd0\u884c\u65f6\u4fee\u6539\u7684\u53d8\u91cf\u5e76\u975e\u6c38\u4e45\u6709\u6548\uff0c\u91cd\u542f\u540e\u5c06\u4f1a\u5931\u6548\uff1b<\/p>\n

\u8fd0\u884c\u65f6\u4fee\u6539global\u7ea7\u522b\u7684\u53d8\u91cf\uff1a\u5bf9\u4fee\u6539\u4e4b\u524d\u5efa\u7acb\u7684\u4f1a\u8bdd\u6ca1\u6709\u5f71\u54cd\uff0c\u4ec5\u5bf9\u4fee\u6539\u540e\u65b0\u5efa\u7acb\u7684\u4f1a\u8bdd\u6709\u6548\uff1b<\/p>\n

\u8fd0\u884c\u65f6\u4fee\u6539session\u7ea7\u522b\u7684\u53d8\u91cf\uff1a\u4ec5\u5bf9\u5f53\u524d\u4f1a\u8bdd\u6709\u6548\uff0c\u4e14\u7acb\u5373\u751f\u6548\uff1b<\/p>\n

\u5982\u679c\u60f3\u8981\u4f7f\u8bbe\u5b9a\u6c38\u4e45\u6709\u6548\uff0c\u9700\u8981\u8bbe\u7f6e\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n

\u4f46\u662f\u5728\u4e0d\u786e\u5b9a\u7684\u60c5\u51b5\u4e0b\uff0c\u4e0d\u8981\u968f\u4fbf\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\uff0c\u5426\u5219\u5c06\u53ef\u80fd\u4f1a\u51fa\u73b0\u65e0\u6cd5\u9884\u8ba1\u7684\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

mysql\u4e2d\u53d8\u91cf\u53ef\u4ee5\u5206\u4e3a\u7cfb\u7edf\u53d8\u91cf\u4e0e\u72b6\u6001\u53d8\u91cf\u3002 \u7cfb\u7edf\u53d8\u91cf\u914d\u7f6e\u4e86mysql\u7684\u8fd0\u884c\u73af\u5883\u5c5e\u6027\u3002 \u72b6\u6001\u53d8\u91cf\u663e\u793a\u4e86mysq […]<\/p>\n","protected":false},"author":362,"featured_media":4820,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-213933","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/213933","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/362"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=213933"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/213933\/revisions"}],"predecessor-version":[{"id":214060,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/213933\/revisions\/214060"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/4820"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=213933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=213933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=213933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}