{"id":15985,"date":"2025-04-18T22:32:59","date_gmt":"2025-04-18T14:32:59","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/15985.html"},"modified":"2025-04-18T22:32:59","modified_gmt":"2025-04-18T14:32:59","slug":"%e8%87%aa%e5%8a%a8%e5%8c%96%e5%90%8c%e6%ad%a5%e5%a4%9a%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%95%b0%e6%8d%ae%e5%ba%93%e8%a1%a8%e7%bb%93%e6%9e%84","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/15985.html","title":{"rendered":"\u81ea\u52a8\u5316\u540c\u6b65\u591a\u670d\u52a1\u5668\u6570\u636e\u5e93\u8868\u7ed3\u6784"},"content":{"rendered":"<p>\u5f53\u9879\u76ee\u6bcf\u6b21\u8fdb\u884c\u7248\u672c\u5347\u7ea7\u7684\u65f6\u5019&#xff0c;\u5982\u679c\u5728\u8fd9\u6b21\u8fed\u4ee3\u4e2d\u6d89\u53ca\u8868\u7ed3\u6784\u53d8\u66f4&#xff0c;\u9700\u8981\u5c06\u4e0d\u540c\u7684\u751f\u4ea7\u73af\u5883\u4e0b&#xff0c;\u90fd\u9700\u8981\u540c\u6b65\u8868\u7ed3\u6784\u7684DDL\u8bed\u53e5&#xff0c;\u6bd4\u8f83\u9ebb\u70e6&#xff0c;\u800c\u4e14\u8fd8\u6709\u53ef\u80fd\u5fd8\u8bb0\u540c\u6b65\u811a\u672c&#xff0c;\u5bfc\u81f4\u751f\u4ea7\u73af\u5883\u62a5\u9519&#8230;.<\/p>\n<p>\u8be5\u65b9\u6848\u91c7\u7528SpringBoot&#043;Mybatis\/MybatisPlus\u6846\u67b6&#xff0c;\u5b8c\u6210\u5728\u9879\u76ee\u542f\u52a8\u65f6&#xff0c;\u81ea\u52a8\u5316\u6267\u884csql\u811a\u672c&#xff0c;\u5e76\u4e14\u540c\u65f6\u652f\u6301\u7248\u672c\u53f7\u3010\u5982\u679c\u5f53\u524d\u7248\u672c\u53f7\u9ad8\u4e8e\u8be5sql\u6587\u4ef6&#xff0c;\u5219\u4e0d\u6267\u884c\u3011\u3002<\/p>\n<h2>1\u3001\u5148\u521b\u5efa\u4e00\u5f20\u8868&#xff0c;\u4e13\u95e8\u7528\u6765\u8bb0\u5f55\u5df2\u7ecf\u540c\u6b65\u8fc7\u7684sql\u811a\u672c\u6587\u4ef6\u540d\u3001\u5bf9\u5e94\u7684\u7248\u672c\u53f7\u3002<\/h2>\n<p>CREATE TABLE &#096;hd_version&#096; (<br \/>\n  &#096;id&#096; varchar(64) NOT NULL,<br \/>\n  &#096;version&#096; varchar(64) DEFAULT NULL COMMENT &#039;\u7248\u672c\u53f7&#039;,<br \/>\n  &#096;created&#096; datetime DEFAULT NULL COMMENT &#039;\u521b\u5efa\u65f6\u95f4&#039;,<br \/>\n  &#096;remark&#096; varchar(500) DEFAULT NULL COMMENT &#039;\u5907\u6ce8&#039;,<br \/>\n  PRIMARY KEY (&#096;id&#096;)<br \/>\n) ENGINE&#061;InnoDB DEFAULT CHARSET&#061;utf8mb4 COMMENT&#061;&#039;\u6570\u636e\u7248\u672c&#039;;<br \/>\nimport java.util.Date;<br \/>\nimport lombok.Data;<br \/>\n&#064;Data<br \/>\npublic class HdVersionEntity {<br \/>\n    \/**<br \/>\n     * \u4e3b\u952eid<br \/>\n     *\/<br \/>\n    private String id;<br \/>\n    \/**<br \/>\n     * \u7248\u672c\u53f7&#xff08;\u4e00\u822c\u662f\u6587\u4ef6\u540d\u53bb\u6389\u6587\u4ef6\u540e\u7f00&#xff09;<br \/>\n     *\/<br \/>\n    private String version;<br \/>\n    \/**<br \/>\n     * \u6587\u4ef6\u540d<br \/>\n     *\/<br \/>\n    private String remark;<br \/>\n    \/**<br \/>\n     * \u521b\u5efa\u65f6\u95f4<br \/>\n     *\/<br \/>\n    private Date created;<br \/>\n}<br \/>\nimport lombok.Data;<\/p>\n<p>&#064;Data<br \/>\npublic class SchemaData {<br \/>\n    \/**<br \/>\n     * \u7248\u672c\u53f7<br \/>\n     *\/<br \/>\n    public String version;<\/p>\n<p>    \/**<br \/>\n     * \u6587\u4ef6\u540d<br \/>\n     *\/<br \/>\n    public String fileName;<\/p>\n<p>    public SchemaData(String version, String fileName) {<br \/>\n        this.version &#061; version;<br \/>\n        this.fileName &#061; fileName;<br \/>\n    }<br \/>\n} <\/p>\n<h2>\u00a02\u3001\u63a5\u7740\u7f16\u5199dao\u5c42<\/h2>\n<p>import org.apache.ibatis.annotations.Mapper;<br \/>\nimport org.apache.ibatis.annotations.Param;<br \/>\nimport org.apache.ibatis.annotations.Update;<\/p>\n<p>&#064;Mapper<br \/>\npublic interface HdCommonDao  {<br \/>\n    \/**<br \/>\n     * \u67e5\u8be2\u8868\u4e2d\u662f\u5426\u5b58\u5728\u5f53\u524d\u7248\u672c\u53f7<br \/>\n     * &#064;param version<br \/>\n     * &#064;return<br \/>\n     *\/<br \/>\n    int selectVersion(&#064;Param(&#034;version&#034;) String version);<\/p>\n<p>    \/**<br \/>\n     * \u63d2\u5165\u7248\u672c<br \/>\n     * &#064;param entity<br \/>\n     * &#064;return<br \/>\n     *\/<br \/>\n    int insertVersion(HdVersionEntity entity);<\/p>\n<p>    \/**<br \/>\n     * \u6267\u884csql&#xff0c;\u53ef\u4ee5\u662fDML\u3001DDL<br \/>\n     * &#064;param sql<br \/>\n     *\/<br \/>\n    &#064;Update(&#034;${sql}&#034;)<br \/>\n    void updateSql(&#064;Param(&#034;sql&#034;) String sql);<br \/>\n} <\/p>\n<h2>3\u3001\u4ee5\u53ca\u5bf9\u5e94\u7684Mapper\u6587\u4ef6<\/h2>\n<p>&lt;?xml version&#061;&#034;1.0&#034; encoding&#061;&#034;UTF-8&#034;?&gt;<br \/>\n&lt;!DOCTYPE mapper PUBLIC &#034;-\/\/mybatis.org\/\/DTD Mapper 3.0\/\/EN&#034; &#034;http:\/\/mybatis.org\/dtd\/mybatis-3-mapper.dtd&#034;&gt;<\/p>\n<p>             &lt;!&#8211;\u8fd9\u91cc\u6587\u4ef6\u7a7a\u95f4\u547d\u540d\u6539\u6210\u81ea\u5df1\u8def\u5f84\u4e0b\u7684&#8211;&gt;<br \/>\n&lt;mapper namespace&#061;&#034;com.xxx.DatabaseAutoFill.HdCommonDao&#034;&gt;<\/p>\n<p>    &lt;select id&#061;&#034;selectVersion&#034; resultType&#061;&#034;int&#034;&gt;<br \/>\n        selecT count(1) from hd_version<br \/>\n        where version &#061; #{version}<br \/>\n    &lt;\/select&gt;<br \/>\n    &lt;select id&#061;&#034;selectTableExist&#034; resultType&#061;&#034;int&#034;&gt;<br \/>\n        select count(*) count  from information_schema.TABLES where TABLE_NAME &#061; #{tableName} and  table_schema &#061; (select database())<br \/>\n    &lt;\/select&gt;<\/p>\n<p>    &lt;insert id&#061;&#034;insertVersion&#034;&gt;<br \/>\n        insert into hd_version(id,version, remark, created) values (uuid(),#{version}, #{remark}, #{created})<br \/>\n    &lt;\/insert&gt;<\/p>\n<p>&lt;\/mapper&gt; <\/p>\n<h2>4\u3001 \u7f16\u5199\u5b9e\u73b0\u7c7b<\/h2>\n<p><span style=\"color:#fe2c24\">\u6ce8\u610f&#xff0c;\u8fd9\u91cc\u662f\u5c06\u6574\u6bb5\u903b\u8f91\u653e\u5728ApplicationRunner\u63a5\u53e3\u4e0b\u6267\u884c&#xff0c;\u5373\u5f53Spring\u5bb9\u5668\u52a0\u8f7d\u5b8c\u4e4b\u540e&#xff0c;\u4f1a\u7acb\u5373\u6267\u884c\u8be5\u65b9\u6cd5\u3002<\/span><\/p>\n<p>&#064;Order(1)<br \/>\n&#064;Component<br \/>\n&#064;Slf4j<br \/>\npublic class HdSchemaExecutor implements ApplicationRunner {<\/p>\n<p>    &#064;Autowired<br \/>\n    HdCommonDao hdCommonDao;<br \/>\n    \/\/ \u6570\u636e\u5e93\u811a\u672c\u6587\u4ef6\u5217\u8868<\/p>\n<p>    private static final String PREFIX &#061; &#034;&#8211;v&#034;;<\/p>\n<p>    &#064;Override<br \/>\n    &#064;Transactional<br \/>\n    public void run(ApplicationArguments args) throws IOException {<br \/>\n        String basePath &#061; &#034;\/dbVersion\/MySQL.sql&#034;;<br \/>\n        InputStream inputStream &#061; this.getClass().getResourceAsStream(basePath);<br \/>\n        String sqlScript &#061; IoUtil.readUtf8(inputStream);<br \/>\n        assert inputStream !&#061; null;<br \/>\n        inputStream.close();<br \/>\n        \/**<br \/>\n         * \u4e00\u6b21\u81f3\u591a\u53ea\u4f1a\u6267\u884c\u4e00\u4e2a\u7248\u672c&#xff0c;\u5176\u5b9e\u6211\u4eec\u53ef\u4ee5\u62ff\u5230\u6240\u6709\u7684\u7248\u672c\u5e76\u6267\u884c\u6700\u540e\u4e00\u4e2a\u7248\u672c\u5373\u53ef<br \/>\n         *\/<br \/>\n        List&lt;String&gt; versionList &#061; new ArrayList&lt;&gt;();<br \/>\n        String[] lines &#061; sqlScript.split(&#034;\\\\n&#034;);<br \/>\n        for (String line : lines) {<br \/>\n            if(line.toLowerCase().contains(PREFIX)){<br \/>\n                versionList.add(line);<br \/>\n            }<br \/>\n        }<br \/>\n        \/\/ \u5f97\u5230\u7248\u672c\u53f7\u6574\u4e32<br \/>\n        String latestVersion &#061; versionList.get(versionList.size()-1);<br \/>\n        \/\/ \u5199\u5165\u6570\u636e\u5e93\u7684\u7248\u672c\u53f7\u524d\u7f00<br \/>\n        String version &#061; latestVersion.substring(latestVersion.lastIndexOf(&#034;-&#034;)&#043;1).trim().toLowerCase();<br \/>\n        int index &#061; sqlScript.lastIndexOf(latestVersion); \/\/ \u67e5\u627es2\u5728s1\u4e2d\u7684\u8d77\u59cb\u4f4d\u7f6e<br \/>\n        String result &#061; &#034;&#034;;<br \/>\n        if (index !&#061; -1) {<br \/>\n            \/\/ \u622a\u53d6s2\u5728s1\u4e2d\u7ed3\u675f\u4f4d\u7f6e\u4e4b\u540e\u7684\u90e8\u5206<br \/>\n            result &#061; sqlScript.substring(index &#043; latestVersion.length());<br \/>\n        } else {<br \/>\n            log.info(&#034;current version exception:{}&#034;,version);<br \/>\n            LogUtil.info(version, &#034;current version exception&#034;);<br \/>\n        }<br \/>\n        \/\/String[] resultList &#061; result.split(&#034;\\\\n&#034;);<br \/>\n        String[] resultList &#061; result.split(&#034;;&#034;);<br \/>\n        int cnt &#061; hdCommonDao.selectVersion(version);<br \/>\n        boolean successInsert &#061; false;<br \/>\n        \/\/ \u8bf4\u660e\u4e0d\u9700\u8981\u5199\u5165\u5e93<br \/>\n        if(cnt &#061;&#061;1 )return;<br \/>\n        for (String line : resultList) {<br \/>\n            if(!line.toLowerCase().contains(&#034;drop&#034;) &amp;&amp; !line.toLowerCase().contains(&#034;delete&#034;) &amp;&amp; line.length() &gt; 25 &amp;&amp; !line.contains(&#034;&#8211;&#034;)) {<br \/>\n                \/\/\u5f00\u59cb\u6267\u884c\u63d2\u5165\u64cd\u4f5c<br \/>\n                try {<br \/>\n                    hdCommonDao.updateSql(line.trim());<br \/>\n                    successInsert &#061; true;<br \/>\n                    log.info(&#034;version:{},start sql script:{}&#034;,version,line.trim());<br \/>\n                    LogUtil.info(&#034;version, sql script:&#034;,version,line.trim());<br \/>\n                } catch (Exception e) {<br \/>\n                    log.info(&#034;version:{},sql\u6267\u884c\u5f02\u5e38:{}&#034;,version,line.trim());<br \/>\n                    LogUtil.info(&#034;sql\u6267\u884c\u5f02\u5e38&#034;,line.trim());<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n        if(successInsert){<br \/>\n            HdVersionEntity entity &#061; new HdVersionEntity();<br \/>\n            entity.setVersion(version);<br \/>\n            entity.setCreated(new Date());<br \/>\n            hdCommonDao.insertVersion(entity);<br \/>\n        }<br \/>\n        log.info(&#034;auto deploying sql finished&#8230;&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u8fd9\u91cc\u4e3b\u8981\u5e72\u4e09\u4ef6\u4e8b&#xff1a;<\/p>\n<p>\u8bfb\u53d6\u6307\u5b9a\u8def\u5f84\u4e0b\u7684\u6587\u4ef6\u5939\u4e2d\u7684\u6240\u6709\u6587\u4ef6 \u6839\u636e\u8fd9\u4e9b\u6587\u4ef6\u7684\u6587\u4ef6\u540d\u53bb\u8868\u91cc\u67e5&#xff0c;\u662f\u5426\u63d2\u5165\u8fc7&#xff0c;\u6ca1\u6709\u8bf4\u660e\u9700\u8981\u88ab\u63d2\u5165&#xff0c;\u5373\u9700\u8981\u6267\u884c\u7684sql\u811a\u672c \u6267\u884csql\u811a\u672c<\/p>\n<p>\u6211\u8fd9\u91cc\u7684\u8def\u5f84\u662fresources\u4e0b\u7684\u76f8\u5bf9\u8def\u5f84&#xff0c;\u56e0\u4e3a\u6211\u8fd9\u4e2a\u4ee3\u7801\u662f\u8981\u6253\u5305\u653e\u5230\u7ebf\u4e0a\u73af\u5883\u7684&#xff0c;\u7528\u7edd\u5bf9\u8def\u5f84\u53ef\u80fd\u4f1a\u62a5&#xff08;FILE NOT FOUND ERROR&#xff09;FNFE\u3002\u00a0<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"127\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418143257-680262996a06f.png\" width=\"359\" \/><\/p>\n<h2>PS<\/h2>\n<p>\u4ee5\u4e0a\u65b9\u6cd5\u5bf9\u4e8eSpring\u5bb9\u5668\u52a0\u8f7d\u65f6&#xff0c;\u6ca1\u6709\u5f3a\u4f9d\u8d56\u7684\u8868&#xff0c;\u662f\u53ef\u4ee5\u901a\u7528\u7684\u00a0&#xff08;\u53ef\u80fd\u6709\u70b9\u62d7\u53e3&#xff09;\u3002<\/p>\n<p>\u5373&#xff0c;\u5982\u679cSpring\u5bb9\u5668\u542f\u52a8\u65f6&#xff0c;\u5982\u679c\u9700\u8981\u4f9d\u8d56\u67d0\u5f20\u8868&#xff0c;\u5426\u5219\u542f\u52a8\u5931\u8d25\u7684\u8bdd\u600e\u4e48\u529e&#xff0c;\u8fd8\u80fd\u7528\u6211\u4eec\u4e0a\u8ff0\u65b9\u6cd5\u5417&#xff1f;<\/p>\n<p>\u7406\u8bba\u4e0a\u662f\u4e0d\u884c\u7684&#xff0c;\u6211\u8fd9\u91cc\u5c06\u5bb9\u5668\u542f\u52a8\u65f6&#xff0c;\u5fc5\u987b\u5f3a\u4f9d\u8d56\u7684\u8868&#xff08;Quartz\u6846\u67b6&#xff09;\u5220\u53bb&#xff0c;\u542f\u52a8\u65f6\u62a5\u9519\u3002 \u90a3\u5bf9\u5e94\u8fd9\u79cd\u60c5\u51b5&#xff0c;\u8be5\u600e\u4e48\u89e3\u51b3\u5462&#xff1f;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"747\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418143257-680262997d0d6.png\" width=\"1206\" \/><\/p>\n<p>\u00a0\u5176\u5b9e\u8fd9\u79cd\u6846\u67b6&#xff0c;\u90fd\u4f1a\u63d0\u4f9b\u6ce8\u89e3&#xff0c;\u5982&#xff1a;<\/p>\n<p>\u8868\u660e&#xff0c;\u5728\u9879\u76ee\u542f\u52a8\u7684\u65f6\u5019&#xff0c;\u4f1a\u81ea\u52a8\u5b8c\u6210jdbc\u7684\u521d\u59cb\u5316&#xff0c;\u5373\u5982\u679c\u4f60\u6ca1\u6709\u8868&#xff0c;\u4f1a\u5148\u7ed9\u4f60\u6267\u884c\u8868\u7684\u521b\u5efa&#xff0c;\u56e0\u6b64\u4e0d\u9700\u8981\u6211\u4eec\u53bb\u8003\u8651\u3002<\/p>\n<p> spring.quartz.jdbc.initialize-schema&#061;always <\/p>\n<p>Quartz\u4e5f\u8d77\u6765\u4e86\u3002\u00a0<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"133\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418143257-68026299dc51e.png\" width=\"1146\" \/><\/p>\n<h2>\u5199\u5728\u6700\u540e<\/h2>\n<p>\u7531\u4e8e\u8fd9\u4e2a\u5de5\u7a0b\u662f\u4e34\u65f6\u7a81\u52a0\u7684&#xff0c;\u6211\u4e5f\u4e0d\u597d\u968f\u4fbf\u5c31\u6d4b\u8bd5\u73af\u5883\u7684\u5e93\u6765\u5220\u5220\u6539\u6539&#xff0c;\u56e0\u6b64\u6211\u5728\u672c\u5730windows\u4e0a\u7528docker\u90e8\u7f72\u4e86mysql&#xff0c;\u6765\u6d4b\u8bd5\u7684\u3002\u4ee5\u4e0b\u662f\u5728windows\u4e0a\u7684docker\u90e8\u7f72mysql\u6b65\u9aa4&#xff1a;<\/p>\n<p>docker pull mysql:8.0<\/p>\n<p>\u5728c\u76d8\u7528\u6237\u76ee\u5f55\u4e0b&#xff0c;\u521b\u5efaconf\u3001data\u3001logs\u4e09\u4e2a\u6587\u4ef6\u5939<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"142\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418143258-6802629a05c17.png\" width=\"635\" \/><\/p>\n<p>\u00a0\u5728conf\u76ee\u5f55\u4e0b&#xff0c;\u521b\u5efamy.cnf\u6587\u4ef6&#xff0c;\u91cc\u9762\u7f16\u5199\u5982\u4e0b\u5185\u5bb9\u3002<\/p>\n<p>[mysql]<br \/>\n#\u8bbe\u7f6emysql\u5ba2\u6237\u7aef\u9ed8\u8ba4\u5b57\u7b26\u96c6<br \/>\ndefault-character-set&#061;UTF8MB4<br \/>\n[mysqld]<br \/>\n#\u8bbe\u7f6e3306\u7aef\u53e3<br \/>\nport&#061;3306<br \/>\n#\u5141\u8bb8\u6700\u5927\u8fde\u63a5\u6570<br \/>\nmax_connections&#061;200<br \/>\n#\u5141\u8bb8\u8fde\u63a5\u5931\u8d25\u7684\u6b21\u6570<br \/>\nmax_connect_errors&#061;10<br \/>\n#\u9ed8\u8ba4\u4f7f\u7528\u201cmysql_native_password\u201d\u63d2\u4ef6\u8ba4\u8bc1<br \/>\ndefault_authentication_plugin&#061;mysql_native_password<br \/>\n#\u670d\u52a1\u7aef\u4f7f\u7528\u7684\u5b57\u7b26\u96c6\u9ed8\u8ba4\u4e3a8\u6bd4\u7279\u7f16\u7801\u7684latin1\u5b57\u7b26\u96c6<br \/>\ncharacter-set-server&#061;UTF8MB4<br \/>\n#\u5f00\u542f\u67e5\u8be2\u7f13\u5b58<br \/>\nexplicit_defaults_for_timestamp&#061;true<br \/>\n#\u521b\u5efa\u65b0\u8868\u65f6\u5c06\u4f7f\u7528\u7684\u9ed8\u8ba4\u5b58\u50a8\u5f15\u64ce<br \/>\ndefault-storage-engine&#061;INNODB<br \/>\n#\u7b49\u5f85\u8d85\u65f6\u65f6\u95f4\u79d2<br \/>\nwait_timeout&#061;60<br \/>\n#\u4ea4\u4e92\u5f0f\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\u79d2<br \/>\ninteractive-timeout&#061;600<br \/>\n# \u5bf9\u6570\u636e\u5e93\u8868\u5927\u5c0f\u5199\u4e0d\u654f\u611f\u8bbe\u7f6e&#xff0c;\u9ed8\u8ba4\u8bbe\u7f6e\u4e3a\u5c0f\u5199&#xff0c;\u6bd4\u8f83\u4e5f\u5168\u90e8\u8bbe\u7f6e\u4e3a\u5c0f\u5199\u5728\u6bd4\u8f83<br \/>\nlower-case-table-names&#061;1<br \/>\n# \u8bbe\u7f6e\u9ed8\u8ba4\u65f6\u533a<br \/>\ndefault-time_zone&#061;&#039;&#043;8:00&#039; <\/p>\n<p>\u542f\u52a8\u5bb9\u5668&#xff0c;\u6ce8\u610f\u5728windows\u4e0b\u00a0\u9700\u8981\u628a\u6bcf\u884c\u540e\u9762\u7684\u00a0&#096;\\\\&#096;\u5220\u53bb&#xff0c;\u5426\u5728windows\u4e0b\u4f1a\u542f\u52a8\u5931\u8d25<\/p>\n<p>\u00a0docker run &#8211;name mysql8.0 \\\\ -v D:\\\\docker\\\\data\\\\mysql8.0\\\\config\\\\my.cnf:\/etc\/mysql\/my.cnf \\\\ -v D:\\\\docker\\\\data\\\\mysql8.0\\\\data:\/var\/lib\/mysql \\\\ -v D:\\\\docker\\\\data\\\\mysql8.0\\\\logs:\/logs -p 3306:3306 \\\\ -e MYSQL_ROOT_PASSWORD&#061;123456 \\\\<\/p>\n<p>-e TZ&#061;Asia\/Shanghai \\\\ -d mysql:8.0 \\\\ &#8211;lower-case-table-names&#061;1<\/p>\n<p>\u8fd9\u6837&#xff0c;\u7406\u8bba\u4e0a\u5c31\u80fd\u542f\u52a8\u6210\u529f\u4e86\u3002<\/p>\n<p>\u5206\u4eab\u51e0\u4e2a\u5e38\u7528\u7684\u547d\u4ee4&#xff1a; docker exec -it \u5bb9\u5668\u540d\u79f0\/\u5bb9\u5668id\u00a0\u00a0bash\u00a0 #\u8fdb\u5165\u5bb9\u5668<\/p>\n<p>docker logs \u5bb9\u5668\u540d\u79f0\/\u5bb9\u5668id -f -n&#061;100 \u67e5\u770b\u5bb9\u5668\u6700\u540e\u4e00\u767e\u884c\u65e5\u5fd7<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb949\u6b21\uff0c\u70b9\u8d5e13\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u7531\u4e8e\u8fd9\u4e2a\u5de5\u7a0b\u662f\u4e34\u65f6\u7a81\u52a0\u7684\uff0c\u6211\u4e5f\u4e0d\u597d\u968f\u4fbf\u5c31\u6d4b\u8bd5\u73af\u5883\u7684\u5e93\u6765\u5220\u5220\u6539\u6539\uff0c\u56e0\u6b64\u6211\u5728\u672c\u5730windows\u4e0a\u7528docker\u90e8\u7f72\u4e86mysql\uff0c\u6765\u6d4b\u8bd5\u7684\u3002\u4ee5\u4e0b\u662f\u5728windows\u4e0a\u7684docker\u90e8\u7f72mysql\u6b65\u9aa4\uff1a\u5728c\u76d8\u7528\u6237\u76ee\u5f55\u4e0b\uff0c\u521b\u5efaconf\u3001data\u3001logs\u4e09\u4e2a\u6587\u4ef6\u5939\u5728conf\u76ee\u5f55\u4e0b\uff0c\u521b\u5efamy.cnf\u6587\u4ef6\uff0c\u91cc\u9762\u7f16\u5199\u5982\u4e0b\u5185\u5bb9\u3002[mysql]#\u8bbe\u7f6emysql\u5ba2\u6237\u7aef\u9ed8\u8ba4\u5b57\u7b26\u96c6[mysqld]#\u8bbe\u7f6e3306\u7aef\u53e3port=3306#\u5141\u8bb8\u6700\u5927\u8fde\u63a5\u6570#\u5141\u8bb8\u8fde\u63a5\u5931\u8d25\u7684\u6b21\u6570\u3002<\/p>\n","protected":false},"author":2,"featured_media":15981,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[100,395,44,1069],"topic":[],"class_list":["post-15985","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-100","tag-395","tag-44","tag-1069"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u81ea\u52a8\u5316\u540c\u6b65\u591a\u670d\u52a1\u5668\u6570\u636e\u5e93\u8868\u7ed3\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/15985.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u81ea\u52a8\u5316\u540c\u6b65\u591a\u670d\u52a1\u5668\u6570\u636e\u5e93\u8868\u7ed3\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb949\u6b21\uff0c\u70b9\u8d5e13\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u7531\u4e8e\u8fd9\u4e2a\u5de5\u7a0b\u662f\u4e34\u65f6\u7a81\u52a0\u7684\uff0c\u6211\u4e5f\u4e0d\u597d\u968f\u4fbf\u5c31\u6d4b\u8bd5\u73af\u5883\u7684\u5e93\u6765\u5220\u5220\u6539\u6539\uff0c\u56e0\u6b64\u6211\u5728\u672c\u5730windows\u4e0a\u7528docker\u90e8\u7f72\u4e86mysql\uff0c\u6765\u6d4b\u8bd5\u7684\u3002\u4ee5\u4e0b\u662f\u5728windows\u4e0a\u7684docker\u90e8\u7f72mysql\u6b65\u9aa4\uff1a\u5728c\u76d8\u7528\u6237\u76ee\u5f55\u4e0b\uff0c\u521b\u5efaconf\u3001data\u3001logs\u4e09\u4e2a\u6587\u4ef6\u5939\u5728conf\u76ee\u5f55\u4e0b\uff0c\u521b\u5efamy.cnf\u6587\u4ef6\uff0c\u91cc\u9762\u7f16\u5199\u5982\u4e0b\u5185\u5bb9\u3002[mysql]#\u8bbe\u7f6emysql\u5ba2\u6237\u7aef\u9ed8\u8ba4\u5b57\u7b26\u96c6[mysqld]#\u8bbe\u7f6e3306\u7aef\u53e3port=3306#\u5141\u8bb8\u6700\u5927\u8fde\u63a5\u6570#\u5141\u8bb8\u8fde\u63a5\u5931\u8d25\u7684\u6b21\u6570\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/15985.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T14:32:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418143257-680262996a06f.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/15985.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/15985.html\",\"name\":\"\u81ea\u52a8\u5316\u540c\u6b65\u591a\u670d\u52a1\u5668\u6570\u636e\u5e93\u8868\u7ed3\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T14:32:59+00:00\",\"dateModified\":\"2025-04-18T14:32:59+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/15985.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/15985.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/15985.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u81ea\u52a8\u5316\u540c\u6b65\u591a\u670d\u52a1\u5668\u6570\u636e\u5e93\u8868\u7ed3\u6784\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u81ea\u52a8\u5316\u540c\u6b65\u591a\u670d\u52a1\u5668\u6570\u636e\u5e93\u8868\u7ed3\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/15985.html","og_locale":"zh_CN","og_type":"article","og_title":"\u81ea\u52a8\u5316\u540c\u6b65\u591a\u670d\u52a1\u5668\u6570\u636e\u5e93\u8868\u7ed3\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb949\u6b21\uff0c\u70b9\u8d5e13\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u7531\u4e8e\u8fd9\u4e2a\u5de5\u7a0b\u662f\u4e34\u65f6\u7a81\u52a0\u7684\uff0c\u6211\u4e5f\u4e0d\u597d\u968f\u4fbf\u5c31\u6d4b\u8bd5\u73af\u5883\u7684\u5e93\u6765\u5220\u5220\u6539\u6539\uff0c\u56e0\u6b64\u6211\u5728\u672c\u5730windows\u4e0a\u7528docker\u90e8\u7f72\u4e86mysql\uff0c\u6765\u6d4b\u8bd5\u7684\u3002\u4ee5\u4e0b\u662f\u5728windows\u4e0a\u7684docker\u90e8\u7f72mysql\u6b65\u9aa4\uff1a\u5728c\u76d8\u7528\u6237\u76ee\u5f55\u4e0b\uff0c\u521b\u5efaconf\u3001data\u3001logs\u4e09\u4e2a\u6587\u4ef6\u5939\u5728conf\u76ee\u5f55\u4e0b\uff0c\u521b\u5efamy.cnf\u6587\u4ef6\uff0c\u91cc\u9762\u7f16\u5199\u5982\u4e0b\u5185\u5bb9\u3002[mysql]#\u8bbe\u7f6emysql\u5ba2\u6237\u7aef\u9ed8\u8ba4\u5b57\u7b26\u96c6[mysqld]#\u8bbe\u7f6e3306\u7aef\u53e3port=3306#\u5141\u8bb8\u6700\u5927\u8fde\u63a5\u6570#\u5141\u8bb8\u8fde\u63a5\u5931\u8d25\u7684\u6b21\u6570\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/15985.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T14:32:59+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418143257-680262996a06f.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/15985.html","url":"https:\/\/www.wsisp.com\/helps\/15985.html","name":"\u81ea\u52a8\u5316\u540c\u6b65\u591a\u670d\u52a1\u5668\u6570\u636e\u5e93\u8868\u7ed3\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T14:32:59+00:00","dateModified":"2025-04-18T14:32:59+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/15985.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/15985.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/15985.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u81ea\u52a8\u5316\u540c\u6b65\u591a\u670d\u52a1\u5668\u6570\u636e\u5e93\u8868\u7ed3\u6784"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/15985","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=15985"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/15985\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/15981"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=15985"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=15985"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=15985"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=15985"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}