{"id":51,"date":"2021-03-13T12:14:18","date_gmt":"2021-03-13T04:14:18","guid":{"rendered":"http:\/\/daishen.ltd\/?p=51"},"modified":"2021-03-13T12:14:18","modified_gmt":"2021-03-13T04:14:18","slug":"mysql%e5%9f%ba%e7%a1%80%e7%ae%a1%e7%90%86","status":"publish","type":"post","link":"https:\/\/daishen.ltd\/?p=51","title":{"rendered":"MySQL\u57fa\u7840\u7ba1\u7406"},"content":{"rendered":"<p><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width initial-scale=1\"><br \/>\n<title>MySQL\u57fa\u7840\u7ba1\u7406<\/title><\/p>\n<h4>MySQL\u542f\u52a8\u548c\u5173\u95ed<\/h4>\n<h5>\u65e5\u5e38\u542f\u505c<\/h5>\n<pre><code class=\"language-shell\" lang=\"shell\">mysql.server start  ---&gt;  mysql_safe ---&gt;mysqld\nsystemctl start mysqld ---&gt; mysqld\n\n\u9700\u8981\u4f9d\u8d56\u4e8e\/etc\/my.cnf\n<\/code><\/pre>\n<h5>\u7ef4\u62a4\u6027\u7684\u4efb\u52a1<\/h5>\n<pre><code class=\"language-shell\" lang=\"shell\">mysqld_safe --skip-grant-tables --skip-networking &amp;\n\n\u6211\u4eec\u4e00\u822c\u4f1a\u5c06\u6211\u4eec\u9700\u8981\u7684\u53c2\u6570\u4e34\u65f6\u52a0\u5230\u547d\u4ee4\u884c.\n\u4e5f\u4f1a\u8bfb\u53d6\/etc\/my.cnf\u7684\u5185\u5bb9,\u4f46\u662f\u5982\u679c\u51b2\u7a81,\u547d\u4ee4\u884c\u4f18\u5148\u7ea7\u6700\u9ad8\n\nmysqld_safe &amp;                     \u5f00\u542f\u6570\u636e\u5e93\u65b9\u6cd5\u4e4b\u4e00\nmysqladmin -uroot -p123 shutdown  \u4ee5\u4e0a\u5f00\u542f\u65b9\u6cd5\uff0c\u53ea\u80fd\u5982\u6b64\u5173\u95ed\n<\/code><\/pre>\n<h4>\u521d\u59cb\u5316\u914d\u7f6e<\/h4>\n<h5>\u4f5c\u7528<\/h5>\n<p>1.\u5f71\u54cd\u6570\u636e\u5e93\u542f\u52a8<br \/>\n2.\u5f71\u54cd\u5ba2\u6237\u7aef\u7684\u5404\u9879\u529f\u80fd<\/p>\n<h5>\u521d\u59cb\u5316\u914d\u7f6e\u65b9\u6cd5<\/h5>\n<p>1.\u521d\u59cb\u5316\u914d\u7f6e\u6587\u4ef6\uff08\/etc\/my.cnf\uff09<br \/>\n2.\u542f\u52a8\u547d\u4ee4\u884c\u4e0a\u8fdb\u884c\u8bbe\u7f6e\uff08\u5982\uff1amysqld_safe mysqld\uff09<br \/>\n3.\u9884\u7f16\u8bd1\u65f6\u8bbe\u7f6e\uff08\u4ec5\u9650\u4e8e\u7f16\u8bd1\u5b89\u88c5\u65f6\u8bbe\u7f6e\uff09<\/p>\n<h5>\u521d\u59cb\u5316\u914d\u7f6e\u6587\u4ef6\u7684\u4e66\u5199\u683c\u5f0f<\/h5>\n<pre><code>[\u6807\u7b7e]\nXXX=XXX\n[\u6807\u7b7e]\nXXX=XXX\n<\/code><\/pre>\n<h5>\u914d\u7f6e\u6587\u4ef6\u7684\u6807\u7b7e\u5f52\u7c7b<\/h5>\n<pre><code>\u670d\u52a1\u5668\u7aef\n[mysqld]\n[mysqld_safe]\n[server]\n\u5ba2\u6237\u7aef\n[mysql]\n[mysqladmin]\n[mysqldump]\n[client]\n<\/code><\/pre>\n<h5>\u914d\u7f6e\u6587\u4ef6\u8bbe\u7f6e\u6837\u677f<\/h5>\n<pre><code class=\"language-mysql\" lang=\"mysql\">#\u670d\u52a1\u5668\u7aef\n[mysqld]\n#\u7528\u6237\nuser=mysql\n#\u8f6f\u4ef6\u5b89\u88c5\u76ee\u5f55\nbasedir=\/application\/mysql \n#\u6570\u636e\u8def\u5f84\ndatadir=\/data\/mysql\/data\n#socket\u6587\u4ef6\u4f4d\u7f6e\nsocket=\/tmp\/mysql.sock\n#\u670d\u52a1\u5668id\u53f7\nserver_id=6\n#\u7aef\u53e3\u53f7\nport=3306\n\n#\u5ba2\u6237\u7aef\u914d\u7f6e\n[mysql]\n##socket\u6587\u4ef6\u4f4d\u7f6e\nsocket=\/tmp\/mysql.sock\n<\/code><\/pre>\n<h5>\u914d\u7f6e\u6587\u4ef6\u8bfb\u53d6\u987a\u5e8f<\/h5>\n<pre><code>\/etc\/my.cnf \/etc\/mysql\/my.cnf \/usr\/local\/mysql\/etc\/my.cnf ~\/.my.cnf \n\n\u5b9e\u9645\u5e94\u7528\u914d\u7f6e\u4ee5\u6700\u540e\u8bfb\u53d6\u7684\u4e3a\u51c6\n<\/code><\/pre>\n<h5>\u5f3a\u5236\u4f7f\u7528\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6<\/h5>\n<pre><code>mysqld_safe  --defaults-file=etc\/my.cnf &amp;\n<\/code><\/pre>\n<h4>MySQL\u8fde\u63a5\u7ba1\u7406<\/h4>\n<h5>MySQL\u547d\u4ee4<\/h5>\n<pre><code class=\"language-shell\" lang=\"shell\">\u6ce8\u610f\uff1a\u63d0\u524d\u628a\u7528\u6237\u6388\u6743\u505a\u597d\ngrant all on *.* to root@'10.0.0.%' identified by '1';\nTCP\/IP:\nmysql -uroot -p -h 10.0.0.51 -P3306\n\nScoket:\nmysql -uroot -p -S \/tmp\/mysql.sock\n<\/code><\/pre>\n<h4>\u591a\u5b9e\u4f8b\u7ba1\u7406<\/h4>\n<h5>\u51c6\u5907\u591a\u4e2a\u76ee\u5f55<\/h5>\n<pre><code class=\"language-shell\" lang=\"shell\">mkdir -p \/data\/330{7,8,9}\/data\n<\/code><\/pre>\n<h5>\u51c6\u5907\u914d\u7f6e\u6587\u4ef6<\/h5>\n<pre><code>cat &gt; \/data\/3307\/my.cnf &lt;&lt;EOF\n#\u670d\u52a1\u5668\u7aef\n[mysqld]\n#\u7528\u6237\nuser=mysql\n#\u8f6f\u4ef6\u5b89\u88c5\u76ee\u5f55\nbasedir=\/application\/mysql \n#\u6570\u636e\u8def\u5f84\ndatadir=\/data\/3307\/data\n#socket\u6587\u4ef6\u4f4d\u7f6e\nsocket=\/data\/3307\/mysql.sock\n#\u670d\u52a1\u5668id\u53f7\nserver_id=7\n#\u7aef\u53e3\u53f7\nport=3307\nlog_bin=\/data\/3307\/mysql-bin\nlog_error=\/data\/3307\/mysql.log\nEOF\n<\/code><\/pre>\n<h5>\u521d\u59cb\u5316\u4e09\u5957\u6570\u636e<\/h5>\n<pre><code class=\"language-shell\" lang=\"shell\">mv \/etc\/my.cnf \/etc\/my.cnf.bak\nmysqld --initialize-insecure --user=mysql --datadir=\/data\/3307\/data --basedir=\/application\/mysql\n\n<\/code><\/pre>\n<h5>systemd\u7ba1\u7406\u591a\u5b9e\u4f8b<\/h5>\n<pre><code class=\"language-shell\" lang=\"shell\"> cd \/etc\/systend\/system\n cp mysqld.service mysqld3307.serveice\n cp mysqld.service mysqld3308.serveice\n cp mysqld.service mysqld3309.serveice\n \n vim mysqld3307.serveice\n #\u4fee\u6539\u4e3a\n ExecStart=\/application\/mysql\/bin\/mysqld --defaults-file=\/data\/3307\/my.cnf\n \n  \n vim mysqld3308.serveice\n #\u4fee\u6539\u4e3a\n ExecStart=\/application\/mysql\/bin\/mysqld --defaults-file=\/data\/3308\/my.cnf\n \n \n vim mysqld3309.serveice\n #\u4fee\u6539\u4e3a\n ExecStart=\/application\/mysql\/bin\/mysqld --defaults-file=\/data\/3309\/my.cnf\n<\/code><\/pre>\n<h5>\u6388\u6743<\/h5>\n<pre><code class=\"language-shell\" lang=\"shell\">chown -R mysql.mysql \/data\/*\n<\/code><\/pre>\n<h5>\u542f\u52a8\u5b9e\u4f8b<\/h5>\n<pre><code class=\"language-shell\" lang=\"shell\">systemctl start mysqld3307.service\nsystemctl start mysqld3308.service\nsystemctl start mysqld3309.service\n<\/code><\/pre>\n<h5>\u9a8c\u8bc1\u591a\u5b9e\u4f8b<\/h5>\n<pre><code class=\"language-shell\" lang=\"shell\">netstat -lnp|grep 330  \n\ntcp6       0      0 :::3306                 :::*                    LISTEN      15017\/mysqld        \ntcp6       0      0 :::3307                 :::*                    LISTEN      52316\/mysqld        \ntcp6       0      0 :::3308                 :::*                    LISTEN      52363\/mysqld        \ntcp6       0      0 :::3309                 :::*                    LISTEN      52408\/mysqld        \nunix  2      [ ACC ]     STREAM     LISTENING     133934   52316\/mysqld         \/data\/3307\/mysql.sock\nunix  2      [ ACC ]     STREAM     LISTENING     134184   52408\/mysqld         \/data\/3309\/mysql.sock\nunix  2      [ ACC ]     STREAM     LISTENING     134059   52363\/mysqld         \/data\/3308\/mysql.sock\n<\/code><\/pre>\n<h5>\u8fde\u63a5\u5b9e\u4f8b<\/h5>\n<pre><code class=\"language-shell\" lang=\"shell\">mysql -uroot -p -S \/data\/3307\/mysql.sock\nmysql -uroot -p -S \/data\/3308\/mysql.sock\nmysql -uroot -p -S \/data\/3309\/mysql.sock\n\nmysql -uroot -p  -P3307\nmysql -uroot -p  -P3308\nmysql -uroot -p  -P3309\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL\u57fa\u7840\u7ba1\u7406 MySQL\u542f\u52a8\u548c\u5173\u95ed \u65e5\u5e38\u542f\u505c mysql.server start &#8212;&gt; my [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-51","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/daishen.ltd\/index.php?rest_route=\/wp\/v2\/posts\/51","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daishen.ltd\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daishen.ltd\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daishen.ltd\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/daishen.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=51"}],"version-history":[{"count":1,"href":"https:\/\/daishen.ltd\/index.php?rest_route=\/wp\/v2\/posts\/51\/revisions"}],"predecessor-version":[{"id":52,"href":"https:\/\/daishen.ltd\/index.php?rest_route=\/wp\/v2\/posts\/51\/revisions\/52"}],"wp:attachment":[{"href":"https:\/\/daishen.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daishen.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daishen.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}