{"id":469,"date":"2021-07-28T19:19:11","date_gmt":"2021-07-28T11:19:11","guid":{"rendered":"https:\/\/egonlin.com\/?p=469"},"modified":"2022-04-06T20:14:45","modified_gmt":"2022-04-06T12:14:45","slug":"%e7%ac%ac%e4%ba%8c%e8%8a%82%ef%bc%9amysql%e5%a4%9a%e5%ae%9e%e4%be%8b","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=469","title":{"rendered":"\u7b2c\u4e8c\u8282\uff1amysql\u591a\u5b9e\u4f8b"},"content":{"rendered":"<h2>\u4e00\u3001mysql\u7684\u591a\u5b9e\u4f8b<\/h2>\n<pre><code class=\"language-bash\">NGINX\u591a\u5b9e\u4f8b\u5c31\u662f\u591a\u4e2a\u914d\u7f6e\u6587\u4ef6\nmysql\u591a\u5b9e\u4f8b\uff1a\u540c\u4e00\u4e2a\u8f6f\u4ef6\u542f\u52a8\u591a\u6b21\uff0c\u5c31\u662f\u591a\u4e2a\u8fdb\u7a0b\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u76d1\u542c\u7684\u7aef\u53e3\u4e0d\u540c\n    1.\u4e0d\u540c\u7684\u6570\u636e\u76ee\u5f55\n    2.\u4e0d\u540c\u7684\u7aef\u53e3\n    3.\u4e0d\u540c\u7684socket\u6587\u4ef6\n    4.\u4e0d\u540c\u7684\u65e5\u5fd7\u6587\u4ef6<\/code><\/pre>\n<h3>1.\u521b\u5efa\u591a\u4e2a\u6570\u636e\u76ee\u5f55<\/h3>\n<pre><code class=\"language-bash\">[root@db01 ~]# mkdir \/data\/{3307,3308,3309} -p<\/code><\/pre>\n<h3>2.\u51c6\u5907\u591a\u4e2a\u914d\u7f6e\u6587\u4ef6<\/h3>\n<pre><code class=\"language-bash\">[root@db01 data]# vim \/data\/3307\/my.cnf\n[mysqld]\nbasedir=\/service\/mysql\ndatadir=\/data\/3307\/data\nport=3307\nsocket=\/data\/3307\/mysql.sock\nlog-error=\/data\/3307\/data\/mysql.err\nlog-bin=\/data\/3307\/data\/mysql-bin\nserver_id=7\n\n-------------------------------------------\n\n[root@db01 data]# vim \/data\/3308\/my.cnf\n[mysqld]\nbasedir=\/service\/mysql\ndatadir=\/data\/3308\/data\nport=3308\nsocket=\/data\/3308\/mysql.sock\nlog-error=\/data\/3308\/data\/mysql.err\nlog-bin=\/data\/3308\/data\/mysql-bin\nserver_id=8\n\n--------------------------------------------\n\n[root@db01 data]# vim \/data\/3309\/my.cnf \n[mysqld]\nbasedir=\/service\/mysql\ndatadir=\/data\/3309\/data\nport=3309\nsocket=\/data\/3309\/mysql.sock\nlog-error=\/data\/3309\/data\/mysql.err\nlog-bin=\/data\/3309\/data\/mysql-bin\nserver_id=9<\/code><\/pre>\n<h3>3.\u521d\u59cb\u5316\u591a\u5957\u6570\u636e\u76ee\u5f55<\/h3>\n<pre><code class=\"language-bash\">[root@db01 scripts]# .\/mysql_install_db --defaults-file=\/data\/3307\/my.cnf --user=mysql --basedir=\/service\/mysql --datadir=\/data\/3307\/data\n\n[root@db01 scripts]# .\/mysql_install_db --defaults-file=\/data\/3308\/my.cnf --user=mysql --basedir=\/service\/mysql --datadir=\/data\/3308\/data\n\n[root@db01 scripts]# .\/mysql_install_db --defaults-file=\/data\/3309\/my.cnf --user=mysql --basedir=\/service\/mysql --datadir=\/data\/3309\/data\n\n#\u4f7f\u7528tree\u53ef\u4ee5\u67e5\u770b\n[root@db01 scripts]# tree -L 3 \/data<\/code><\/pre>\n<h3>4.\u6388\u6743\u76ee\u5f55<\/h3>\n<pre><code class=\"language-bash\">[root@db01 scripts]# chown -R mysql.mysql \/data<\/code><\/pre>\n<h3>5.\u542f\u52a8\u6570\u636e\u5e93<\/h3>\n<pre><code class=\"language-bash\">[root@db01 scripts]# mysqld_safe --defaults-file=\/data\/3307\/my.cnf &amp;\n[root@db01 scripts]# mysqld_safe --defaults-file=\/data\/3308\/my.cnf &amp;\n[root@db01 scripts]# mysqld_safe --defaults-file=\/data\/3309\/my.cnf &amp;<\/code><\/pre>\n<h3>6.\u68c0\u67e5\u542f\u52a8<\/h3>\n<pre><code class=\"language-bash\">[root@db01 scripts]# netstat -lntup|grep 330\ntcp6       0      0 :::3307                 :::*                    LISTEN      25550\/mysqld        \ntcp6       0      0 :::3308                 :::*                    LISTEN      25722\/mysqld        \ntcp6       0      0 :::3309                 :::*                    LISTEN      25894\/mysqld     <\/code><\/pre>\n<h3>7.\u591a\u5b9e\u4f8b\u8bbe\u7f6e\u5bc6\u7801<\/h3>\n<pre><code class=\"language-bash\">[root@db01 scripts]# mysqladmin -uroot -S \/data\/3307\/mysql.sock password &#039;3307&#039;\n[root@db01 scripts]# mysqladmin -uroot -S \/data\/3308\/mysql.sock password &#039;3308&#039;\n[root@db01 scripts]# mysqladmin -uroot -S \/data\/3309\/mysql.sock password &#039;3309&#039;<\/code><\/pre>\n<h3>8.\u591a\u5b9e\u4f8b\u9a8c\u8bc1<\/h3>\n<pre><code>[root@db01 scripts]# mysql -uroot -p3307 -S \/data\/3307\/mysql.sock -e &quot;show variables like &#039;server_id&#039;;&quot;\nWarning: Using a password on the command line interface can be insecure.\n+---------------+-------+\n| Variable_name | Value |\n+---------------+-------+\n| server_id     | 7     |\n+---------------+-------+\n\n[root@db01 scripts]# mysql -uroot -p3308 -S \/data\/3308\/mysql.sock -e &quot;show variables like &#039;server_id&#039;;&quot;\nWarning: Using a password on the command line interface can be insecure.\n+---------------+-------+\n| Variable_name | Value |\n+---------------+-------+\n| server_id     | 8     |\n+---------------+-------+\n\n[root@db01 scripts]# mysql -uroot -p3309 -S \/data\/3309\/mysql.sock -e &quot;show variables like &#039;server_id&#039;;&quot;\nWarning: Using a password on the command line interface can be insecure.\n+---------------+-------+\n| Variable_name | Value |\n+---------------+-------+\n| server_id     | 9     |\n+---------------+-------+<\/code><\/pre>\n<h3>9.\u8fde\u63a5\u591a\u5b9e\u4f8b\u5c0f\u6280\u5de7<\/h3>\n<pre><code class=\"language-bash\">[root@db01 scripts]# vim \/usr\/bin\/mysql3309\nmysql -uroot -p3309 -S \/data\/3309\/mysql.sock\n[root@db01 scripts]# vim \/usr\/bin\/mysql3308\nmysql -uroot -p3308 -S \/data\/3308\/mysql.sock\n[root@db01 scripts]# vim \/usr\/bin\/mysql3307\nmysql -uroot -p3307 -S \/data\/3307\/mysql.sock\n\n[root@db01 scripts]# chmod +x \/usr\/bin\/mysql*<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001mysql\u7684\u591a\u5b9e\u4f8b NGINX\u591a\u5b9e\u4f8b\u5c31\u662f\u591a\u4e2a\u914d\u7f6e\u6587\u4ef6 mysql\u591a\u5b9e\u4f8b\uff1a\u540c\u4e00\u4e2a\u8f6f\u4ef6\u542f\u52a8\u591a\u6b21\uff0c\u5c31\u662f\u591a\u4e2a\u8fdb\u7a0b\uff0c [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":467,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[78],"tags":[21,19,99,22,100,20],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/469"}],"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=469"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/469\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/media\/467"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}