{"id":7436,"date":"2026-06-19T09:02:15","date_gmt":"2026-06-19T01:02:15","guid":{"rendered":"https:\/\/silubaba.com.cn\/?p=7436"},"modified":"2026-06-19T09:02:16","modified_gmt":"2026-06-19T01:02:16","slug":"%e6%89%b9%e9%87%8f%e5%a4%9a%e6%9c%8d%e5%8a%a1%e5%99%a8-mysql-%e5%90%8c%e6%97%b6%e6%89%a7%e8%a1%8c-sql-%e8%84%9a%e6%9c%ac%ef%bc%8850-%e5%8f%b0%e5%b9%b6%e5%8f%91%e5%90%8c%e6%ad%a5%e6%89%a7%e8%a1%8c","status":"publish","type":"post","link":"https:\/\/silubaba.com.cn\/?p=7436","title":{"rendered":"\u6279\u91cf\u591a\u670d\u52a1\u5668 MySQL \u540c\u65f6\u6267\u884c SQL \u811a\u672c\uff0850 \u53f0\u5e76\u53d1\u540c\u6b65\u6267\u884c\uff09"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\"><\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e24\u79cd\u65b9\u6848<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u65b9\u6848 A\uff1a\u5e26\u8d26\u53f7\u5bc6\u7801\u660e\u6587\uff0c\u5feb\u901f\u5373\u7528\uff08\u6d4b\u8bd5 \/ \u5185\u7f51\uff09<\/li>\n\n\n\n<li>\u65b9\u6848 B\uff1a\u672c\u5730 my.cnf \u514d\u5bc6\u914d\u7f6e\uff08\u751f\u4ea7\u63a8\u8350\uff0c\u65e0\u660e\u6587\u5bc6\u7801\uff09 \u529f\u80fd\uff1a50 \u53f0 MySQL<strong>\u540c\u4e00\u65f6\u523b\u5e76\u53d1\u6267\u884c\u540c\u4e00\u6761 \/ \u540c\u4e00\u6bb5 SQL<\/strong>\uff0c\u6240\u6709\u5e93\u540c\u65f6\u64cd\u4f5c<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u4e3b\u673a\u6e05\u5355\u914d\u7f6e mysql_hosts.list<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u548c\u811a\u672c\u653e\u540c\u4e00\u76ee\u5f55\uff0c\u4e00\u884c\u4e00\u53f0 MySQL \u8282\u70b9\uff0c\u683c\u5f0f\uff1a<code>IP \u7aef\u53e3 mysql\u7528\u6237 mysql\u5bc6\u7801 \u6570\u636e\u5e93\u540d<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">plaintext<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u793a\u4f8b\uff0c\u586b\u6ee150\u53f0\n10.0.0.10 3306 root Mysql@123 test_db\n10.0.0.11 3306 root Mysql@123 test_db\n10.0.0.12 3306 root Mysql@123 test_db\n#...\u7ee7\u7eed\u6dfb\u52a0\u81f350\u53f0\u670d\u52a1\u5668\n# #\u5f00\u5934\u4e3a\u6ce8\u91ca\u884c\uff0c\u811a\u672c\u81ea\u52a8\u5ffd\u7565\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u6279\u91cf\u5e76\u53d1\u6267\u884c MySQL SQL \u811a\u672c batch_mysql_exec.sh<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">bash<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# \u591a\u670d\u52a1\u5668MySQL\u540c\u4e00\u65f6\u95f4\u5e76\u53d1\u6267\u884cSQL\nHOST_LIST=\".\/mysql_hosts.list\"\n# ====================== \u8fd9\u91cc\u4fee\u6539\u8981\u6267\u884c\u7684SQL ======================\n# \u793a\u4f8b\uff1a\u5efa\u8868\u3001\u66f4\u65b0\u3001\u65b0\u589e\u7d22\u5f15\u3001\u6570\u636e\u540c\u6b65\u8bed\u53e5\uff0c\u591a\u6761\u7528;\u5206\u9694\nSQL_CONTENT=\"\nSET NAMES utf8mb4;\nUPDATE sys_user SET status=1 WHERE create_time&lt;'2026-01-01';\nALTER TABLE order_info ADD INDEX idx_create_time(create_time);\nSELECT COUNT(*) FROM sys_user;\n\"\n# \u5982\u9700\u6267\u884c\u5916\u90e8sql\u6587\u4ef6\uff0c\u66ff\u6362\u4e0a\u9762\u4e3a\u8bfb\u53d6\u6587\u4ef6\uff1aSQL_CONTENT=$(cat .\/sync.sql)\n# =================================================================\n\n# \u5e76\u53d1\u6570\uff0c50\u53f0\u76f4\u63a5\u5f0050\u5e76\u53d1\u540c\u65f6\u6267\u884c\nMAX_TASK=50\n# MySQL\u8fde\u63a5\u8d85\u65f6\nCONNECT_TIMEOUT=8\n\n# \u6821\u9a8c\u4e3b\u673a\u6587\u4ef6\nif &#91; ! -f \"${HOST_LIST}\" ];then\n    echo \"\u9519\u8bef\uff1a${HOST_LIST} \u6587\u4ef6\u4e0d\u5b58\u5728\uff0c\u8bf7\u521b\u5efa\u914d\u7f6e\u670d\u52a1\u5668\u4fe1\u606f\"\n    exit 1\nfi\n\n# \u6821\u9a8cmysql\u5ba2\u6237\u7aef\u662f\u5426\u5b58\u5728\nif ! command -v mysql &amp;&gt; \/dev\/null;then\n    echo \"\u9519\u8bef\uff1a\u672c\u673a\u672a\u5b89\u88c5mysql\u5ba2\u6237\u7aef\uff0c\u8bf7\u5b89\u88c5\uff1ayum install mysql -y \/ apt install mysql-client -y\"\n    exit 1\nfi\n\necho \"==============================================\"\necho \"\u6279\u91cfMySQL\u540c\u6b65\u6267\u884c\u542f\u52a8\uff0c\u5e76\u53d1\uff1a${MAX_TASK}\"\necho \"\u5f85\u6267\u884cSQL\uff1a\"\necho \"${SQL_CONTENT}\"\necho \"==============================================\"\n\n# \u5faa\u73af\u904d\u5386\u6240\u6709mysql\u8282\u70b9\nwhile read line\ndo\n    # \u8df3\u8fc7\u7a7a\u884c\/\u6ce8\u91ca\n    &#91;&#91; -z \"$line\" || \"$line\" =~ ^# ]] &amp;&amp; continue\n    # \u62c6\u5206\u5b57\u6bb5\n    M_IP=$(echo $line | awk '{print $1}')\n    M_PORT=$(echo $line | awk '{print $2}')\n    M_USER=$(echo $line | awk '{print $3}')\n    M_PASS=$(echo $line | awk '{print $4}')\n    M_DB=$(echo $line | awk '{print $5}')\n\n    # \u540e\u53f0\u5e76\u53d1\u6267\u884c\uff0c\u6240\u6709\u670d\u52a1\u5668\u51e0\u4e4e\u540c\u4e00\u65f6\u95f4\u53d1\u8d77\u8bf7\u6c42\n    (\n        echo -e \"\\n===== MySQL\u8282\u70b9 ${M_IP}:${M_PORT} \u6267\u884c\u65e5\u5fd7 =====\"\n        mysql \\\n        -h${M_IP} \\\n        -P${M_PORT} \\\n        -u${M_USER} \\\n        -p${M_PASS} \\\n        --connect-timeout=${CONNECT_TIMEOUT} \\\n        ${M_DB} -e \"${SQL_CONTENT}\"\n\n        if &#91; $? -eq 0 ];then\n            echo \"&#91;${M_IP}] SQL\u6267\u884c\u6210\u529f\"\n        else\n            echo \"&#91;${M_IP}] SQL\u6267\u884c\u5931\u8d25\uff01\u68c0\u67e5\u7f51\u7edc\/\u8d26\u53f7\/SQL\u8bed\u6cd5\"\n        fi\n    ) &amp;\n\n    # \u63a7\u5236\u5e76\u53d1\u6570\u91cf\uff0c\u9632\u6b62\u672c\u5730\u8fdb\u7a0b\u6253\u6ee1\n    RUN_NUM=$(jobs -r | wc -l)\n    while &#91; ${RUN_NUM} -ge ${MAX_TASK} ];do\n        sleep 0.2\n        RUN_NUM=$(jobs -r | wc -l)\n    done\ndone &lt; ${HOST_LIST}\n\n# \u7b49\u5f85\u5168\u90e8\u540e\u53f0mysql\u8fdb\u7a0b\u6267\u884c\u5b8c\u6bd5\nwait\necho -e \"\\n==============================================\"\necho \"\u5168\u90e8MySQL\u670d\u52a1\u5668SQL\u6267\u884c\u5b8c\u6210\uff01\"\necho \"==============================================\"\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u6267\u884c\u5916\u90e8 SQL \u6587\u4ef6\uff08\u5927\u6279\u91cf\u540c\u6b65\u8bed\u53e5\u4e13\u7528\uff09<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u65b0\u5efa <code>sync.sql<\/code>\uff0c\u5199\u5165\u4f60\u7684\u6570\u636e\u5e93\u540c\u6b65\u8bed\u53e5<\/li>\n\n\n\n<li>\u4fee\u6539\u811a\u672c\u4e2d SQL_CONTENT \u8fd9\u4e00\u884c\u4e3a\uff1a<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">bash<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SQL_CONTENT=$(cat .\/sync.sql)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u4f7f\u7528\u6b65\u9aa4<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5b89\u88c5 MySQL \u5ba2\u6237\u7aef<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">bash<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># CentOS\/RHEL\nyum install mysql -y\n# Ubuntu\/Debian\napt update &amp;&amp; apt install mysql-client -y\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u7f16\u8f91 <code>mysql_hosts.list<\/code> \u586b\u5165\u5168\u90e8 50 \u53f0\u6570\u636e\u5e93\u670d\u52a1\u5668\u4fe1\u606f<\/li>\n\n\n\n<li>\u4fee\u6539\u811a\u672c\u5185 <code>SQL_CONTENT<\/code> \u4e3a\u4f60\u9700\u8981\u540c\u6b65\u6267\u884c\u7684 SQL<\/li>\n\n\n\n<li>\u6388\u6743 + \u8fd0\u884c<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">bash<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod +x batch_mysql_exec.sh\n.\/batch_mysql_exec.sh\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u751f\u4ea7\u5b89\u5168\u4f18\u5316\u65b9\u6848\uff08\u7981\u6b62\u660e\u6587\u5b58\u50a8\u6570\u636e\u5e93\u5bc6\u7801\uff09<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">1. \u6bcf\u53f0\u6570\u636e\u5e93\u670d\u52a1\u5668\u914d\u7f6e\u514d\u5bc6\u767b\u5f55 .my.cnf\uff08\u8fdc\u7a0b\u673a\u5668\uff09<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fdc\u7a0b\u6570\u636e\u5e93\u670d\u52a1\u5668\u5bf9\u5e94\u8d26\u53f7\u5bb6\u76ee\u5f55\u521b\u5efa <code>~\/.my.cnf<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ini<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;client]\nuser=root\npassword=Mysql@123\nport=3306\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6388\u6743\u6743\u9650\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">bash<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod 600 ~\/.my.cnf\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">2. \u4fee\u6539\u811a\u672c\uff0c\u5220\u9664\u5bc6\u7801\u53c2\u6570\uff0chosts.list \u53ea\u4fdd\u7559 IP\u3001\u7aef\u53e3\u3001\u5e93\u540d<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">mysql_hosts.list \u683c\u5f0f\u6539\u4e3a\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">plaintext<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>10.0.0.10 3306 test_db\n10.0.0.11 3306 test_db\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u811a\u672c mysql \u6267\u884c\u884c\u7b80\u5316\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">bash<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -h${M_IP} -P${M_PORT} --connect-timeout=${CONNECT_TIMEOUT} ${M_DB} -e \"${SQL_CONTENT}\"\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u8865\u5145\uff1a\u8de8\u516c\u7f51\u5168\u7403 MySQL \u8282\u70b9\u4f18\u5316<\/h1>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u8d85\u65f6\u65f6\u95f4\u8c03\u6574\uff1a\u5168\u7403\u7f51\u7edc\u5ef6\u8fdf\u5927\uff0c\u628a <code>CONNECT_TIMEOUT=15<\/code><\/li>\n\n\n\n<li>\u5e76\u53d1\u53ef\u964d\u4f4e\u81f3 20~30\uff0c\u9632\u6b62\u5927\u91cf\u516c\u7f51\u8fde\u63a5\u5e76\u53d1\u672c\u5730\u4e22\u5305<\/li>\n\n\n\n<li>\u82e5\u6570\u636e\u5e93\u9700\u8981 SSL \u8fde\u63a5\uff0cmysql \u547d\u4ee4\u589e\u52a0 ssl \u53c2\u6570\uff1a<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">bash<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql --ssl-mode=REQUIRED -h${M_IP} -P${M_PORT} -u${M_USER} -p${M_PASS} ${M_DB} -e \"${SQL_CONTENT}\"\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u6838\u5fc3\u7279\u6027<\/h1>\n\n\n\n<ol class=\"wp-block-list\">\n<li>50 \u53f0 MySQL<strong>\u5e76\u53d1\u540c\u65f6\u53d1\u8d77 SQL \u8bf7\u6c42<\/strong>\uff0c\u505a\u5230\u7edf\u4e00\u65f6\u95f4\u6267\u884c\u6570\u636e\u5e93\u540c\u6b65\u8bed\u53e5<\/li>\n\n\n\n<li>\u81ea\u52a8\u8df3\u8fc7\u6ce8\u91ca\u3001\u7a7a\u884c\uff0c\u65b9\u4fbf\u6279\u91cf\u7ba1\u7406\u4e0a\u767e\u53f0\u8282\u70b9<\/li>\n\n\n\n<li>\u5355\u8282\u70b9\u8fde\u63a5\u8d85\u65f6\uff0c\u4e0d\u4f1a\u963b\u585e\u6574\u4f53\u4efb\u52a1<\/li>\n\n\n\n<li>\u6bcf\u53f0\u8282\u70b9\u5355\u72ec\u8f93\u51fa\u6267\u884c\u7ed3\u679c\uff0c\u5feb\u901f\u5b9a\u4f4d\u6267\u884c\u5931\u8d25\u6570\u636e\u5e93<\/li>\n\n\n\n<li>\u652f\u6301\u5355\u884c SQL\u3001\u591a\u884c\u590d\u6742 SQL\u3001\u5916\u90e8 SQL \u6587\u4ef6\u5bfc\u5165\u540c\u6b65<\/li>\n\n\n\n<li>\u517c\u5bb9\u5185\u7f51\u96c6\u7fa4\u3001\u5168\u7403\u591a\u5730\u57df\u5206\u5e03\u5f0f MySQL \u670d\u52a1\u5668<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u4e24\u79cd\u65b9\u6848 \u4e00\u3001\u4e3b\u673a\u6e05\u5355\u914d\u7f6e mysql_hosts.list \u548c\u811a\u672c\u653e\u540c\u4e00\u76ee\u5f55\uff0c\u4e00\u884c\u4e00\u53f0 MySQL \u8282\u70b9\uff0c\u683c\u5f0f\uff1aIP \u7aef\u53e3 mysql\u7528\u6237 mysql\u5bc6\u7801 \u6570\u636e\u5e93\u540d plaintext \u4e8c\u3001\u6279\u91cf\u5e76\u53d1\u6267\u884c MySQL SQL \u811a\u672c batch_mysql_exec.sh bash \u8fd0\u884c \u4e09\u3001\u6267\u884c\u5916\u90e8 SQL \u6587\u4ef6\uff08\u5927\u6279\u91cf\u540c\u6b65\u8bed\u53e5\u4e13\u7528\uff09 bash \u8fd0\u884c \u56db\u3001\u4f7f\u7528\u6b65\u9aa4 bash \u8fd0\u884c bash \u8fd0\u884c \u751f\u4ea7\u5b89\u5168\u4f18\u5316\u65b9\u6848\uff08\u7981\u6b62\u660e\u6587\u5b58\u50a8\u6570\u636e\u5e93\u5bc6\u7801\uff09 1. \u6bcf\u53f0\u6570\u636e\u5e93\u670d\u52a1\u5668\u914d\u7f6e\u514d\u5bc6\u767b\u5f55 .my.cnf\uff08\u8fdc\u7a0b\u673a\u5668\uff09 \u8fdc\u7a0b\u6570\u636e\u5e93\u670d\u52a1\u5668\u5bf9\u5e94\u8d26\u53f7\u5bb6\u76ee\u5f55\u521b\u5efa ~\/.my.cnf ini \u6388\u6743\u6743\u9650\uff1a bash \u8fd0\u884c 2. \u4fee\u6539\u811a\u672c\uff0c\u5220\u9664\u5bc6\u7801\u53c2\u6570\uff0chosts.list \u53ea\u4fdd\u7559 IP\u3001\u7aef\u53e3\u3001\u5e93\u540d mysql_hosts.list \u683c\u5f0f\u6539\u4e3a\uff1a plaintext \u811a\u672c mysql \u6267\u884c\u884c\u7b80\u5316\uff1a bash \u8fd0\u884c \u8865\u5145\uff1a\u8de8\u516c\u7f51\u5168\u7403 MySQL \u8282\u70b9\u4f18\u5316 bash \u8fd0\u884c&hellip;&nbsp;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-7436","post","type-post","status-publish","format-standard","hentry","category-company-news"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/silubaba.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/7436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/silubaba.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/silubaba.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/silubaba.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/silubaba.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7436"}],"version-history":[{"count":1,"href":"https:\/\/silubaba.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/7436\/revisions"}],"predecessor-version":[{"id":7437,"href":"https:\/\/silubaba.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/7436\/revisions\/7437"}],"wp:attachment":[{"href":"https:\/\/silubaba.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/silubaba.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/silubaba.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}