{"id":489,"date":"2021-07-28T19:36:50","date_gmt":"2021-07-28T11:36:50","guid":{"rendered":"https:\/\/egonlin.com\/?p=489"},"modified":"2021-07-30T10:26:57","modified_gmt":"2021-07-30T02:26:57","slug":"489","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=489","title":{"rendered":"\u6743\u9650\u7ba1\u7406"},"content":{"rendered":"<h1>\u6743\u9650\u7ba1\u7406<\/h1>\n<h2>\u4e00 mysql\u5e93\u4e0b\u7684\u6388\u6743\u8868<\/h2>\n<p>linux\u7cfb\u7edf\u7684\u7528\u6237\u4f5c\u7528\u662f:<\/p>\n<ul>\n<li>1\u3001\u767b\u9646\u7cfb\u7edf<\/li>\n<li>2\u3001\u7ba1\u7406\u7cfb\u7edf\u6587\u4ef6<\/li>\n<\/ul>\n<p>\u4e00\u6837\u7684\u9053\u7406\uff0cmysql\u6570\u636e\u5e93\u7ba1\u7406\u8f6f\u4ef6\u7528\u6237\u7684\u5219\u4f5c\u7528\u662f:<\/p>\n<ul>\n<li>1\u3001\u767b\u9646MySQL\u6570\u636e\u5e93<\/li>\n<li>2\u3001\u7ba1\u7406\u5e93\u4e0e\u8868\u7b49\u6570\u636e\u5e93\u5bf9\u8c61<\/li>\n<\/ul>\n<p>mysql\u6570\u636e\u5e93\u7ba1\u7406\u8f6f\u4ef6\u5c06\u6743\u9650\u4fe1\u606f\u90fd\u5b58\u653e\u4e8emysql\u5e93\u4e0b\uff0c\u8be5\u5e93\u4e0b\u6709\u4e00\u7cfb\u5217\u6388\u6743\u8868\uff0c\u6743\u9650\u4fe1\u606f\u90fd\u5b58\u653e\u4e8e\u8fd9\u4e00\u7cfb\u5217\u8868\u4e2d\uff0c\u6211\u4eec\u6311\u51e0\u4e2a\u91cd\u70b9\u4ecb\u7ecd\u4e00\u4e0b<\/p>\n<p>mysql\u5e93\u4e0b\u7684\u6388\u6743\u8868\u53ca\u5176\u653e\u884c\u6743\u9650\u7684\u8303\u56f4<\/p>\n<ul>\n<li>\n<p>1\u3001mysql.user <\/p>\n<p>\u9488\u5bf9\u6240\u6709\u6570\u636e\u3001\u6240\u6709\u5e93\u4e0b\u6240\u6709\u8868\u3001\u4ee5\u53ca\u8868\u4e0b\u7684\u6240\u6709\u5b57\u6bb5<\/p>\n<\/li>\n<li>\n<p>2\u3001msyql.db <\/p>\n<p>\u53ea\u9488\u5bf9\u67d0\u4e00\u6570\u636e\u5e93\u4e0b\u7684\u6240\u6709\u8868\uff0c\u4ee5\u53ca\u8868\u4e0b\u7684\u6240\u6709\u5b57\u6bb5<\/p>\n<\/li>\n<li>\n<p>3\u3001tables_priv <\/p>\n<p>\u53ea\u9488\u5bf9\u67d0\u4e00\u5f20\u8868\u3001\u4ee5\u53ca\u8be5\u8868\u4e0b\u7684\u6240\u6709\u5b57\u6bb5<\/p>\n<\/li>\n<li>\n<p>4\u3001columns_priv <\/p>\n<p>\u53ea\u9488\u5bf9\u67d0\u4e00\u4e2a\u5b57\u6bb5<\/p>\n<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff1a\u5982\u4e0b\u56fe\uff0c\u6743\u9650\u8868\u653e\u884c\u6743\u9650\u7684\u8303\u56f4<\/p>\n<pre><code>mysql.user\uff1a\u9488\u5bf9\u5e93db1\uff0cdb2\u53ca\u5176\u5305\u542b\u7684\u6240\u6709\ndb\uff1a\u53ea\u9488\u5bf9\u5e93\u4f8b\u5982db1\uff0c\u53ca\u5176db1\u5305\u542b\u7684\u6240\u6709\ntables_priv:\u53ea\u9488\u5bf9db1.table1\uff0c\u53ca\u5176\u8be5\u8868\u5305\u542b\u7684\u6240\u6709\ncolumns_prive:\u53ea\u9488\u5bf9db1.table1.column1\uff0c\u53ea\u653e\u884c\u8be5\u5b57\u6bb5<\/code><\/pre>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2021\/07\/11-1.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2021\/07\/11-1.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<h2>\u4e8c \u6743\u9650\u76f8\u5173\u64cd\u4f5c<\/h2>\n<h3>2.1 \u521b\u5efa\\\u67e5\u8be2\\\u5220\u9664\u7528\u6237<\/h3>\n<p>\u521b\u5efa\u7528\u6237\u8bed\u6cd5<\/p>\n<pre><code>create user &#039;\u7528\u6237\u540d&#039;@&#039;\u4e3b\u673a&#039; identified by &#039;\u5bc6\u7801&#039;;<\/code><\/pre>\n<p>\u4f8b<\/p>\n<pre><code>create user &#039;egon&#039;@&#039;1.1.1.1&#039; identified by &#039;123&#039;;\ncreate user &#039;egon&#039;@&#039;192.168.1.%&#039; identified by &#039;123&#039;;\ncreate user &#039;egon&#039;@&#039;%&#039; identified by &#039;123&#039;;<\/code><\/pre>\n<p>\u67e5\u8be2\u7528\u6237<\/p>\n<pre><code>mysql&gt; select user,host from mysql.user;\n+------+-----------+\n| user | host      |\n+------+-----------+\n| root | 127.0.0.1 |\n| root | ::1       |\n|      | db04      |\n| root | db04      |\n|      | localhost |\n| root | localhost |\n+------+-----------+<\/code><\/pre>\n<p>\u5220\u9664\u7528\u6237<\/p>\n<pre><code>mysql&gt; drop user root@&#039;::1&#039;;\nQuery OK, 0 rows affected (0.01 sec)\n\nmysql&gt; drop user &#039;&#039;@db04;\nQuery OK, 0 rows affected (0.00 sec)\n\nmysql&gt; drop user &#039;root&#039;@db04;\nQuery OK, 0 rows affected (0.00 sec)\n\nmysql&gt; drop user &#039;&#039;@localhost;\nQuery OK, 0 rows affected (0.00 sec)<\/code><\/pre>\n<p>\u4fee\u6539\u5bc6\u7801<\/p>\n<pre><code># \u65b9\u5f0f1\nmysqladmin -uroot -p123 password &#039;1&#039;\n\n# \u65b9\u5f0f2\nupdate mysql.user set password=password(&#039;123&#039;) where user=&#039;root&#039; and host=&#039;localhost&#039;;\n\n# \u65b9\u5f0f3\nset password=password(&#039;1&#039;);   \u4fee\u6539\u5f53\u524d\u7528\u6237\u7684\u5bc6\u7801\n\n# \u65b9\u5f0f4\ngrant all on *.* to &#039;root&#039;@&#039;localhost&#039; identified by &#039;123&#039;;<\/code><\/pre>\n<h3>2.2 \u6388\u6743<\/h3>\n<p>MySQL \u8d4b\u4e88\u7528\u6237\u6743\u9650\u547d\u4ee4\u7684\u7b80\u5355\u683c\u5f0f\u53ef\u6982\u62ec\u4e3a\uff1a<\/p>\n<pre><code>grant \u6743\u9650 on \u6570\u636e\u5e93\u5bf9\u8c61 to \u7528\u6237<\/code><\/pre>\n<p>\u6ce8\u610f\uff1agrant, revoke \u7528\u6237\u6743\u9650\u540e\uff0c\u8be5\u7528\u6237\u53ea\u6709\u91cd\u65b0\u8fde\u63a5 MySQL \u6570\u636e\u5e93\uff0c\u6743\u9650\u624d\u80fd\u751f\u6548\u3002<\/p>\n<p>\u67e5\u770b\u5e2e\u52a9<\/p>\n<pre><code>mysql&gt; help grant<\/code><\/pre>\n<p>\u6743\u9650\uff1a\u5bf9\u6587\u4ef6\u5939\uff0c\u5bf9\u6587\u4ef6\uff0c\u5bf9\u6587\u4ef6\u67d0\u4e00\u5b57\u6bb5\u7684\u6743\u9650<\/p>\n<p>\u5e38\u7528\u6743\u9650\u6709\uff1aselect, insert, update, delete<br \/>\nall\u53ef\u4ee5\u4ee3\u8868\u9664\u4e86grant\u4e4b\u5916\u7684\u6240\u6709\u6743\u9650<\/p>\n<p>MySQL \u7684 \u6743\u9650\uff0c\u5206\u522b\u53ef\u4ee5\u4f5c\u7528\u5728\u591a\u4e2a\u5c42\u6b21\u4e0a<\/p>\n<ul>\n<li>\n<p>1\u3001\u6240\u6709\u5e93\u7684\u6240\u6709\u8868<\/p>\n<\/li>\n<li>\n<p>2\u3001\u5355\u5e93\u4e0b\u7684\u6240\u6709\u8868\uff08\u6700\u5e38\u7528\u7684\u6388\u6743\u7ea7\u522b\uff09<\/p>\n<\/li>\n<li>\n<p>3\u3001\u5355\u8868\u4e0b\u7684\u6240\u6709\u5217<\/p>\n<\/li>\n<li>\n<p>4\u3001\u5355\u5217\u6743\u9650\uff1a\u4f01\u4e1a\u4e1a\u91cc\u79f0\u5355\u5217\u6388\u6743\u4e3a \u8131\u654f\uff0c\u5373\u8131\u79bb\u654f\u611f\u4fe1\u606f\uff0c\u6d89\u53ca\u5230\u654f\u611f\u4fe1\u606f\u4e00\u5b9a\u8981\u8131\u654f<\/p>\n<pre><code>\u4f8b\u5982\n\u6388\u4e88vip\u8d26\u53f7\u5bf9\u67d0\u4e00\u8868\u4e0b\u6240\u6709\u5217\u7684\u67e5\u8be2\u6743\u9650\n\u800c\u6388\u4e88\u975evip\u8d26\u53f7\u5bf9\u67d0\u4e00\u8868\u4e0b\u7684\u67d0\u4e00\u5217\u7684\u67e5\u8be2\u6743\u9650<\/code><\/pre>\n<\/li>\n<li>\n<p>5\u3001\u9488\u5bf9\u5b58\u50a8\u8fc7\u7a0b\u7684\u6743\u9650<\/p>\n<\/li>\n<li>\n<p>6\u3001\u9488\u5bf9\u51fd\u6570\u7684\u6743\u9650<\/p>\n<\/li>\n<\/ul>\n<p>\u4e3e\u4f8b\u5982\u4e0b<\/p>\n<pre><code>#\uff081\uff09\u9488\u5bf9\u6240\u6709\u5e93\u7684\u6240\u6709\u8868\uff1a*.* \ngrant select on *.* to &#039;egon1&#039;@&#039;localhost&#039; identified by &#039;123&#039;; \n\u53ea\u5728user\u8868\u4e2d\u53ef\u4ee5\u67e5\u5230egon1\u7528\u6237\u7684select\u6743\u9650\u88ab\u8bbe\u7f6e\u4e3aY\n\n#\uff082\uff09\u9488\u5bf9\u67d0\u4e00\u6570\u636e\u5e93\uff1adb1.*\ngrant select on db1.* to &#039;egon2&#039;@&#039;%&#039; identified by &#039;123&#039;; \n\u53ea\u5728db\u8868\u4e2d\u53ef\u4ee5\u67e5\u5230egon2\u7528\u6237\u7684select\u6743\u9650\u88ab\u8bbe\u7f6e\u4e3aY\n\n#\uff083\uff09\u9488\u5bf9\u67d0\u4e00\u4e2a\u8868\uff1adb1.t1\ngrant select on db1.t1 to &#039;egon3&#039;@&#039;%&#039; identified by &#039;123&#039;;  \n\u53ea\u5728tables_priv\u8868\u4e2d\u53ef\u4ee5\u67e5\u5230egon3\u7528\u6237\u7684select\u6743\u9650\n\n#\uff084\uff09\u9488\u5bf9\u67d0\u4e00\u4e2a\u5b57\u6bb5\uff1a\nmysql&gt; select * from t3;\n+------+-------+------+\n| id   | name  | age  |\n+------+-------+------+\n|    1 | egon1 |   18 |\n|    2 | egon2 |   19 |\n|    3 | egon3 |   29 |\n+------+-------+------+\n\ngrant select (id,name),update (age) on db1.t3 to &#039;egon4&#039;@&#039;localhost&#039; identified by &#039;123&#039;; \n#\u53ef\u4ee5\u5728tables_priv\u548ccolumns_priv\u4e2d\u770b\u5230\u76f8\u5e94\u7684\u6743\u9650\nmysql&gt; select * from tables_priv where user=&#039;egon4&#039;\\G\n*************************** 1. row ***************************\n       Host: localhost\n         Db: db1\n       User: egon4\n Table_name: t3\n    Grantor: root@localhost\n  Timestamp: 0000-00-00 00:00:00\n Table_priv:\nColumn_priv: Select,Update\nrow in set (0.00 sec)\n\nmysql&gt; select * from columns_priv where user=&#039;egon4&#039;\\G\n*************************** 1. row ***************************\n       Host: localhost\n         Db: db1\n       User: egon4\n Table_name: t3\nColumn_name: id\n  Timestamp: 0000-00-00 00:00:00\nColumn_priv: Select\n*************************** 2. row ***************************\n       Host: localhost\n         Db: db1\n       User: egon4\n Table_name: t3\nColumn_name: name\n  Timestamp: 0000-00-00 00:00:00\nColumn_priv: Select\n*************************** 3. row ***************************\n       Host: localhost\n         Db: db1\n       User: egon4\n Table_name: t3\nColumn_name: age\n  Timestamp: 0000-00-00 00:00:00\nColumn_priv: Update\nrows in set (0.00 sec)\n\n#\uff085\uff09\u4f5c\u7528\u5728\u5b58\u50a8\u8fc7\u7a0b\u4e0a\uff1a\nuse db1;\n\ndelimiter \/\/\ncreate procedure p1()\nBEGIN\n    select * from blog;\n    INSERT into blog(name,sub_time) values(&quot;xxx&quot;,now());\nEND \/\/\ndelimiter ;\n\nshow procedure status; -- \u67e5\u770b\u5230db1\u4e0b\u6709\u4e00\u4e2a\u540d\u4e3ap1\u7684\u5b58\u50a8\u8fc7\u7a0b \n\ngrant execute on procedure db1.p1 to &#039;dba&#039;@&#039;localhost&#039;;\n\n#\uff086\uff09\u4f5c\u7528\u5728\u51fd\u6570\u4e0a\uff1a\ndelimiter \/\/\ncreate function f1(\n    i1 int,\n    i2 int)\nreturns int\nBEGIN\n    declare num int;\n    set num = i1 + i2;\n    return(num);\nEND \/\/\ndelimiter ;\n\nshow function status; -- \u67e5\u770b\u5230db1\u4e0b\u6709\u4e00\u4e2a\u540d\u4e3af1\u7684\u51fd\u6570\n\ngrant execute on function db1.f1 to &#039;dba&#039;@&#039;localhost&#039;;\n\n\u6d4b\u8bd5\uff1a\n[root@localhost ~]# mysql -udba -p\nmysql&gt; select db1.f1(1,2);<\/code><\/pre>\n<p>all\u53ef\u4ee5\u4ee3\u8868\u9664\u4e86grant\u4e4b\u5916\u7684\u6240\u6709\u6743\u9650\uff0c\u53ef\u4ee5\u7528with\u5e26\u4e0agrant,\u6388\u6743\u4e00\u4e2a\u8d85\u7ea7\u7ba1\u7406\u5458<\/p>\n<pre><code>grant all on *.* to egon@&#039;%&#039; identified by &#039;123&#039; with grant option;\n\u67e5\u770bmysql.user\u8868\u4e2d\u53ef\u4ee5\u67e5\u5230egon\u7528\u6237\u7684grant\u6743\u9650\u4e5f\u88ab\u8bbe\u7f6e\u4e3aY<\/code><\/pre>\n<h3>2.3 \u67e5\u770b\u6388\u6743<\/h3>\n<pre><code>#1.\u6388\u6743:\nmysql&gt; grant all on *.* to root@&#039;%&#039; identified by &#039;123&#039;;\n\n#2.\u67e5\u770b\u7528\u6237\u6743\u9650\n\u67e5\u770b\u5f53\u524d\u7528\u6237\uff08\u81ea\u5df1\uff09\u6743\u9650\uff1a\nmysql&gt; show grants;\n\n\u67e5\u770b\u5176\u4ed6 MySQL \u7528\u6237\u6743\u9650\uff1a\nmysql&gt; show grants for root@&#039;%&#039;;<\/code><\/pre>\n<h3>2.4 \u64a4\u9500\u6743\u9650\u3002<\/h3>\n<p>revoke \u8ddf grant \u7684\u8bed\u6cd5\u5dee\u4e0d\u591a\uff0c\u53ea\u9700\u8981\u628a\u5173\u952e\u5b57 \u201cto\u201d \u6362\u6210 \u201cfrom\u201d \u5373\u53ef\uff1a<\/p>\n<pre><code>grant  all on *.* to   dba@localhost;\nrevoke all on *.* from dba@localhost;\nrevoke select on db1.* from &#039;egon&#039;@&#039;%&#039;;<\/code><\/pre>\n<h3>2.5 \u6269\u5c55\u6388\u6743<\/h3>\n<pre><code>max_queries_per_hour\uff1a\u4e00\u4e2a\u7528\u6237\u6bcf\u5c0f\u65f6\u53ef\u53d1\u51fa\u7684\u67e5\u8be2\u6570\u91cf\nmax_updates_per_hour\uff1a\u4e00\u4e2a\u7528\u6237\u6bcf\u5c0f\u65f6\u53ef\u53d1\u51fa\u7684\u66f4\u65b0\u6570\u91cf\nmax_connections_per_hour\uff1a\u4e00\u4e2a\u7528\u6237\u6bcf\u5c0f\u65f6\u53ef\u8fde\u63a5\u5230\u670d\u52a1\u5668\u7684\u6b21\u6570\nmax_user_connections\uff1a\u5141\u8bb8\u540c\u65f6\u8fde\u63a5\u6570\u91cf\n\nmysql&gt; grant all on *.* to test@&#039;%&#039; identified by &#039;123&#039; with max_user_connections 1;\n\n# \u6d4b\u8bd5\uff1a\nmysql -utest -p123 -h192.168.15.100\n\n\u4e0d\u8981\u7528-hlocalhost\uff0c\u5b83\u4ee3\u8868\u901a\u8fc7\u672c\u5730\u5957\u63a5\u5b57\u94fe\u63a5<\/code><\/pre>\n<h3>2.6 \u9488\u5bf9\u4e0d\u540c\u89d2\u8272\u6743\u9650\u5206\u914d<\/h3>\n<h4>2.6.1 \u9488\u5bf9\u666e\u901a\u7528\u6237<\/h4>\n<p>grant \u666e\u901a\u6570\u636e\u7528\u6237\uff0c\u67e5\u8be2\u3001\u63d2\u5165\u3001\u66f4\u65b0\u3001\u5220\u9664 \u6570\u636e\u5e93\u4e2d\u6240\u6709\u8868\u6570\u636e\u7684\u6743\u5229\u3002<\/p>\n<pre><code>grant select on testdb.* to common_user@&#039;%&#039;\ngrant insert on testdb.* to common_user@&#039;%&#039;\ngrant update on testdb.* to common_user@&#039;%&#039;\ngrant delete on testdb.* to common_user@&#039;%&#039;<\/code><\/pre>\n<p>\u6216\u8005\uff0c\u7528\u4e00\u6761 MySQL \u547d\u4ee4\u6765\u66ff\u4ee3\uff1a<\/p>\n<pre><code>grant select, insert, update, delete on testdb.* to common_user@&#039;%&#039;<\/code><\/pre>\n<h4>2.6.2 \u9488\u5bf9\u5f00\u53d1\u4eba\u5458<\/h4>\n<p>grant \u6570\u636e\u5e93\u5f00\u53d1\u4eba\u5458\uff0c\u521b\u5efa\u8868\u3001\u7d22\u5f15\u3001\u89c6\u56fe\u3001\u5b58\u50a8\u8fc7\u7a0b\u3001\u51fd\u6570\u3002\u3002\u3002\u7b49\u6743\u9650\uff0c\u5177\u4f53\u64cd\u4f5c\u5982\u4e0b<\/p>\n<p>1\u3001grant \u521b\u5efa\u3001\u4fee\u6539\u3001\u5220\u9664 MySQL \u6570\u636e\u8868\u7ed3\u6784\u6743\u9650\u3002<\/p>\n<pre><code>grant create on testdb.* to developer@&#039;192.168.0.%&#039;;\ngrant alter  on testdb.* to developer@&#039;192.168.0.%&#039;;\ngrant drop   on testdb.* to developer@&#039;192.168.0.%&#039;;<\/code><\/pre>\n<p>2\u3001grant \u64cd\u4f5c MySQL \u5916\u952e\u6743\u9650\u3002<\/p>\n<pre><code>grant references on testdb.* to developer@&#039;192.168.0.%&#039;;<\/code><\/pre>\n<p>3\u3001grant \u64cd\u4f5c MySQL \u4e34\u65f6\u8868\u6743\u9650\u3002<\/p>\n<pre><code>grant create temporary tables on testdb.* to developer@&#039;192.168.0.%&#039;;<\/code><\/pre>\n<p>4\u3001grant \u64cd\u4f5c MySQL \u7d22\u5f15\u6743\u9650\u3002<\/p>\n<pre><code>grant index on testdb.* to developer@&#039;192.168.0.%&#039;;<\/code><\/pre>\n<p>5\u3001grant \u64cd\u4f5c MySQL \u89c6\u56fe\u3001\u67e5\u770b\u89c6\u56fe\u6e90\u4ee3\u7801 \u6743\u9650\u3002<\/p>\n<pre><code>grant create view on testdb.* to developer@&#039;192.168.0.%&#039;;\n\ngrant show view on testdb.* to developer@&#039;192.168.0.%&#039;;<\/code><\/pre>\n<p>6\u3001grant \u64cd\u4f5c MySQL \u5b58\u50a8\u8fc7\u7a0b\u3001\u51fd\u6570 \u6743\u9650\u3002<\/p>\n<pre><code>grant create routine on testdb.* to developer@&#039;192.168.0.%&#039;; -- now, can show procedure status\n\ngrant alter  routine on testdb.* to developer@&#039;192.168.0.%&#039;; -- now, you can drop a procedure\n\ngrant execute        on testdb.* to developer@&#039;192.168.0.%&#039;;<\/code><\/pre>\n<h4>2.6.3 \u9488\u5bf9\u666e\u901aDBA<\/h4>\n<p>grant \u666e\u901a DBA \u7ba1\u7406\u67d0\u4e2a MySQL \u6570\u636e\u5e93\u7684\u6743\u9650\u3002<\/p>\n<pre><code>grant all privileges on testdb.* to dba@&#039;localhost&#039;<\/code><\/pre>\n<p>\u5176\u4e2d\uff0c\u5173\u952e\u5b57 \u201cprivileges\u201d \u53ef\u4ee5\u7701\u7565\u3002<\/p>\n<h4>2.6.4 \u9488\u5bf9\u9ad8\u7ea7DBA<\/h4>\n<p>grant \u9ad8\u7ea7 DBA \u7ba1\u7406 MySQL \u4e2d\u6240\u6709\u6570\u636e\u5e93\u7684\u6743\u9650\u3002<\/p>\n<pre><code>grant all on *.* to dba@&#039;localhost&#039;<\/code><\/pre>\n<h3>2.7 \u5728\u4f01\u4e1a\u4e2d\u6743\u9650\u7684\u8bbe\u5b9a<\/h3>\n<pre><code>#\u5f00\u53d1\u4eba\u5458\u8bf4\uff1a\u8bf7\u7ed9\u6211\u5f00\u4e00\u4e2a\u7528\u6237\n\n#1.\u9996\u5148\u8fdb\u884c\u6c9f\u901a\n    1.\u4f60\u9700\u8981\u5bf9\u54ea\u4e9b\u5e93\u3001\u8868\u8fdb\u884c\u64cd\u4f5c\n    2.\u4f60\u4ece\u54ea\u91cc\u8fde\u63a5\u8fc7\u6765\n    3.\u7528\u6237\u540d\u6709\u6ca1\u6709\u8981\u6c42\n    4.\u5bc6\u7801\u8981\u6c42\n    5.\u4f60\u8981\u4f7f\u7528\u591a\u957f\u65f6\u95f4\n    6.\u53d1\u90ae\u4ef6\n\n#2.\u4e00\u822c\u7ed9\u5f00\u53d1\u521b\u5efa\u7528\u6237\u6743\u9650\uff0c\u5efa\u8bae\u4e0d\u7ed9delete\u6743\u9650\ngrant select,update,delete,insert on *.* to egon@&#039;10.0.0.%&#039;&#039; identified by &#039;123&#039;;\n\n#3.\u6ce8\u610f\uff1a\n\u5f00\u53d1\u56fe\u65b9\u4fbf\u60f3\u8981root\u7528\u6237\uff0c\u8fd9\u73a9\u610f\uff0c\u8c01\u7ed9\u8c01\u80cc\u9505\uff0c\u81ea\u5df1\u659f\u914c\uff0c\u53ef\u4ee5\u8003\u8651\u8ba9\u90e8\u95e8\u8001\u5927\u6765\u7ed9<\/code><\/pre>\n<h2>\u56db \u7834\u89e3\u5bc6\u7801<\/h2>\n<h3>4.1 linux\u5e73\u53f0<\/h3>\n<p>\u65b9\u6cd5\u4e00\uff1a\u4e0d\u63a8\u8350<\/p>\n<pre><code>[root@egon ~]# rm -rf \/var\/lib\/mysql\/mysql  # \u6240\u6709\u6388\u6743\u4fe1\u606f\u5168\u90e8\u4e22\u5931\uff01\uff01\uff01\n[root@egon ~]# systemctl restart mariadb\n[root@egon ~]# mysql<\/code><\/pre>\n<p>\u65b9\u6cd5\u4e8c\uff1a\u542f\u52a8\u65f6\uff0c\u8df3\u8fc7\u6388\u6743\u5e93<\/p>\n<pre><code>[root@egon ~]# vim \/etc\/my.cnf    #mysql\u4e3b\u914d\u7f6e\u6587\u4ef6\n[mysqld]\nskip-grant-table\n\n[root@egon ~]# systemctl restart mariadb\n\n[root@egon ~]# mysql\nMariaDB [(none)]&gt; update mysql.user set password=password(&quot;123&quot;) where user=&quot;root&quot; and host=&quot;localhost&quot;;\nMariaDB [(none)]&gt; flush privileges;\nMariaDB [(none)]&gt; \\q\n\n[root@egon ~]# #\u6253\u5f00\/etc\/my.cnf\u53bb\u6389skip-grant-table,\u7136\u540e\u91cd\u542f\n[root@egon ~]# systemctl restart mariadb\n[root@egon ~]# mysql -u root -p123  # \u4ee5\u65b0\u5bc6\u7801\u767b\u5f55<\/code><\/pre>\n<p>\u65b9\u6cd5\u4e09\uff1a<\/p>\n<pre><code class=\"language-bash\"># 1\u3001\u5148\u5173\u95ed\u6570\u636e\u5e93\u670d\u52a1\n\u65b9\u5f0f\u4e00\nsystemctl stop mysql\n\u65b9\u5f0f\u4e8c\nmysqladmin -uroot -p123 -S \/tmp\/mysql.sock shutdown\n\n# 2\u3001\u8df3\u8fc7\u6388\u6743\u8868\u542f\u52a8mysql\nmysqld_safe --skip-grant-tables --skip-networking &amp;\n\nps\uff1a\u8fd8\u9700\u8981\u8df3\u8fc7\u7f51\u7edc\uff0c\u5426\u5219\u5728\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\u5f88\u4e0d\u5b89\u5168\n\n# 3\u3001\u767b\u5f55\u5e76\u4fee\u6539\u5bc6\u7801\n[root@egon ~]# mysql\nMariaDB [(none)]&gt; update mysql.user set password=password(&quot;123&quot;) where user=&quot;root&quot; and host=&quot;localhost&quot;;\nMariaDB [(none)]&gt; flush privileges;\nMariaDB [(none)]&gt; \\q\n\n# 4\u3001\u91cd\u542f\u670d\u52a1\nsystemctl start mysql\n\n# 5\u3001\u7528\u4fee\u6539\u540e\u7684\u5bc6\u7801\u767b\u5f55\u5373\u53ef<\/code><\/pre>\n<h3>4.2 windows\u5e73\u53f0\u4e0b<\/h3>\n<p>5.7\u7248\u672cmysql<br \/>\n\u65b9\u5f0f\u4e00<\/p>\n<pre><code>#1 \u5173\u95edmysql\n#2 \u5728cmd\u4e2d\u6267\u884c\uff1amysqld --skip-grant-tables\n#3 \u5728cmd\u4e2d\u6267\u884c\uff1amysql\n#4 \u6267\u884c\u5982\u4e0bsql\uff1a\nupdate mysql.user set authentication_string=password(&#039;&#039;) where user = &#039;root&#039;;\nflush privileges;\n\n#5 tskill mysqld #\u6216taskkill -f \/PID 7832\n#6 \u91cd\u65b0\u542f\u52a8mysql<\/code><\/pre>\n<p>\u65b9\u5f0f\u4e8c<\/p>\n<pre><code>#1. \u5173\u95edmysql\uff0c\u53ef\u4ee5\u7528tskill mysqld\u5c06\u5176\u6740\u6b7b\n#2. \u5728\u89e3\u538b\u76ee\u5f55\u4e0b\uff0c\u65b0\u5efamysql\u914d\u7f6e\u6587\u4ef6my.ini\n#3. my.ini\u5185\u5bb9,\u6307\u5b9a\n[mysqld]\nskip-grant-tables\n\n#4.\u542f\u52a8mysqld\n#5.\u5728cmd\u91cc\u76f4\u63a5\u8f93\u5165mysql\u767b\u5f55\uff0c\u7136\u540e\u64cd\u4f5c\nupdate mysql.user set authentication_string=password(&#039;&#039;) where user=&#039;root and host=&#039;localhost&#039;;\n\nflush privileges;\n\n#6.\u6ce8\u91camy.ini\u4e2d\u7684skip-grant-tables\uff0c\u7136\u540e\u542f\u52a8myqsld\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u4ee5\u65b0\u5bc6\u7801\u767b\u5f55\u4e86<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6743\u9650\u7ba1\u7406 \u4e00 mysql\u5e93\u4e0b\u7684\u6388\u6743\u8868 linux\u7cfb\u7edf\u7684\u7528\u6237\u4f5c\u7528\u662f: 1\u3001\u767b\u9646\u7cfb\u7edf 2\u3001\u7ba1\u7406\u7cfb\u7edf\u6587\u4ef6 \u4e00\u6837\u7684\u9053\u7406 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":490,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[81],"tags":[21,19,99,22,100,20],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/489"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=489"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/489\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/media\/490"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}