{"id":231,"date":"2024-11-13T17:10:19","date_gmt":"2024-11-13T09:10:19","guid":{"rendered":"https:\/\/telaker.cn\/?p=231"},"modified":"2024-11-17T10:40:57","modified_gmt":"2024-11-17T02:40:57","slug":"mysql-01","status":"publish","type":"post","link":"https:\/\/telaker.cn\/index.php\/2024\/11\/13\/mysql-01\/","title":{"rendered":"MYSQL\u67e5\u770b\u7528\u6237\u3001\u521b\u5efa\u7528\u6237\u3001\u8d4b\u4e88\u6743\u9650\u3001\u8fdc\u7a0b\u8bbf\u95ee"},"content":{"rendered":"\n<p>\u5728 MySQL \u6570\u636e\u5e93\u4e2d\uff0c\u67e5\u770b\u7528\u6237\u4fe1\u606f\u901a\u5e38\u6d89\u53ca\u5230\u8bbf\u95ee\u7cfb\u7edf\u6570\u636e\u5e93\u4e2d\u7684\u7528\u6237\u8868\u3002\u5728 MySQL 5.7 \u53ca\u66f4\u9ad8\u7248\u672c\u4e2d\uff0c\u7528\u6237\u4fe1\u606f\u5b58\u50a8\u5728&nbsp;<code>mysql<\/code>&nbsp;\u6570\u636e\u5e93\u7684&nbsp;<code>user<\/code>&nbsp;\u8868\u4e2d\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u67e5\u770b MySQL \u7528\u6237\u7684\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f7f\u7528 SQL \u67e5\u8be2\u67e5\u770b\u7528\u6237<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u767b\u5f55\u5230 MySQL\uff1a\u9996\u5148\uff0c\u4f60\u9700\u8981\u4ee5\u5177\u6709\u8db3\u591f\u6743\u9650\uff08\u5982&nbsp;root&nbsp;\u7528\u6237\uff09\u7684\u8eab\u4efd\u767b\u5f55\u5230 MySQL \u670d\u52a1\u5668\u3002\n\nmysql -u root -p\n#\u7cfb\u7edf\u4f1a\u63d0\u793a\u4f60\u8f93\u5165&nbsp;root&nbsp;\u7528\u6237\u7684\u5bc6\u7801\u3002\n\n#\u67e5\u8be2\u7528\u6237\u8868\uff1a\n#\u767b\u5f55\u540e\uff0c\u4f60\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b SQL \u67e5\u8be2\u6765\u67e5\u770b\u6240\u6709\u7528\u6237\uff1a\n\nSELECT User, Host FROM mysql.user;\n#\u8fd9\u5c06\u5217\u51fa\u6240\u6709\u7528\u6237\u53ca\u5176\u5bf9\u5e94\u7684\u4e3b\u673a\u540d\uff08\u5373\u7528\u6237\u53ef\u4ee5\u4ece\u54ea\u4e9b\u4e3b\u673a\u8fde\u63a5\u5230 MySQL \u670d\u52a1\u5668\uff09\u3002<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5728 MariaDB \u4e2d\uff0c\u521b\u5efa\u65b0\u7528\u6237\u3001\u8bbe\u7f6e\u5bc6\u7801\u4ee5\u53ca\u6388\u4e88\u6570\u636e\u5e93\u6240\u6709\u6743\uff08\u6216\u7279\u5b9a\u6743\u9650\uff09<\/h2>\n\n\n\n<p>\u901a\u5e38\u6d89\u53ca\u51e0\u4e2a\u6b65\u9aa4\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u6267\u884c\u8fd9\u4e9b\u64cd\u4f5c\u7684\u6307\u5357\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u767b\u5f55\u5230 MariaDB<\/strong>\uff1a<br>\u9996\u5148\uff0c\u4f60\u9700\u8981\u4ee5\u5177\u6709\u8db3\u591f\u6743\u9650\uff08\u5982&nbsp;<code>root<\/code>&nbsp;\u7528\u6237\uff09\u7684\u8eab\u4efd\u767b\u5f55\u5230 MariaDB \u670d\u52a1\u5668\u3002<br><code>mysql -u root -p<\/code><br>\u7cfb\u7edf\u4f1a\u63d0\u793a\u4f60\u8f93\u5165&nbsp;<code>root<\/code>&nbsp;\u7528\u6237\u7684\u5bc6\u7801\u3002<\/li>\n\n\n\n<li><strong>\u521b\u5efa\u65b0\u7528\u6237<\/strong>\uff1a<br>\u4f7f\u7528\u00a0<code>CREATE USER<\/code>\u00a0\u8bed\u53e5\u6765\u521b\u5efa\u540d\u4e3a\u00a0<code>superset<\/code>\u00a0\u7684\u65b0\u7528\u6237\uff0c\u5e76\u4e3a\u5176\u8bbe\u7f6e\u5bc6\u7801\u00a0\u3002\u6ce8\u610f\uff0c\u51fa\u4e8e\u5b89\u5168\u8003\u8651\uff0c\u901a\u5e38\u5efa\u8bae\u4f7f\u7528\u66f4\u590d\u6742\u7684\u5bc6\u7801\u3002<br><code>CREATE USER 'superset'@'%' IDENTIFIED BY '\u5bc6\u7801';<\/code><br>\u8fd9\u91cc\u7684\u00a0<code>'%'<\/code>\u00a0\u8868\u793a\u7528\u6237\u53ef\u4ee5\u4ece\u4efb\u4f55\u4e3b\u673a\u8fde\u63a5\u5230\u00a0MariaDB \u670d\u52a1\u5668\u3002\u5982\u679c\u4f60\u5e0c\u671b\u9650\u5236\u7528\u6237\u53ea\u80fd\u4ece\u7279\u5b9a\u4e3b\u673a\u8fde\u63a5\uff0c\u53ef\u4ee5\u5c06\u00a0<code>'%'<\/code>\u00a0\u66ff\u6362\u4e3a\u5177\u4f53\u7684 IP \u5730\u5740\u6216\u4e3b\u673a\u540d\u3002<\/li>\n\n\n\n<li><strong>\u521b\u5efa\u6570\u636e\u5e93\uff08\u5982\u679c\u5c1a\u672a\u521b\u5efa\uff09<\/strong>\uff1a<br>\u5982\u679c\u6570\u636e\u5e93&nbsp;<code>TEMP<\/code>&nbsp;\u8fd8\u4e0d\u5b58\u5728\uff0c\u4f60\u9700\u8981\u5148\u521b\u5efa\u5b83\u3002<br><code>CREATE DATABASE TEMP;<\/code><\/li>\n\n\n\n<li><strong>\u6388\u4e88\u6743\u9650<\/strong>\uff1a<br>\u4f7f\u7528&nbsp;<code>GRANT<\/code>&nbsp;\u8bed\u53e5\u6765\u6388\u4e88&nbsp;<code>superset<\/code>&nbsp;\u7528\u6237\u5bf9&nbsp;<code>TEMP<\/code>&nbsp;\u6570\u636e\u5e93\u7684\u6240\u6709\u6743\uff08\u6216\u7279\u5b9a\u6743\u9650\uff09\u3002\u6240\u6709\u6743\u901a\u5e38\u610f\u5473\u7740\u7528\u6237\u5177\u6709\u5bf9\u8be5\u6570\u636e\u5e93\u7684\u6240\u6709\u6743\u9650\uff0c\u5305\u62ec\u521b\u5efa\u8868\u3001\u63d2\u5165\u6570\u636e\u3001\u66f4\u65b0\u6570\u636e\u548c\u5220\u9664\u6570\u636e\u7b49\u3002<br><code>GRANT ALL PRIVILEGES ON TEMP.* TO 'superset'@'%';<\/code><br>\u8fd9\u91cc\u7684&nbsp;<code>ALL PRIVILEGES<\/code>&nbsp;\u8868\u793a\u6388\u4e88\u6240\u6709\u6743\u9650\uff0c<code>TEMP.*<\/code>&nbsp;\u8868\u793a&nbsp;<code>TEMP<\/code>&nbsp;\u6570\u636e\u5e93\u4e2d\u7684\u6240\u6709\u5bf9\u8c61\uff08\u8868\u3001\u89c6\u56fe\u7b49\uff09\uff0c<code>'superset'@'%'<\/code>&nbsp;\u6307\u5b9a\u4e86\u7528\u6237\u548c\u4e3b\u673a\u3002<\/li>\n\n\n\n<li><strong>\u5237\u65b0\u6743\u9650<\/strong>\uff1a<br>\u867d\u7136 MariaDB \u901a\u5e38\u4f1a\u81ea\u52a8\u5237\u65b0\u6743\u9650\uff0c\u4f46\u51fa\u4e8e\u4e60\u60ef\uff0c\u4f60\u53ef\u4ee5\u6267\u884c&nbsp;<code>FLUSH PRIVILEGES<\/code>&nbsp;\u8bed\u53e5\u6765\u786e\u4fdd\u6743\u9650\u66f4\u6539\u7acb\u5373\u751f\u6548\u3002<br><code>FLUSH PRIVILEGES;<\/code><\/li>\n\n\n\n<li><strong>\u9a8c\u8bc1<\/strong>\uff1a<br>\u4f60\u53ef\u4ee5\u4f7f\u7528&nbsp;<code>SHOW GRANTS<\/code>&nbsp;\u8bed\u53e5\u6765\u9a8c\u8bc1&nbsp;<code>superset<\/code>&nbsp;\u7528\u6237\u7684\u6743\u9650\u3002<br><code>SHOW GRANTS FOR 'superset'@'%';<\/code><br>\u8fd9\u5c06\u663e\u793a&nbsp;<code>superset<\/code>&nbsp;\u7528\u6237\u88ab\u6388\u4e88\u7684\u6240\u6709\u6743\u9650\u3002<\/li>\n\n\n\n<li><strong>\u9000\u51fa MariaDB<\/strong>\uff1a<br>\u5b8c\u6210\u64cd\u4f5c\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528&nbsp;<code>exit<\/code>&nbsp;\u6216&nbsp;<code>quit<\/code>&nbsp;\u547d\u4ee4\u9000\u51fa MariaDB \u5ba2\u6237\u7aef\u3002<code><br>exit;<\/code><\/li>\n<\/ol>\n\n\n\n<p>\u8bf7\u786e\u4fdd\u5728\u5b9e\u9645\u73af\u5883\u4e2d\u4f7f\u7528\u5f3a\u5bc6\u7801\uff0c\u5e76\u6839\u636e\u5b89\u5168\u6700\u4f73\u5b9e\u8df5\u914d\u7f6e\u7528\u6237\u6743\u9650\u3002\u5982\u679c\u4f60\u5c06\u7528\u6237\u914d\u7f6e\u4e3a\u53ef\u4ee5\u4ece\u4efb\u4f55\u4e3b\u673a\u8fde\u63a5\uff0c\u8bf7\u786e\u4fdd\u4f60\u4e86\u89e3\u8fd9\u5e26\u6765\u7684\u5b89\u5168\u98ce\u9669\uff0c\u5e76\u8003\u8651\u4f7f\u7528\u9632\u706b\u5899\u6216\u5176\u4ed6\u5b89\u5168\u63aa\u65bd\u6765\u9650\u5236\u8bbf\u95ee\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5f00\u653e\u8fdc\u7a0b\u8bbf\u95ee<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/etc\/mysql\/mysql.conf.d\/mysqld.cnf\/50-server.cnf \n\u6216\u8005 \nvim \/etc\/mysql\/mariadb.conf.d\/50-server.cnf<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/telaker.cn\/wp-content\/uploads\/2024\/11\/image-14.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"572\" height=\"81\" data-original=\"https:\/\/telaker.cn\/wp-content\/uploads\/2024\/11\/image-14.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-236\"  sizes=\"auto, (max-width: 572px) 100vw, 572px\" \/><\/div><\/figure>\n\n\n\n<p>\u628a\u8fd9\u4e00\u884c\u8fdb\u884c\u6ce8\u91ca\uff0c\u518d\u91cd\u542fmysql\u5c31\u884c\u4e86<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo service mysqld restart<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 MySQL \u6570\u636e\u5e93\u4e2d\uff0c\u67e5\u770b\u7528\u6237\u4fe1\u606f\u901a\u5e38\u6d89\u53ca\u5230\u8bbf\u95ee\u7cfb\u7edf\u6570\u636e\u5e93\u4e2d\u7684\u7528\u6237\u8868\u3002\u5728 MySQL 5.7 \u53ca\u66f4\u9ad8\u7248\u672c\u4e2d [&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":[26],"class_list":["post-231","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-mysql"],"_links":{"self":[{"href":"https:\/\/telaker.cn\/index.php\/wp-json\/wp\/v2\/posts\/231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/telaker.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/telaker.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/telaker.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/telaker.cn\/index.php\/wp-json\/wp\/v2\/comments?post=231"}],"version-history":[{"count":0,"href":"https:\/\/telaker.cn\/index.php\/wp-json\/wp\/v2\/posts\/231\/revisions"}],"wp:attachment":[{"href":"https:\/\/telaker.cn\/index.php\/wp-json\/wp\/v2\/media?parent=231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/telaker.cn\/index.php\/wp-json\/wp\/v2\/categories?post=231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/telaker.cn\/index.php\/wp-json\/wp\/v2\/tags?post=231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}