{"id":1363,"date":"2017-12-25T16:03:45","date_gmt":"2017-12-25T08:03:45","guid":{"rendered":"http:\/\/www.royalwzy.com\/?p=1363"},"modified":"2018-01-09T16:07:06","modified_gmt":"2018-01-09T08:07:06","slug":"mysql8%e6%96%b0%e7%89%b9%e6%80%a7-persist","status":"publish","type":"post","link":"http:\/\/www.royalwzy.com\/?p=1363","title":{"rendered":"MySQL8\u65b0\u7279\u6027-PERSIST"},"content":{"rendered":"<p>\u5728\u4ee5\u524d\u662f\u7248\u672c\u91cc\u6211\u4eecset \u4e00\u4e2a\u53c2\u6570\u7684\u65f6\u5019\u53ef\u4ee5\u4f7f\u7528GLOBAL | SESSION\u548c\u5f71\u54cd\u5f53\u524d\u4f1a\u8bdd\u548c\u5168\u5c40\u7684\u53c2\u6570\u3002\u4f46\u662f\u5373\u4f7f\u662fglobal\u7684\u53c2\u6570\u5728\u91cd\u65b0\u542f\u52a8\u5b9e\u4f8b\u4ee5\u540e\u4e5f\u662f\u4f1a\u6d88\u5931\u7684\u3002\u4e3a\u6b64\u5728MySQL8\u4ee5\u540e\u7684\u7248\u672c\u5f15\u5165\u4e86\u53e6\u5916\u7684\u4e24\u4e2a\u8bed\u6cd5\u53c2\u6570\uff0c\u6211\u4eec\u4f7f\u7528help set\u53ef\u4ee5\u770b\u5230\u4e00\u5171\u7528\u4e86\u4ee5\u4e0b\u56db\u4e2a\u503c\u3002<br \/>\n[GLOBAL | SESSION | PERSIST | PERSIST_ONLY]<br \/>\n[@@global. | @@session. | @@persist. | @@persist_only. | @@]<br \/>\n\u7b80\u5355\u6765\u8bf4PERSIST\u8fd9\u662f\u4e00\u4e2a\u7528\u6765\u914d\u7f6e\u6301\u7eed\u4f18\u5316\u7edf\u8ba1\u53c2\u6570\u7684\u8bed\u6cd5\u3002\u5f53\u6211\u4eecset PERSIST system_var_name = expr\u7684\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u8fdb\u884c\u914d\u7f6e\u66f4\u6539\u5e76\u4fdd\u5b58\uff0c\u5728\u670d\u52a1\u5668\u91cd\u542f\u540e\u4ecd\u751f\u6548\uff0c \u8fd9\u4e2a\u73af\u5883\u53d8\u91cf\u5728\u4fee\u6539\u7684\u540c\u65f6\u8fd8\u4f1a\u5f71\u54cd\u5230\u6570\u636e\u6587\u4ef6\u76ee\u5f55\u7684\u4e00\u4e2a\u53eb\u505amysqld-auto.cnf\u7684\u6587\u4ef6\uff0cmysql\u5728\u91cd\u65b0\u542f\u52a8\u7684\u65f6\u5019\uff0c\u4f1a\u4f18\u5148\u4f7f\u7528\u8fd9\u4e2a\u6587\u4ef6\u91cc\u7684\u53c2\u6570\u503c\u3002mysql\u7ed9\u6211\u7684\u5efa\u8bae\u662fmysqld-auto.cnf\u6587\u4ef6\u5e94\u7531\u7ba1\u7406\u670d\u52a1\u5668,\u800c\u4e0d\u662f\u624b\u52a8\u6267\u884c\u3002\u6211\u4eec\u5148\u6765\u7b80\u5355\u7684\u770b\u4e00\u4e2a\u4f8b\u5b50<\/p>\n<p>\u5728\u4fee\u6539\u4e4b\u524d\u6211\u4eec\u5148\u67e5\u770b\u4e00\u4e0b\uff1a<br \/>\ndba@(none) 10:39:24&gt;select * from performance_schema.variables_info where VARIABLE_NAME=\u2019mandatory_role;<br \/>\n+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014+\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2014\u2014+\u2014\u2014\u2014-+\u2014\u2014\u2014-+<br \/>\n| VARIABLE_NAME | VARIABLE_SOURCE | VARIABLE_PATH | MIN_VALUE | MAX_VALUE | SET_TIME | SET_USER | SET_HOST |<br \/>\n+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014+\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2014\u2014+\u2014\u2014\u2014-+\u2014\u2014\u2014-+<br \/>\n| mandatory_roles | COMPILED | | 0 | 0 | 2017-11-08 10:58:40 | | |<br \/>\n+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014+\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2014\u2014+\u2014\u2014\u2014-+\u2014\u2014\u2014-+<br \/>\n1 row in set (0.00 sec)<\/p>\n<p>\u7136\u540e\u6211\u4eec\u4fee\u6539\u8fd9\u4e2a\u503c\uff1a<br \/>\nSET PERSIST mandatory_roles = \u2018app_developer@%\u2019;<\/p>\n<p>\u7136\u540e\u67e5\u770b\u4e00\u4e0b\u8fd9\u4e2a\u503c\u7684\u786e\u662f\u88ab\u4fee\u6539\u4e86\uff1a<br \/>\ndba@(none) 10:40:43&gt;<br \/>\ndba@(none) 10:40:43&gt;select * from performance_schema.variables_info where VARIABLE_NAME=\u2019mandatory_roles\u2019;<br \/>\n+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014+\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2014\u2014+\u2014\u2014\u2014-+\u2014\u2014\u2014\u2013+<br \/>\n| VARIABLE_NAME | VARIABLE_SOURCE | VARIABLE_PATH | MIN_VALUE | MAX_VALUE | SET_TIME | SET_USER | SET_HOST |<br \/>\n+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014+\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2014\u2014+\u2014\u2014\u2014-+\u2014\u2014\u2014\u2013+<br \/>\n| mandatory_roles | DYNAMIC | | 0 | 0 | 2017-11-08 14:35:24 | dbadmin | localhost |<br \/>\n+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014+\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2014\u2014+\u2014\u2014\u2014-+\u2014\u2014\u2014\u2013+<br \/>\n1 row in set (0.00 sec)<\/p>\n<p>\u53ef\u4ee5\u53d1\u73b0\u5728\u6211\u4eec\u7684my.cnf\u6587\u4ef6\u91cc\u8fd9\u4e2a\u503c\u5e76\u6ca1\u6709\u88ab\u4fee\u6539\u3002<br \/>\n$cat my.cnf | grep mandatory_roles<\/p>\n<p>\u7136\u540e\u6211\u4eec\u53bb\u6570\u636e\u6587\u4ef6\u6240\u5728\u7684\u76ee\u5f55\u67e5\u770b\u591a\u51fa\u6765\u7684\u4e00\u4e2a\u6587\u4ef6\u3002<br \/>\n$cat mysqld-auto.cnf<br \/>\n{ \u201cmysql_server\u201d: {\u201cmandatory_roles\u201d: \u201capp_developer@%\u201d} }<br \/>\n\u53ef\u4ee5\u770b\u5230\u662f\u4e00\u4e2ajson\u683c\u5f0f\u7684\u63cf\u8ff0\u6587\u4ef6\u3002<br \/>\n\u63a5\u4e0b\u6765\u6211\u4eec\u91cd\u542f\u6570\u636e\u5e93\uff0c\u7136\u540e\u67e5\u770b\u5f53\u524d\u53c2\u6570\u7684\u503c\u3002<br \/>\ndbadmin@(none) 10:52:49&gt;show variables like \u2018%mandatory_roles%\u2019;<br \/>\n+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2013+<br \/>\n| Variable_name | Value |<br \/>\n+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2013+<br \/>\n| mandatory_roles | app_developer@% |<br \/>\n+\u2014\u2014\u2014\u2014\u2014\u2013+\u2014\u2014\u2014\u2014\u2014\u2013+<br \/>\n1 row in set (0.00 sec)<\/p>\n<p>dba@(none) 10:55:11&gt;select * from performance_schema.variables_info where VARIABLE_NAME=\u2019mandatory_roles\u2019\\G<br \/>\n*************************** 1. row ***************************<br \/>\nVARIABLE_NAME: mandatory_roles<br \/>\nVARIABLE_SOURCE: PERSISTED<br \/>\nVARIABLE_PATH: \/u01\/my3306\/data\/mysqld-auto.cnf<br \/>\nMIN_VALUE: 0<br \/>\nMAX_VALUE: 0<br \/>\nSET_TIME: 2017-11-09 10:52:14<br \/>\nSET_USER:<br \/>\nSET_HOST:<br \/>\n1 row in set (0.00 sec)<br \/>\n\u53ef\u4ee5\u53d1\u73b0\u8fd8\u662f\u4fee\u6539\u8fc7\u503c\u3002\u8fd9\u4e5f\u8bc1\u660e\u4e86\u6211\u4eec\u7684\u7684\u914d\u7f6e\u8fdb\u884c\u4e86\u6301\u4e45\u5316\u3002<\/p>\n<p>\u90a3\u4e48\u6211\u4eec\u600e\u4e48\u53d6\u6d88\u8fd9\u4e2a\u503c\u8bbe\u7f6e\u5462\u3002<br \/>\n\u6709\u4e24\u79cd\u65b9\u6cd5\uff0c\u5b83\u4eec\u7565\u6709\u4e00\u70b9\u4e0d\u540c<br \/>\n1.SET PERSIST mandatory_roles = DEFAULT;<br \/>\n2.RESET PERSIST IF EXISTS mandatory_roles;<br \/>\n\u5728\u6211\u4eec\u4f7f\u7528\u7b2c\u4e00\u79cd\u65b9\u6cd5\u7684\u65f6\u5019\uff0cmysqld-auto.cnf\u8fd8\u662f\u6709\u8fd9\u4e2a\u503c\u7684\uff0c\u5f53\u6211\u4eec\u518d\u6b21\u91cd\u542f\u7684\u65f6\u5019\u5b83\u8fd8\u662f\u8bfb\u8fd9\u4e2a\u6587\u4ef6<br \/>\n$cat data\/mysqld-auto.cnf<br \/>\n{ \u201cmysql_server\u201d: {\u201cmandatory_roles\u201d: \u201c\u201d } }<br \/>\n\u5728\u6211\u4eec\u4f7f\u7528\u7b2c\u4e8c\u79cd\u65b9\u6cd5\u7684\u65f6\u5019\u5c31\u5b8c\u5168\u628a\u8fd9\u4e2a\u53c2\u6570\u7684\u5185\u5bb9\u7684\u53bb\u6389\u3002<br \/>\n$cat data\/mysqld-auto.cnf<br \/>\n{ \u201cmysql_server\u201d: { } }<\/p>\n<p>\u4f7f\u7528\u7b2c\u4e8c\u79cd\u5982\u679c\u4e0d\u5b58\u5728\u7684\u8bdd\uff1a<br \/>\ndba@(none) 10:59:27&gt;RESET PERSIST IF EXISTS mandatory_roles;<br \/>\nQuery OK, 0 rows affected, 1 warning (0.00 sec)<\/p>\n<p>dba@(none) 11:01:22&gt;show warnings;<br \/>\n+\u2014\u2014\u2014+\u2014\u2014+\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014+<br \/>\n| Level | Code | Message |<br \/>\n+\u2014\u2014\u2014+\u2014\u2014+\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014+<br \/>\n| Warning | 3615 | Variable mandatory_roles does not exist in persisted config file |<br \/>\n+\u2014\u2014\u2014+\u2014\u2014+\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014+<br \/>\n1 row in set (0.00 sec)<\/p>\n<p>dba@(none) 11:01:27&gt;RESET PERSIST mandatory_roles;<br \/>\nERROR 3615 (HY000): Variable mandatory_roles does not exist in persisted config file<\/p>\n<p>\u5f53\u7136\u6211\u4eec\u4e5f\u53ef\u4ee5\u53ea\u4f7f\u7528@@persist_only \u6765\u5f71\u54cdmysqld-auto.cnf\u7684\u6587\u4ef6\uff0c\u5728\u4e0b\u6b21\u91cd\u542f\u4ee5\u540e\u624d\u751f\u4ea7\u3002<\/p>\n<p>\u6574\u4e2a\u7684\u4f7f\u7528\u5c31\u50cforalce\u7684pfile\u548cspfile\u3002<\/p>\n<p>\u5982\u679c\u4f60\u4e0d\u60f3\u8ba9mysqld-auto.cnf\u4e2d\u7684\u914d\u7f6e\u751f\u6548\uff0c\u53ef\u4ee5\u5728\u542f\u52a8\u65f6\u5173\u95ed\u53ea\u8bfb\u53c2\u6570persisted_globals_load\uff0c\u8fd9\u6837\u5728\u542f\u52a8\u65f6\u5c31\u4e0d\u4f1a\u8f7d\u5165mysqld-auto.cnf\u4e2d\u7684\u914d\u7f6e\u9879\u4e86<\/p>\n<p>https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/set-variable.html?spm=5176.100239.blogcont60656.10.SVzv1S<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4ee5\u524d\u662f\u7248\u672c\u91cc\u6211\u4eecset \u4e00\u4e2a\u53c2\u6570\u7684\u65f6\u5019\u53ef\u4ee5\u4f7f\u7528GLOBAL | SESSION\u548c\u5f71\u54cd\u5f53\u524d\u4f1a\u8bdd\u548c\u5168\u5c40\u7684\u53c2\u6570\u3002\u4f46 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-1363","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts\/1363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1363"}],"version-history":[{"count":1,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts\/1363\/revisions"}],"predecessor-version":[{"id":1364,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts\/1363\/revisions\/1364"}],"wp:attachment":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1363"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}