{"id":232,"date":"2024-11-19T19:14:34","date_gmt":"2024-11-19T11:14:34","guid":{"rendered":"https:\/\/www.xxiaoteng.cn\/?p=232"},"modified":"2026-05-11T21:18:37","modified_gmt":"2026-05-11T13:18:37","slug":"%e4%b8%80%e9%94%ae%e5%ae%89%e8%a3%85mysql","status":"publish","type":"post","link":"https:\/\/www.xxiaoteng.cn\/?p=232","title":{"rendered":"\u4e00\u952e\u5b89\u88c5mysql"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >#!\/bin\/bash\n#1.\u5b89\u88c5\u4f9d\u8d56\u8f6f\u4ef6\necho &quot;\u6b63\u5728\u5b89\u88c5\u4f9d\u8d56\u8f6f\u4ef6...&quot;\nyum -y install libaio &amp;&gt; \/dev\/null\nif &#091; $? -ne 0 ];then\n    echo &quot;libaio\u5b89\u88c5\u5931\u8d25&quot;\n    exit 1\nfi\n#2.\u5224\u65ad\u662f\u5426\u6709\u538b\u7f29\u5305\uff0c\u5982\u679c\u6709\uff0c\u5219\u6267\u884c\u89e3\u538b\u7f29\u64cd\u4f5c\necho &quot;\u6b63\u5728\u5224\u65ad\u662f\u5426\u6709\u538b\u7f29\u5305\uff0c\u5982\u679c\u6709\u8fdb\u884c\u89e3\u538b\u7f29\u64cd\u4f5c...&quot;\nif &#091; -f mysql-8.0.40-linux-glibc2.17-x86_64.tar.xz ]; then\n    tar -xf mysql-8.0.40-linux-glibc2.17-x86_64.tar.xz\n    ls -l mysql-8.0.40-linux-glibc2.17-x86_64\nfi\n#3.\u5224\u65ad\u7cfb\u7edf\u4e2d\u662f\u5426\u5b89\u88c5\u8fc7mariadb\u8f6f\u4ef6\uff0c\u5982\u679c\u6709\u5bf9\u5176\u8fdb\u884c\u5378\u8f7d\u64cd\u4f5c\necho &quot;\u6b63\u5728\u5224\u65ad\u7cfb\u7edf\u4e2d\u662f\u5426\u5b89\u88c5\u8fc7mariadb\u8f6f\u4ef6\uff0c\u5982\u679c\u6709\u5bf9\u5176\u8fdb\u884c\u5378\u8f7d\u64cd\u4f5c...&quot;\nrpm -qa | grep mariadb | xargs -r dnf remove -y\n&#091; -f \/etc\/my.cnf ] &amp;&amp; rm -rf \/etc\/my.cnf\n#4.\u521b\u5efamysql\u7cfb\u7edf\u8d26\u53f7\nid mysql &amp;&gt; \/dev\/null\n&#091; $? -ne 0 ] &amp;&amp; useradd -r -s \/sbin\/nologin mysql\n#5.\u521b\u5efa\/export\/server\u76ee\u5f55\uff0c\u7136\u540e\u79fb\u52a8mysql\u538b\u7f29\u5305\u89e3\u538b\u540e\u7684\u6587\u4ef6\u5230\/export\/server\u76ee\u5f55\u4e0b\nrm -rf \/export\/server\nmkdir -p \/export\/server\nmv mysql-8.0.40-linux-glibc2.17-x86_64 \/export\/server\/mysql\n#6.\u8fdb\u5165mysql\u76ee\u5f55\uff0c\u5bf9\u5176\u8fdb\u884c\u521d\u59cb\u5316\u64cd\u4f5c\necho &quot;\u6b63\u5728\u8fdb\u5165mysql\u76ee\u5f55\uff0c\u5bf9\u5176\u8fdb\u884c\u521d\u59cb\u5316\u64cd\u4f5c...&quot;\ncd \/export\/server\/mysql\nbin\/mysqld --initialize --user=mysql --basedir=\/export\/server\/mysql --datadir=\/export\/server\/mysql\/data 2&gt;&amp;1 | tee \/tmp\/mysqld.log | grep password | awk &#039;{print $NF}&#039; &gt; \/tmp\/mysql_temp_password.txt\n#7.\u8bbe\u7f6essl\u52a0\u5bc6\u4f20\u8f93\u8fde\u63a5\nbin\/mysql_ssl_rsa_setup --datadir=\/export\/server\/mysql\/data &amp;&gt; \/dev\/null\n#8.\u8bbe\u7f6emy.cnf\u4e0emysqld.service\u6587\u4ef6\necho &quot;\u6b63\u5728\u8bbe\u7f6emy.cnf\u4e0emysqld.service\u6587\u4ef6...&quot;\ncat &gt; \/etc\/my.cnf &lt;&lt;EOF\n&#091;mysqld]\nport=3306\nbasedir=\/export\/server\/mysql\ndatadir=\/export\/server\/mysql\/data\nsocket=\/tmp\/mysql.sock\ncharacter_set_server=utf8\ncollation-server=utf8_unicode_ci\nEOF\n\ncat &gt; \/etc\/systemd\/system\/mysqld.service &lt;&lt;EOF\n&#091;Unit]\nDescription=MySQL Server\nAfter=network.target\n\n&#091;Service]\nUser=mysql\nGroup=mysql\nType=forking\n\n# MySQL \u6267\u884c\u547d\u4ee4\u53ca\u8def\u5f84\nExecStart=\/export\/server\/mysql\/bin\/mysqld --daemonize --pid-file=\/export\/server\/mysql\/data\/mysqld.pid\nExecStop=\/export\/server\/mysql\/bin\/mysqladmin --defaults-file=\/export\/server\/mysql\/my.cnf shutdown\n\n# Ensure MySQL has sufficient time to start up\nTimeoutSec=600\n\n# PID \u6587\u4ef6\u8def\u5f84\nPIDFile=\/export\/server\/mysql\/data\/mysqld.pid\n\n# Enable these options to auto-restart the service if it crashes\nRestart=on-failure\nRestartSec=5\n\n&#091;Install]\nWantedBy=multi-user.target\nEOF\n#9.\u5237\u65b0\u540e\u53f0\u670d\u52a1\uff0c\u7136\u540e\u542f\u52a8mysqld\necho &quot;\u6b63\u5728\u5237\u65b0\u540e\u53f0\u670d\u52a1\uff0c\u7136\u540e\u542f\u52a8mysqld...&quot;\nsystemctl daemon-reload\nsystemctl start mysqld\nsystemctl enable mysqld\n#10.\u91cd\u7f6emysql\u7ba1\u7406\u5458\u5bc6\u7801\u4e3a123456\necho &quot;\u6b63\u5728\u91cd\u7f6emysql\u7ba1\u7406\u5458\u5bc6\u7801...&quot;\ncd \/export\/server\/mysql\ntemp_password=`cat \/tmp\/mysql_temp_password.txt`\nbin\/mysqladmin -uroot password &#039;123456&#039; -p$temp_password\n#11.\u628amysql\u7684bin\u76ee\u5f55\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\u4e2d\necho &#039;export PATH=$PATH:\/export\/server\/mysql\/bin&#039; &gt;&gt; \/etc\/profile\nsource \/etc\/profile\n#12.\u89e3\u51b3mysql\u5ba2\u6237\u7aef\u9996\u6b21\u65e0\u6cd5\u767b\u5f55\u95ee\u9898\n&#091; ! -f \/lib64\/libncurses.so.5 ] &amp;&amp; ln -s \/lib64\/libncurses.so.6 \/lib64\/libncurses.so.5\n&#091; ! -f \/lib64\/libtinfo.so.5 ] &amp;&amp; ln -s \/lib64\/libtinfo.so.6 \/lib64\/libtinfo.so.5\n#13.\u5f39\u51fa\u63d0\u793a\uff0cMySQL\u5b89\u88c5\u6210\u529f\necho &quot;MySQL\u5b89\u88c5\u6210\u529f\uff0c\u8f6f\u4ef6\u5b89\u88c5\u8def\u5f84\uff1a\/export\/server\/mysql\uff0c\u6570\u636e\u5e93\u521d\u59cb\u5bc6\u7801\uff1a123456\uff01&quot;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,29],"tags":[],"class_list":["post-232","post","type-post","status-publish","format-standard","hentry","category-mysql","category-shell"],"_links":{"self":[{"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=\/wp\/v2\/posts\/232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=232"}],"version-history":[{"count":2,"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=\/wp\/v2\/posts\/232\/revisions"}],"predecessor-version":[{"id":234,"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=\/wp\/v2\/posts\/232\/revisions\/234"}],"wp:attachment":[{"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}