{"id":6243,"date":"2024-11-14T10:16:07","date_gmt":"2024-11-14T02:16:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6243\/"},"modified":"2024-11-14T10:16:07","modified_gmt":"2024-11-14T02:16:07","slug":"%e5%a6%82%e4%bd%95%e9%85%8d%e7%bd%aemysql%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6243\/","title":{"rendered":"\u5982\u4f55\u914d\u7f6emysql\u6570\u636e\u5e93"},"content":{"rendered":"<blockquote><p>\n  mysql\u6570\u636e\u5e93\u7684\u914d\u7f6e\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u5b89\u88c5mysql\u5e76\u8bbe\u7f6eroot\u7528\u6237\u548c\u5bc6\u7801\u3002\u7f16\u8f91my.cnf\u914d\u7f6e\u6587\u4ef6\u4ee5\u914d\u7f6e\u7aef\u53e3\u3001\u76d1\u542c\u5730\u5740\u3001\u6700\u5927\u8fde\u63a5\u6570\u548c\u65e5\u5fd7\u4f4d\u7f6e\u3002\u8bbe\u7f6emysql_home\u548cpath\u73af\u5883\u53d8\u91cf\u3002\u542f\u52a8mysql\u670d\u52a1\u5668\u3002\u521b\u5efa\u6570\u636e\u5e93\u3001\u7528\u6237\u5e76\u6388\u4e88\u6743\u9650\u3002\u5b9a\u671f\u5907\u4efd\u548c\u6062\u590d\u6570\u636e\u5e93\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/15\/2024061516062492427.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u914d\u7f6emysql\u6570\u636e\u5e93\u63d2\u56fe\" alt=\"\u5982\u4f55\u914d\u7f6emysql\u6570\u636e\u5e93\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL\u6570\u636e\u5e93\u7684\u914d\u7f6e\u65b9\u6cd5<\/strong><\/p>\n<p>\u914d\u7f6eMySQL\u6570\u636e\u5e93\u9700\u8981\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u5b89\u88c5MySQL<\/strong><\/p>\n<ul>\n<li>\u901a\u8fc7\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5MySQL\u3002<\/li>\n<li>\u786e\u4fdd\u5df2\u8bbe\u7f6e\u597droot\u7528\u6237\u548c\u5bc6\u7801\u3002<\/li>\n<\/ul>\n<p><strong>2. \u914d\u7f6emy.cnf\u6587\u4ef6<\/strong><\/p>\n<ul>\n<li>\u627e\u5230my.cnf\u914d\u7f6e\u6587\u4ef6\uff08\u901a\u5e38\u4f4d\u4e8e\/etc\/\/my.cnf\uff09\u3002<\/li>\n<li>\u6253\u5f00\u8be5\u6587\u4ef6\u5e76\u7f16\u8f91\u4ee5\u4e0b\u8bbe\u7f6e\uff1a<\/li>\n<\/ul>\n<pre># MySQL\u670d\u52a1\u5668\u7aef\u53e3\nport = 3306\n\n# MySQL\u670d\u52a1\u5668\u76d1\u542c\u5730\u5740\nbind-address = 127.0.0.1\n\n# MySQL\u7684\u6700\u5927\u8fde\u63a5\u6570\nmax_connections = 100\n\n# MySQL\u7684\u65e5\u5fd7\u6587\u4ef6\u4f4d\u7f6e\nlog-error = \/var\/log\/mysql\/mysql.err\n\n# MySQL\u7684\u6162\u67e5\u8be2\u65e5\u5fd7\u6587\u4ef6\u4f4d\u7f6e\nslow-query-log = 1\nslow-query-log-file = \/var\/log\/mysql\/mysql-slow.log<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/strong><\/p>\n<ul>\n<li>\u6dfb\u52a0\u4ee5\u4e0b\u73af\u5883\u53d8\u91cf\uff1a<\/li>\n<\/ul>\n<pre>export MYSQL_HOME=\/usr\/local\/mysql\nexport PATH=$MYSQL_HOME\/bin:$PATH<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u542f\u52a8MySQL\u670d\u52a1\u5668<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8MySQL\u670d\u52a1\u5668\uff1a<\/li>\n<\/ul>\n<pre>mysqld --defaults-file=\/etc\/mysql\/my.cnf start<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u521b\u5efa\u6570\u636e\u5e93\u548c\u7528\u6237<\/strong><\/p>\n<ul>\n<li>\u767b\u5f55MySQL\u63a7\u5236\u53f0\uff1a<\/li>\n<\/ul>\n<pre>mysql -u root -p<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u636e\u5e93\uff1a<\/li>\n<\/ul>\n<pre>CREATE DATABASE my_database;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7528\u6237\uff1a<\/li>\n<\/ul>\n<pre>CREATE USER my_user IDENTIFIED BY 'my_password';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u6388\u4e88\u7528\u6237\u6743\u9650\uff1a<\/li>\n<\/ul>\n<pre>GRANT ALL PRIVILEGES ON my_database.* TO my_user;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>6. \u5907\u4efd\u548c\u6062\u590d<\/strong><\/p>\n<ul>\n<li>\u5b9a\u671f\u5907\u4efd\u6570\u636e\u5e93\uff1a<\/li>\n<\/ul>\n<pre>mysqldump -u root -p my_database &gt; my_database_backup.sql<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u6062\u590d\u6570\u636e\u5e93\uff1a<\/li>\n<\/ul>\n<pre>mysql -u root -p my_database &lt; my_database_backup.sql<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u914d\u7f6e\u6570\u636e\u5e93\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>mysql\u6570\u636e\u5e93\u7684\u914d\u7f6e\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u5b89\u88c5mysql\u5e76\u8bbe\u7f6eroot\u7528\u6237\u548c\u5bc6\u7801\u3002\u7f16\u8f91my.cnf\u914d\u7f6e\u6587\u4ef6\u4ee5\u914d\u7f6e\u7aef\u53e3\u3001\u76d1\u542c\u5730\u5740\u3001\u6700\u5927\u8fde\u63a5\u6570\u548c\u65e5\u5fd7\u4f4d\u7f6e\u3002\u8bbe\u7f6emysql_home\u548cpath\u73af\u5883\u53d8\u91cf\u3002\u542f\u52a8mysql\u670d\u52a1\u5668\u3002\u521b\u5efa\u6570\u636e\u5e93\u3001\u7528\u6237\u5e76\u6388\u4e88\u6743\u9650\u3002\u5b9a\u671f\u5907\u4efd\u548c\u6062\u590d\u6570\u636e\u5e93\u3002 MySQL\u6570\u636e\u5e93\u7684\u914d\u7f6e\u65b9\u6cd5 \u914d\u7f6eMySQL\u6570\u636e\u5e93\u9700\u8981\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u5b89\u88c5MySQL \u901a\u8fc7\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5MySQL\u3002 \u786e\u4fdd\u5df2\u8bbe\u7f6e\u597droot\u7528\u6237\u548c\u5bc6\u7801\u3002 2. \u914d\u7f6emy.cnf\u6587\u4ef6 \u627e\u5230my.cnf\u914d\u7f6e\u6587\u4ef6\uff08\u901a\u5e38\u4f4d\u4e8e\/etc\/\/my.cnf\uff09\u3002 \u6253\u5f00\u8be5\u6587\u4ef6\u5e76\u7f16\u8f91\u4ee5\u4e0b\u8bbe\u7f6e\uff1a # MySQL\u670d\u52a1\u5668\u7aef\u53e3 port = 3306 # MySQL\u670d\u52a1\u5668\u76d1\u542c\u5730\u5740 bind-address = 127.0.0.1 # MySQL\u7684\u6700\u5927\u8fde\u63a5\u6570 max_connections = 100 # MySQL\u7684\u65e5\u5fd7\u6587\u4ef6\u4f4d\u7f6e log-error = \/var\/log\/mysql\/mysql.err # MySQL\u7684\u6162\u67e5\u8be2\u65e5\u5fd7\u6587\u4ef6\u4f4d\u7f6e slow-query-log = 1 slow-query-log-file = \/var\/log\/mysql\/mysql-slow.log \u767b\u5f55\u540e\u590d\u5236 3. \u8bbe\u7f6e\u73af\u5883\u53d8\u91cf \u6dfb\u52a0\u4ee5\u4e0b\u73af\u5883\u53d8\u91cf\uff1a export MYSQL_HOME=\/usr\/local\/mysql export PATH=$MYSQL_HOME\/bin:$PATH \u767b\u5f55\u540e\u590d\u5236 4. \u542f\u52a8MySQL\u670d\u52a1\u5668 \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8MySQL\u670d\u52a1\u5668\uff1a mysqld &#8211;defaults-file=\/etc\/mysql\/my.cnf start \u767b\u5f55\u540e\u590d\u5236 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6243","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6243"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6243\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}