{"id":16784,"date":"2021-08-18T16:36:11","date_gmt":"2021-08-18T08:36:11","guid":{"rendered":"https:\/\/aqzt.com\/16784.html"},"modified":"2021-08-18T16:36:11","modified_gmt":"2021-08-18T08:36:11","slug":"springboot%e5%be%ae%e6%9c%8d%e5%8a%a1-tomcat%e9%9b%86%e7%be%a4ngnix%e8%b4%9f%e8%bd%bd%e5%9d%87%e8%a1%a1mysql%e4%b8%bb%e4%bb%8e%e5%a4%8d%e5%88%b6%ef%bc%8c%e8%af%bb%e5%86%99%e5%88%86%e7%a6%bb-3","status":"publish","type":"post","link":"https:\/\/aqzt.com\/16784.html","title":{"rendered":"SpringBoot\u5fae\u670d\u52a1 +tomcat\u96c6\u7fa4+Ngnix\u8d1f\u8f7d\u5747\u8861+Mysql\u4e3b\u4ece\u590d\u5236\uff0c\u8bfb\u5199\u5206\u79bb\uff084\uff09"},"content":{"rendered":"<p>\u56db\uff1amysql\u4e3b\u4ece\u590d\u5236\uff0c\u8bfb\u5199\u5206\u79bb<\/p>\n<\/p>\n<p>1.\u9996\u5148\u628amysql\u6e90\u7801\u5305\u6587\u4ef6\u62f7\u5230\u4e24\u53f0linux\u670d\u52a1\u5668\u4e0a\uff0c\u7136\u540e\u5728\u4e24\u53f0\u670d\u52a1\u5668\u4e0a\u5b89\u88c5Mysql\u6570\u636e\u5e93<\/p>\n<pre>\n\n<div class=\"codecolorer-container text solarized-dark language-bash\" style=\"overflow:auto;white-space:nowrap;width:800px;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/>32<br \/>33<br \/>34<br \/>35<br \/>36<br \/>37<br \/>38<br \/>39<br \/>40<br \/>41<br \/>42<br \/>43<br \/>44<br \/>45<br \/>46<br \/>47<br \/>48<br \/>49<br \/>50<br \/>51<br \/>52<br \/>53<br \/>54<br \/>55<br \/>56<br \/>57<br \/>58<br \/>59<br \/>60<br \/>61<br \/>62<br \/>63<br \/>64<br \/>65<br \/>66<br \/>67<br \/>68<br \/>69<br \/>70<br \/>71<br \/>72<br \/>73<br \/>74<br \/>75<br \/>76<br \/>77<br \/>78<br \/>79<br \/>80<br \/>81<br \/>82<br \/>83<br \/>84<br \/>85<br \/>86<br \/>87<br \/>88<br \/>89<br \/>90<br \/>91<br \/>92<br \/>93<br \/>94<br \/>95<br \/><\/div><\/td><td><div class=\"text codecolorer\">1\u5b89\u88c5 MySQL &nbsp; <br \/>\n2 &nbsp; &nbsp;1 \u5b89\u88c5 ncurses &nbsp;<br \/>\n3 &nbsp; &nbsp; &nbsp; &nbsp;Ncurses \u63d0\u4f9b\u5b57\u7b26\u7ec8\u7aef\u5904\u7406\u5e93\uff0c\u5305\u62ec\u9762\u677f\u548c\u83dc\u5355\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u5957\u63a7\u5236\u5149\u6807\uff0c\u5efa\u7acb &nbsp;<br \/>\n4 &nbsp; &nbsp; &nbsp; &nbsp;\u7a97\u53e3\uff0c\u6539\u53d8\u524d\u666f\u80cc\u666f\u989c\u8272\u4ee5\u53ca\u5904\u7406\u9f20\u6807\u64cd\u4f5c\u7684\u51fd\u6570\u3002\u4f7f\u7528\u6237\u5728\u5b57\u7b26\u7ec8\u7aef\u4e0b\u7f16\u5199\u5e94 &nbsp;<br \/>\n5 &nbsp; &nbsp; &nbsp; &nbsp;\u7528\u7a0b\u5e8f\u65f6\u7ed5\u8fc7\u4e86\u90a3\u4e9b\u607c\u4eba\u7684\u5e95\u5c42\u673a\u5236\u3002\u7b80\u800c\u8a00\u4e4b\uff0c\u4ed6\u662f\u4e00\u4e2a\u53ef\u4ee5\u4f7f\u5e94\u7528\u7a0b\u5e8f\u76f4\u63a5 &nbsp;<br \/>\n6 &nbsp; &nbsp; &nbsp; &nbsp;\u63a7\u5236\u7ec8\u7aef\u5c4f\u5e55\u663e\u793a\u7684\u51fd\u6570\u5e93\u3002 &nbsp;<br \/>\n7 &nbsp; &nbsp; &nbsp; &nbsp;1\u3001 &nbsp;<br \/>\n8 &nbsp; &nbsp; &nbsp; &nbsp;yum -y install ncurses-devel &nbsp;<br \/>\n9 &nbsp; &nbsp; &nbsp; &nbsp;\u6ce8\uff1a\u5982\u679c\u62a5\u9519\uff0c\u5305\u627e\u4e0d\u5230\uff0c\u662f*\u901a\u914d\u7b26\u6ca1\u6709\u8bc6\u522b\uff0c\u7ed9\u6587\u4ef6\u540d\u52a0\u53cc\u5f15\u53f7 \u201cncurses*\u201d &nbsp;<br \/>\n10 &nbsp; &nbsp; &nbsp; &nbsp;2\u3001\u6e90\u4ee3\u7801\u7f16\u8bd1: &nbsp;<br \/>\n11 &nbsp; &nbsp; &nbsp; &nbsp;cd \/lamp\/ncurses-5.9 &nbsp;<br \/>\n12 &nbsp; &nbsp; &nbsp; &nbsp;.\/configure --with-shared --without-debug --without-ada --enable-overwrite &nbsp;<br \/>\n13 &nbsp; &nbsp; &nbsp; &nbsp;make &nbsp;<br \/>\n14 &nbsp; &nbsp; &nbsp; &nbsp;make install &nbsp;<br \/>\n15 &nbsp; &nbsp; &nbsp; &nbsp;* \u82e5\u4e0d\u5b89\u88c5 ncurses \u7f16\u8bd1 MySQL \u65f6\u4f1a\u62a5\u9519 &nbsp;<br \/>\n16 &nbsp; &nbsp; &nbsp; &nbsp;* --without-ada \u53c2\u6570\u4e3a\u8bbe\u5b9a\u4e0d\u7f16\u8bd1\u4e3a ada \u7ed1\u5b9a\uff0c\u56e0\u8fdb\u5165 chroot \u73af\u5883\u4e0d\u80fd\u4f7f\u7528 ada \uff1b &nbsp;<br \/>\n17 &nbsp; &nbsp; &nbsp; &nbsp;--enable-overwrite \u53c2\u6570\u4e3a\u5b9a\u4e49\u628a\u5934\u6587\u4ef6\u5b89\u88c5\u5230\/tools\/include \u4e0b\u800c\u4e0d\u662f &nbsp;<br \/>\n18 &nbsp; &nbsp; &nbsp; &nbsp;\/tools\/include\/ncurses \u76ee\u5f55 &nbsp;<br \/>\n19 &nbsp; &nbsp; &nbsp; &nbsp;* --with-shared &nbsp;\u751f\u6210\u5171\u4eab\u5e93 &nbsp;<br \/>\n20 &nbsp; &nbsp;2.\u5b89\u88c5 cmake \u548c bison &nbsp;<br \/>\n21 &nbsp; &nbsp; &nbsp; &nbsp;mysql \u5728 5.5 \u4ee5\u540e\uff0c\u4e0d\u518d\u4f7f\u7528.\/configure \u5de5\u5177\uff0c\u8fdb\u884c\u7f16\u8bd1\u5b89\u88c5\u3002\u800c\u4f7f\u7528 cmake \u5de5\u5177\u66ff\u4ee3 &nbsp;<br \/>\n22 &nbsp; &nbsp; &nbsp; &nbsp;\u4e86.\/configure \u5de5\u5177\u3002cmake \u7684\u5177\u4f53\u7528\u6cd5\u53c2\u8003\u6587\u6863 cmake \u8bf4\u660e\u3002 &nbsp;<br \/>\n23 &nbsp; &nbsp; &nbsp; &nbsp;bison \u662f\u4e00\u4e2a\u81ea\u7531\u8f6f\u4ef6\uff0c\u7528\u4e8e\u81ea\u52a8\u751f\u6210\u8bed\u6cd5\u5206\u6790\u5668\u7a0b\u5e8f\uff0c\u53ef\u7528\u4e8e\u6240\u6709\u5e38\u89c1\u7684\u64cd\u4f5c\u7cfb &nbsp;<br \/>\n24 &nbsp; &nbsp; &nbsp; &nbsp;\u7edf &nbsp;<br \/>\n25 &nbsp; &nbsp; &nbsp; &nbsp;yum -y install cmake &nbsp;<br \/>\n26 &nbsp; &nbsp; &nbsp; &nbsp;yum -y install bison &nbsp;<br \/>\n27 &nbsp; &nbsp;3. \u5b89\u88c5 MySQL &nbsp; <br \/>\n28 &nbsp; &nbsp; &nbsp; &nbsp;\u4f2a\u7528\u6237 mysql \u5f53\u5b89\u88c5Apache\u5df2\u7ecf\u5b58\u5728 &nbsp;<br \/>\n29 &nbsp; &nbsp; &nbsp; &nbsp;groupadd mysql &nbsp;<br \/>\n30 &nbsp; &nbsp; &nbsp; &nbsp;useradd -g mysql mysql &nbsp;<br \/>\n31 &nbsp; &nbsp; &nbsp; &nbsp;* \u6dfb\u52a0\u7528\u6237\u7ec4 mysql \uff0c\u5c06 mysql \u7528\u6237\u9ed8\u8ba4\u7ec4\u8bbe\u7f6e\u4e3a mysql \u7528\u6237\u7ec4 &nbsp;<br \/>\n32 &nbsp; &nbsp; &nbsp; &nbsp;cd \/lamp\/mysql-5.5.23 &nbsp;<br \/>\n33 &nbsp;<br \/>\n34 &nbsp; &nbsp; &nbsp; &nbsp;cmake -DCMAKE_INSTALL_PREFIX=\/usr\/local\/mysql &nbsp;<br \/>\n35 &nbsp; &nbsp; &nbsp; &nbsp;-DMYSQL_UNIX_ADDR=\/tmp\/mysql.sock -DEXTRA_CHARSETS=all &nbsp;<br \/>\n36 &nbsp; &nbsp; &nbsp; &nbsp;-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci &nbsp;<br \/>\n37 &nbsp; &nbsp; &nbsp; &nbsp;-DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 &nbsp;<br \/>\n38 &nbsp; &nbsp; &nbsp; &nbsp;-DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 &nbsp;<br \/>\n39 &nbsp; &nbsp; &nbsp; &nbsp;-DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 &nbsp;<br \/>\n40 &nbsp;<br \/>\n41 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-DCMAKE_INSTALL_PREFIX=\/usr\/local\/mysql \u5b89\u88c5\u4f4d\u7f6e &nbsp;<br \/>\n42 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-DMYSQL_UNIX_ADDR=\/tmp\/mysql.sock &nbsp;\u6307\u5b9a socket\uff08\u5957\u63a5\u5b57\uff09\u6587\u4ef6\u4f4d\u7f6e &nbsp;<br \/>\n43 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-DEXTRA_CHARSETS=all &nbsp;\u6269\u5c55\u5b57\u7b26\u652f\u6301 &nbsp;<br \/>\n44 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-DDEFAULT_CHARSET=utf8 \u9ed8\u8ba4\u5b57\u7b26\u96c6 &nbsp;<br \/>\n45 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-DDEFAULT_COLLATION=utf8_general_ci \u9ed8\u8ba4\u5b57\u7b26\u6821\u5bf9 &nbsp;<br \/>\n46 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-DWITH_MYISAM_STORAGE_ENGINE=1 \u5b89\u88c5 myisam \u5b58\u50a8\u5f15\u64ce &nbsp;<br \/>\n47 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-DWITH_INNOBASE_STORAGE_ENGINE=1 \u5b89\u88c5 innodb \u5b58\u50a8\u5f15\u64ce &nbsp;<br \/>\n48 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-DWITH_MEMORY_STORAGE_ENGINE=1 \u5b89\u88c5 memory \u5b58\u50a8\u5f15\u64ce &nbsp;<br \/>\n49 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-DWITH_READLINE=1 \u652f\u6301 readline \u5e93 &nbsp;<br \/>\n50 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-DENABLED_LOCAL_INFILE=1 \u542f\u7528\u52a0\u8f7d\u672c\u5730\u6570\u636e &nbsp;<br \/>\n51 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-DMYSQL_USER=mysql \u6307\u5b9a mysql \u8fd0\u884c\u7528\u6237 &nbsp;<br \/>\n52 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-DMYSQL_TCP_PORT=3306 &nbsp;\u6307\u5b9a mysql \u7aef\u53e3 &nbsp;<br \/>\n53 &nbsp; &nbsp; &nbsp; &nbsp;make &nbsp;<br \/>\n54 &nbsp; &nbsp; &nbsp; &nbsp;make install &nbsp;<br \/>\n55 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br \/>\n56 &nbsp; &nbsp; &nbsp; &nbsp;#\u5982\u679c\u62a5\u9519\uff0c\u6e05\u9664\u7f13\u5b58\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0a\u547d\u4ee4 &nbsp;<br \/>\n57 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;make clean &nbsp;<br \/>\n58 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rm -rf CMakeCache.txt &nbsp;<br \/>\n59 &nbsp; &nbsp; &nbsp; &nbsp;#\u4fee\u6539 mysql \u76ee\u5f55\u6743\u9650 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br \/>\n60 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cd \/usr\/local\/mysql\/ &nbsp;<br \/>\n61 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;chown -R mysql . &nbsp;<br \/>\n62 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;chgrp -R mysql . &nbsp;<br \/>\n63 &nbsp; &nbsp; &nbsp; &nbsp;#\u521b\u5efa\u6570\u636e\u5e93\u6388\u6743\u8868\uff0c &nbsp;<br \/>\n64 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u521d\u59cb\u5316\u6570\u636e\u5e93 &nbsp;<br \/>\n65 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/usr\/local\/mysql\/scripts\/mysql_install_db --user=mysql &nbsp;<br \/>\n66 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;root &nbsp;\/etc\/passwd &nbsp;<br \/>\n67 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;root &nbsp;user \u8868 mysql \u5e93 \/usr\/local\/mysql\/data &nbsp;<br \/>\n68 &nbsp; &nbsp; &nbsp; &nbsp;#\u4fee\u6539 mysql \u76ee\u5f55\u6743\u9650 &nbsp;<br \/>\n69 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;chown -R root . &nbsp;<br \/>\n70 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;chown -R mysql data &nbsp;<br \/>\n71 &nbsp; &nbsp; &nbsp; &nbsp;#\u590d\u5236 mysql \u914d\u7f6e\u6587\u4ef6 &nbsp;<br \/>\n72 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cp support-files\/my-medium.cnf \/etc\/my.cnf &nbsp;<br \/>\n73 &nbsp; &nbsp; &nbsp; &nbsp;#\u5728\u8fdb\u884c\u521d\u59cb\u5316\u6570\u636e\u5e93 &nbsp;<br \/>\n74 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/usr\/local\/mysql\/scripts\/mysql_install_db --user=mysql &nbsp;<br \/>\n75 &nbsp; &nbsp;4.\u542f\u52a8 MySQL \u670d\u52a1\uff1a &nbsp;<br \/>\n76 &nbsp; &nbsp; &nbsp; &nbsp;1.\u7528\u539f\u672c\u6e90\u4ee3\u7801\u7684\u65b9\u5f0f\u53bb\u4f7f\u7528\u548c\u542f\u52a8 mysql &nbsp;<br \/>\n77 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/usr\/local\/mysql\/bin\/mysqld_safe --user=mysql &amp;amp; &nbsp;# &amp;amp;\u5e76\u4e14\u653e\u5165\u540e\u53f0 &nbsp;<br \/>\n78 &nbsp; &nbsp; &nbsp; &nbsp;2.\u91cd\u542fLinux\u4ee5\u540e\u8fd8\u8981\u81ea\u542f\u52a8: &nbsp;<br \/>\n79 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;vi \/etc\/rc.local &nbsp;<br \/>\n80 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/usr\/local\/mysql\/bin\/mysqladmin -uroot -p shutdown \u5173\u95edmysql &nbsp;<br \/>\n81 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/usr\/local\/mysql\/bin\/mysqld_safe --user=mysql &amp;amp; &nbsp; #\u6b64\u5904\u7684\u610f\u601d\u662f\u4f7f\u7528mysql \u7528\u6237\u521d\u59cb\u5316 mysql\u6570\u636e\u5e93 &nbsp;<br \/>\n82 &nbsp; &nbsp; &nbsp; &nbsp;3.\u8bbe\u5b9a mysql \u5bc6\u7801 &nbsp;<br \/>\n83 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* \u7ed9 mysql \u7528\u6237 root \u52a0\u5bc6\u7801 123 &nbsp;<br \/>\n84 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* \u6ce8\u610f\u5bc6\u7801\u4e0d\u80fd\u5199\u6210 \u201c123\u201d &nbsp; <br \/>\n85 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/usr\/local\/mysql\/bin\/mysqladmin -u root password 123 &nbsp;#\u6b64\u5904\u7684\u610f\u601d\u662f\u4f7f\u7528mysql \u7528\u6237\u521d\u59cb\u5316 mysql\u6570\u636e\u5e93 &nbsp;<br \/>\n86 &nbsp; &nbsp; &nbsp;<br \/>\n87 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/usr\/local\/mysql\/bin\/mysql -u root -p &nbsp; #\u6b64\u5904\u7684\u610f\u601d\u662f\u767b\u9646mysql &nbsp;<br \/>\n88 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mysql&amp;gt;show databases; &nbsp;<br \/>\n89 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mysql&amp;gt;use test; &nbsp;<br \/>\n90 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mysql&amp;gt;show tables; &nbsp;<br \/>\n91 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mysql&amp;gt;\\s &nbsp;#\u67e5\u770b\u5b57\u7b26\u96c6\u662f\u5426\u6539\u4e3a utf8 &nbsp;<br \/>\n92 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* \u8fdb\u5165 mysql \u4ee5\u540e\u7528 set \u6765\u6539\u5bc6\u7801 &nbsp;<br \/>\n93 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mysql&amp;gt; exit &nbsp;<br \/>\n94 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* \u767b\u5f55 MySQL \u5ba2\u6237\u7aef\u63a7\u5236\u53f0\u8bbe\u7f6e\u6307\u5b9a root \u5bc6\u7801 &nbsp;<br \/>\n95<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<pre>\n\n<div class=\"codecolorer-container text solarized-dark language-bash\" style=\"overflow:auto;white-space:nowrap;width:800px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/><\/div><\/td><td><div class=\"text codecolorer\">12.\u5b89\u88c5\u5b8c\u6bd5\u4ee5\u540e\u914d\u7f6e\u4e3b\u4ece\u6570\u636e\u5e93 \u00a0 \u4e3b\u6570\u636e\u53ea\u8d1f\u8f7d\u5199\u6570\u636e \u00a0\u4ece\u6570\u636e\u5e93\u53ea\u8d1f\u8d23\u8bfb\u6570\u636e <br \/>\n2<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<pre>\n\n<div class=\"codecolorer-container text solarized-dark language-bash\" style=\"overflow:auto;white-space:nowrap;width:800px;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/>32<br \/>33<br \/>34<br \/>35<br \/>36<br \/>37<br \/>38<br \/>39<br \/>40<br \/>41<br \/>42<br \/>43<br \/>44<br \/>45<br \/>46<br \/>47<br \/>48<br \/>49<br \/>50<br \/>51<br \/>52<br \/>53<br \/>54<br \/>55<br \/>56<br \/>57<br \/>58<br \/>59<br \/>60<br \/>61<br \/>62<br \/>63<br \/>64<br \/>65<br \/>66<br \/>67<br \/>68<br \/>69<br \/>70<br \/>71<br \/>72<br \/>73<br \/>74<br \/>75<br \/>76<br \/>77<br \/>78<br \/>79<br \/>80<br \/>81<br \/>82<br \/>83<br \/>84<br \/>85<br \/>86<br \/>87<br \/>88<br \/>89<br \/>90<br \/>91<br \/>92<br \/>93<br \/>94<br \/>95<br \/>96<br \/>97<br \/>98<br \/>99<br \/>100<br \/>101<br \/>102<br \/>103<br \/>104<br \/>105<br \/>106<br \/>107<br \/>108<br \/>109<br \/>110<br \/>111<br \/>112<br \/>113<br \/>114<br \/>115<br \/>116<br \/>117<br \/>118<br \/>119<br \/>120<br \/>121<br \/>122<br \/>123<br \/>124<br \/>125<br \/>126<br \/>127<br \/>128<br \/>129<br \/>130<br \/>131<br \/>132<br \/>133<br \/>134<br \/>135<br \/>136<br \/>137<br \/>138<br \/>139<br \/>140<br \/>141<br \/>142<br \/>143<br \/>144<br \/>145<br \/>146<br \/>147<br \/>148<br \/>149<br \/>150<br \/>151<br \/>152<br \/>153<br \/>154<br \/>155<br \/>156<br \/>157<br \/>158<br \/>159<br \/>160<br \/>161<br \/>162<br \/>163<br \/>164<br \/>165<br \/>166<br \/>167<br \/>168<br \/>169<br \/>170<br \/>171<br \/>172<br \/>173<br \/>174<br \/>175<br \/>176<br \/>177<br \/>178<br \/>179<br \/>180<br \/>181<br \/>182<br \/>183<br \/>184<br \/>185<br \/>186<br \/>187<br \/>188<br \/>189<br \/>190<br \/>191<br \/>192<br \/>193<br \/>194<br \/>195<br \/>196<br \/>197<br \/>198<br \/>199<br \/>200<br \/>201<br \/>202<br \/>203<br \/>204<br \/>205<br \/>206<br \/>207<br \/>208<br \/>209<br \/>210<br \/>211<br \/>212<br \/>213<br \/>214<br \/>215<br \/>216<br \/>217<br \/>218<br \/>219<br \/>220<br \/>221<br \/>222<br \/>223<br \/>224<br \/>225<br \/>226<br \/>227<br \/>228<br \/>229<br \/>230<br \/>231<br \/>232<br \/>233<br \/>234<br \/>235<br \/>236<br \/>237<br \/>238<br \/>239<br \/>240<br \/>241<br \/>242<br \/>243<br \/>244<br \/>245<br \/>246<br \/>247<br \/>248<br \/>249<br \/>250<br \/>251<br \/>252<br \/>253<br \/>254<br \/>255<br \/><\/div><\/td><td><div class=\"text codecolorer\">1 \u4e8c\u3001\u628aMySQL\u4e3b\u670d\u52a1\u5668192.168.117.118\u4e2d\u7684\u6570\u636e\u5e93osyunweidb\u5bfc\u5165\u5230MySQL\u4ece\u670d\u52a1\u5668192.168.117.119\u4e2d &nbsp;<br \/>\n2 &nbsp;<br \/>\n3 &nbsp; &nbsp; &nbsp; &nbsp;1\u3001\u5bfc\u51fa\u6570\u636e\u5e93osyunweidb &nbsp;<br \/>\n4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#\u5728MySQL\u4e3b\u670d\u52a1\u5668\u8fdb\u884c\u64cd\u4f5c\uff0c\u5bfc\u51fa\u6570\u636e\u5e93osyunweidb\u5230\/home\/data5.sql &nbsp;<br \/>\n5 &nbsp; &nbsp; &nbsp; &nbsp;mysqldump -u root -p --default-character-set=utf8 --opt -Q -R --skip-lock-tables osyunweidb &amp;gt; \/home\/data5.sql &nbsp; &nbsp;<br \/>\n6 &nbsp;<br \/>\n7 &nbsp; &nbsp; &nbsp; &nbsp;\u5907\u6ce8\uff1a\u5728\u5bfc\u51fa\u4e4b\u524d\u53ef\u4ee5\u5148\u8fdb\u5165MySQL\u63a7\u5236\u53f0\u6267\u884c\u4e0b\u9762\u547d\u4ee4 &nbsp;<br \/>\n8 &nbsp;<br \/>\n9 &nbsp; &nbsp; &nbsp; &nbsp;flush tables with read lock; &nbsp; &nbsp;#\u6570\u636e\u5e93\u53ea\u8bfb\u9501\u5b9a\u547d\u4ee4\uff0c\u9632\u6b62\u5bfc\u51fa\u6570\u636e\u5e93\u7684\u65f6\u5019\u6709\u6570\u636e\u5199\u5165 &nbsp;<br \/>\n10 &nbsp;<br \/>\n11 &nbsp; &nbsp; &nbsp; &nbsp;unlock tables; &nbsp; #\u89e3\u9664\u9501\u5b9a &nbsp;<br \/>\n12 &nbsp; &nbsp; &nbsp; &nbsp;#\u628ahome\u76ee\u5f55\u4e0b\u7684data5.sql \u6570\u636e\u5e93\u6587\u4ef6\u4e0a\u4f20\u5230MySQL\u4ece\u670d\u52a1\u5668\u7684home\u76ee\u5f55\u4e0b\u9762 &nbsp;<br \/>\n13 &nbsp; &nbsp; &nbsp; &nbsp;scp \/home\/data5.sql root@192.168.117.119:\/home &nbsp; &nbsp; <br \/>\n14 &nbsp;<br \/>\n15 &nbsp; &nbsp; &nbsp; &nbsp;\u7cfb\u7edf\u8fd0\u7ef4 &nbsp;www.osyunwei.com &nbsp;\u6e29\u99a8\u63d0\u9192\uff1aqihang01\u539f\u521b\u5185\u5bb9 \u7248\u6743\u6240\u6709,\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904\u53ca\u539f\u6587\u94fe\u63a5 &nbsp;<br \/>\n16 &nbsp;<br \/>\n17 &nbsp; &nbsp; &nbsp; &nbsp;2\u3001\u5bfc\u5165\u6570\u636e\u5e93\u5230MySQL\u4ece\u670d\u52a1\u5668 &nbsp;<br \/>\n18 &nbsp;<br \/>\n19 &nbsp; &nbsp; &nbsp; &nbsp;mysql &nbsp;-u root -p &nbsp;#\u8fdb\u5165\u4ece\u670d\u52a1\u5668MySQL\u63a7\u5236\u53f0 &nbsp;<br \/>\n20 &nbsp;<br \/>\n21 &nbsp; &nbsp; &nbsp; &nbsp;create database osyunweidb; &nbsp; #\u521b\u5efa\u6570\u636e\u5e93 &nbsp;<br \/>\n22 &nbsp;<br \/>\n23 &nbsp; &nbsp; &nbsp; &nbsp;use osyunweidb &nbsp; &nbsp;#\u8fdb\u5165\u6570\u636e\u5e93 &nbsp;<br \/>\n24 &nbsp;<br \/>\n25 &nbsp; &nbsp; &nbsp; &nbsp;source &nbsp;\/home\/data5.sql &nbsp;#\u5bfc\u5165\u5907\u4efd\u6587\u4ef6\u5230\u6570\u636e\u5e93 &nbsp;<br \/>\n26 &nbsp;<br \/>\n27 &nbsp; &nbsp; &nbsp; &nbsp;mysql -u data5 -h 192.168.117.118 -p &nbsp;#\u6d4b\u8bd5\u5728\u4ece\u670d\u52a1\u5668\u4e0a\u767b\u5f55\u5230\u4e3b\u670d\u52a1\u5668 &nbsp;<br \/>\n28 &nbsp;<br \/>\n29 &nbsp; &nbsp; &nbsp; &nbsp;\u4e09\u3001\u914d\u7f6eMySQL\u4e3b\u670d\u52a1\u5668\uff08192.168.117.118\uff09\u7684my.cnf\u6587\u4ef6 &nbsp;<br \/>\n30 &nbsp;<br \/>\n31 &nbsp; &nbsp; &nbsp; &nbsp;vi \/etc\/my.cnf &nbsp; #\u7f16\u8f91\u914d\u7f6e\u6587\u4ef6\uff0c\u5728[mysqld]\u90e8\u5206\u6dfb\u52a0\u4e0b\u9762\u5185\u5bb9 &nbsp;<br \/>\n32 &nbsp;<br \/>\n33 &nbsp; &nbsp; &nbsp; &nbsp;server-id=1 &nbsp; #\u8bbe\u7f6e\u670d\u52a1\u5668id\uff0c\u4e3a1\u8868\u793a\u4e3b\u670d\u52a1\u5668\uff0c\u6ce8\u610f\uff1a\u5982\u679c\u539f\u6765\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u5df2\u7ecf\u6709\u8fd9\u4e00\u884c\uff0c\u5c31\u4e0d\u7528\u518d\u6dfb\u52a0\u4e86\u3002 &nbsp;<br \/>\n34 &nbsp;<br \/>\n35 &nbsp; &nbsp; &nbsp; &nbsp;log-bin=mysql-bin &nbsp;#\u542f\u52a8MySQ\u4e8c\u8fdb\u5236\u65e5\u5fd7\u7cfb\u7edf\uff0c\u6ce8\u610f\uff1a\u5982\u679c\u539f\u6765\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u5df2\u7ecf\u6709\u8fd9\u4e00\u884c\uff0c\u5c31\u4e0d\u7528\u518d\u6dfb\u52a0\u4e86\u3002 &nbsp;<br \/>\n36 &nbsp;<br \/>\n37 &nbsp; &nbsp; &nbsp; &nbsp;binlog-do-db=osyunweidb &nbsp;#\u9700\u8981\u540c\u6b65\u7684\u6570\u636e\u5e93\u540d\uff0c\u5982\u679c\u6709\u591a\u4e2a\u6570\u636e\u5e93\uff0c\u53ef\u91cd\u590d\u6b64\u53c2\u6570\uff0c\u6bcf\u4e2a\u6570\u636e\u5e93\u4e00\u884c &nbsp;<br \/>\n38 &nbsp;<br \/>\n39 &nbsp; &nbsp; &nbsp; &nbsp;binlog-ignore-db=mysql &nbsp; #\u4e0d\u540c\u6b65mysql\u7cfb\u7edf\u6570\u636e\u5e93 &nbsp;<br \/>\n40 &nbsp;<br \/>\n41 &nbsp; &nbsp; &nbsp; &nbsp;:wq! &nbsp; #\u4fdd\u5b58\u9000\u51fa &nbsp;<br \/>\n42 &nbsp;<br \/>\n43 &nbsp; &nbsp; &nbsp; &nbsp;service mysqld &nbsp;restart &nbsp;#\u91cd\u542fMySQL &nbsp;<br \/>\n44 &nbsp;<br \/>\n45 &nbsp; &nbsp; &nbsp; &nbsp;mysql -u root -p &nbsp; #\u8fdb\u5165mysql\u63a7\u5236\u53f0 &nbsp;<br \/>\n46 &nbsp;<br \/>\n47 &nbsp; &nbsp; &nbsp; &nbsp;show variables like &amp;#x27;server_id&amp;#x27;; &nbsp;#\u67e5\u770bserver-id\u7684\u503c\u662f\u5426\u4e3a1 &nbsp;<br \/>\n48 &nbsp;<br \/>\n49 &nbsp; &nbsp; &nbsp; &nbsp;mysql&amp;gt; show variables like &amp;#x27;server_id&amp;#x27;; &nbsp;<br \/>\n50 &nbsp;<br \/>\n51 &nbsp; &nbsp; &nbsp; &nbsp;+---------------+-------+ &nbsp;<br \/>\n52 &nbsp;<br \/>\n53 &nbsp; &nbsp; &nbsp; &nbsp;| Variable_name | Value | &nbsp;<br \/>\n54 &nbsp;<br \/>\n55 &nbsp; &nbsp; &nbsp; &nbsp;+---------------+-------+ &nbsp;<br \/>\n56 &nbsp;<br \/>\n57 &nbsp; &nbsp; &nbsp; &nbsp;| server_id &nbsp; &nbsp; | 1 &nbsp; &nbsp; | &nbsp;<br \/>\n58 &nbsp;<br \/>\n59 &nbsp; &nbsp; &nbsp; &nbsp;+---------------+-------+ &nbsp;<br \/>\n60 &nbsp;<br \/>\n61 &nbsp; &nbsp; &nbsp; &nbsp;1 row in set (0.00 sec) &nbsp;<br \/>\n62 &nbsp;<br \/>\n63 &nbsp; &nbsp; &nbsp; &nbsp;show master status; &nbsp;#\u67e5\u770b\u4e3b\u670d\u52a1\u5668\uff0c\u51fa\u73b0\u4ee5\u4e0b\u7c7b\u4f3c\u4fe1\u606f &nbsp;<br \/>\n64 &nbsp;<br \/>\n65 &nbsp; &nbsp; &nbsp; &nbsp;mysql&amp;gt; show master status; &nbsp;<br \/>\n66 &nbsp;<br \/>\n67 &nbsp; &nbsp; &nbsp; &nbsp;+------------------+----------+--------------+------------------+ &nbsp;<br \/>\n68 &nbsp;<br \/>\n69 &nbsp; &nbsp; &nbsp; &nbsp;| File &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Position | Binlog_Do_DB | Binlog_Ignore_DB | &nbsp;<br \/>\n70 &nbsp;<br \/>\n71 &nbsp; &nbsp; &nbsp; &nbsp;+------------------+----------+--------------+------------------+ &nbsp;<br \/>\n72 &nbsp;<br \/>\n73 &nbsp; &nbsp; &nbsp; &nbsp;| mysql-bin.000011 | &nbsp; &nbsp; &nbsp;107 | osyunweidb &nbsp; | mysql &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp;<br \/>\n74 &nbsp;<br \/>\n75 &nbsp; &nbsp; &nbsp; &nbsp;+------------------+----------+--------------+------------------+ &nbsp;<br \/>\n76 &nbsp;<br \/>\n77 &nbsp; &nbsp; &nbsp; &nbsp;1 row in set (0.00 sec) &nbsp;<br \/>\n78 &nbsp;<br \/>\n79 &nbsp; &nbsp; &nbsp; &nbsp;\u6ce8\u610f\uff1a\u8fd9\u91cc\u8bb0\u4f4fFile\u7684\u503c\uff1amysql-bin.000011\u548cPosition\u7684\u503c\uff1a107\uff0c\u540e\u9762\u4f1a\u7528\u5230\u3002 &nbsp;<br \/>\n80 &nbsp;<br \/>\n81 &nbsp; &nbsp; &nbsp; &nbsp;\u56db\u3001\u914d\u7f6eMySQL\u4ece\u670d\u52a1\u5668\uff08192.168.117.119\uff09\u7684my.cnf\u6587\u4ef6 &nbsp;<br \/>\n82 &nbsp;<br \/>\n83 &nbsp; &nbsp; &nbsp; &nbsp;vi \/etc\/my.cnf &nbsp; #\u7f16\u8f91\u914d\u7f6e\u6587\u4ef6\uff0c\u5728[mysqld]\u90e8\u5206\u6dfb\u52a0\u4e0b\u9762\u5185\u5bb9 &nbsp;<br \/>\n84 &nbsp;<br \/>\n85 &nbsp; &nbsp; &nbsp; &nbsp;server-id=2 &nbsp; #\u8bbe\u7f6e\u670d\u52a1\u5668id\uff0c\u4fee\u6539\u5176\u503c\u4e3a2\uff0c\u8868\u793a\u4e3a\u4ece\u6570\u636e\u5e93 &nbsp;<br \/>\n86 &nbsp;<br \/>\n87 &nbsp; &nbsp; &nbsp; &nbsp;log-bin=mysql-bin &nbsp;#\u542f\u52a8MySQ\u4e8c\u8fdb\u5236\u65e5\u5fd7\u7cfb\u7edf\uff0c\u6ce8\u610f\uff1a\u5982\u679c\u539f\u6765\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u5df2\u7ecf\u6709\u8fd9\u4e00\u884c\uff0c\u5c31\u4e0d\u7528\u518d\u6dfb\u52a0\u4e86\u3002 &nbsp;<br \/>\n88 &nbsp;<br \/>\n89 &nbsp; &nbsp; &nbsp; &nbsp;replicate-do-db=osyunweidb &nbsp; #\u9700\u8981\u540c\u6b65\u7684\u6570\u636e\u5e93\u540d\uff0c\u5982\u679c\u6709\u591a\u4e2a\u6570\u636e\u5e93\uff0c\u53ef\u91cd\u590d\u6b64\u53c2\u6570\uff0c\u6bcf\u4e2a\u6570\u636e\u5e93\u4e00\u884c &nbsp;<br \/>\n90 &nbsp;<br \/>\n91 &nbsp; &nbsp; &nbsp; &nbsp;replicate-ignore-db=mysql &nbsp; #\u4e0d\u540c\u6b65mysql\u7cfb\u7edf\u6570\u636e\u5e93 &nbsp;<br \/>\n92 &nbsp;<br \/>\n93 &nbsp; &nbsp; &nbsp; &nbsp;read_only &nbsp;#\u8bbe\u7f6e\u6570\u636e\u5e93\u53ea\u8bfb &nbsp;<br \/>\n94 &nbsp;<br \/>\n95 &nbsp; &nbsp; &nbsp; &nbsp;:wq! &nbsp; &nbsp;#\u4fdd\u5b58\u9000\u51fa &nbsp;<br \/>\n96 &nbsp;<br \/>\n97 &nbsp; &nbsp; &nbsp; &nbsp;service mysqld restart &nbsp; #\u91cd\u542fMySQL &nbsp;<br \/>\n98 &nbsp;<br \/>\n99 &nbsp; &nbsp; &nbsp; &nbsp;mysql &nbsp;-u root -p &nbsp;#\u8fdb\u5165MySQL\u63a7\u5236\u53f0 &nbsp;<br \/>\n100 &nbsp;<br \/>\n101 &nbsp; &nbsp; &nbsp; &nbsp;show variables like &amp;#x27;server_id&amp;#x27;; &nbsp;#\u67e5\u770bserver-id\u7684\u503c\uff0c\u5fc5\u987b\u4e3a\u4e0a\u9762\u8bbe\u7f6e\u76842\uff0c\u5426\u5219\u8bf7\u8fd4\u56de\u4fee\u6539\u914d\u7f6e\u6587\u4ef6 &nbsp;<br \/>\n102 &nbsp;<br \/>\n103 &nbsp; &nbsp; &nbsp; &nbsp;mysql&amp;gt; show variables like &amp;#x27;server_id&amp;#x27;; &nbsp;<br \/>\n104 &nbsp;<br \/>\n105 &nbsp; &nbsp; &nbsp; &nbsp;+---------------+-------+ &nbsp;<br \/>\n106 &nbsp;<br \/>\n107 &nbsp; &nbsp; &nbsp; &nbsp;| Variable_name | Value | &nbsp;<br \/>\n108 &nbsp;<br \/>\n109 &nbsp; &nbsp; &nbsp; &nbsp;+---------------+-------+ &nbsp;<br \/>\n110 &nbsp;<br \/>\n111 &nbsp; &nbsp; &nbsp; &nbsp;| server_id &nbsp; &nbsp; | 2 &nbsp; &nbsp; | &nbsp;<br \/>\n112 &nbsp;<br \/>\n113 &nbsp; &nbsp; &nbsp; &nbsp;+---------------+-------+ &nbsp;<br \/>\n114 &nbsp;<br \/>\n115 &nbsp; &nbsp; &nbsp; &nbsp;1 row in set (0.01 sec) &nbsp;<br \/>\n116 &nbsp;<br \/>\n117 &nbsp; &nbsp; &nbsp; &nbsp;slave stop; &nbsp; #\u505c\u6b62slave\u540c\u6b65\u8fdb\u7a0b &nbsp;<br \/>\n118 &nbsp;<br \/>\n119 &nbsp; &nbsp; &nbsp; &nbsp;change master to master_host=&amp;#x27;192.168.117.118&amp;#x27;,master_user=&amp;#x27;data5&amp;#x27;,master_password=&amp;#x27;123456&amp;#x27;, &nbsp;<br \/>\n120 &nbsp; &nbsp; &nbsp; &nbsp;master_log_file=&amp;#x27;mysql-bin.000011&amp;#x27; ,master_log_pos=107; &nbsp; &nbsp;#\u6267\u884c\u540c\u6b65\u8bed\u53e5 &nbsp;<br \/>\n121 &nbsp;<br \/>\n122 &nbsp; &nbsp; &nbsp; &nbsp;slave start; &nbsp; &nbsp;#\u5f00\u542fslave\u540c\u6b65\u8fdb\u7a0b &nbsp;<br \/>\n123 &nbsp;<br \/>\n124 &nbsp; &nbsp; &nbsp; &nbsp;SHOW SLAVE STATUS\\G &nbsp; #\u67e5\u770bslave\u540c\u6b65\u4fe1\u606f\uff0c\u51fa\u73b0\u4ee5\u4e0b\u5185\u5bb9 &nbsp;<br \/>\n125 &nbsp;<br \/>\n126 &nbsp; &nbsp; &nbsp; &nbsp;mysql&amp;gt; SHOW SLAVE STATUS\\G &nbsp;<br \/>\n127 &nbsp;<br \/>\n128 &nbsp; &nbsp; &nbsp; &nbsp;*************************** 1. row *************************** &nbsp;<br \/>\n129 &nbsp;<br \/>\n130 &nbsp; &nbsp; &nbsp; &nbsp;Slave_IO_State: Waiting for master to send event &nbsp;<br \/>\n131 &nbsp;<br \/>\n132 &nbsp; &nbsp; &nbsp; &nbsp;Master_Host: 192.168.117.118 &nbsp;<br \/>\n133 &nbsp;<br \/>\n134 &nbsp; &nbsp; &nbsp; &nbsp;Master_User: data5 &nbsp;<br \/>\n135 &nbsp;<br \/>\n136 &nbsp; &nbsp; &nbsp; &nbsp;Master_Port: 3306 &nbsp;<br \/>\n137 &nbsp;<br \/>\n138 &nbsp; &nbsp; &nbsp; &nbsp;Connect_Retry: 60 &nbsp;<br \/>\n139 &nbsp;<br \/>\n140 &nbsp; &nbsp; &nbsp; &nbsp;Master_Log_File: mysql-bin.000011 &nbsp;<br \/>\n141 &nbsp;<br \/>\n142 &nbsp; &nbsp; &nbsp; &nbsp;Read_Master_Log_Pos: 107 &nbsp;<br \/>\n143 &nbsp;<br \/>\n144 &nbsp; &nbsp; &nbsp; &nbsp;Relay_Log_File: mysqlslave-relay-bin.000004 &nbsp;<br \/>\n145 &nbsp;<br \/>\n146 &nbsp; &nbsp; &nbsp; &nbsp;Relay_Log_Pos: 253 &nbsp;<br \/>\n147 &nbsp;<br \/>\n148 &nbsp; &nbsp; &nbsp; &nbsp;Relay_Master_Log_File: mysql-bin.000011 &nbsp;<br \/>\n149 &nbsp;<br \/>\n150 &nbsp; &nbsp; &nbsp; &nbsp;Slave_IO_Running: Yes &nbsp;<br \/>\n151 &nbsp;<br \/>\n152 &nbsp; &nbsp; &nbsp; &nbsp;Slave_SQL_Running: Yes &nbsp;<br \/>\n153 &nbsp;<br \/>\n154 &nbsp; &nbsp; &nbsp; &nbsp;Replicate_Do_DB: osyunweidb &nbsp;<br \/>\n155 &nbsp;<br \/>\n156 &nbsp; &nbsp; &nbsp; &nbsp;Replicate_Ignore_DB: mysql &nbsp;<br \/>\n157 &nbsp;<br \/>\n158 &nbsp; &nbsp; &nbsp; &nbsp;Replicate_Do_Table: &nbsp;<br \/>\n159 &nbsp;<br \/>\n160 &nbsp; &nbsp; &nbsp; &nbsp;Replicate_Ignore_Table: &nbsp;<br \/>\n161 &nbsp;<br \/>\n162 &nbsp; &nbsp; &nbsp; &nbsp;Replicate_Wild_Do_Table: &nbsp;<br \/>\n163 &nbsp;<br \/>\n164 &nbsp; &nbsp; &nbsp; &nbsp;Replicate_Wild_Ignore_Table: &nbsp;<br \/>\n165 &nbsp;<br \/>\n166 &nbsp; &nbsp; &nbsp; &nbsp;Last_Errno: 0 &nbsp;<br \/>\n167 &nbsp;<br \/>\n168 &nbsp; &nbsp; &nbsp; &nbsp;Last_Error: &nbsp;<br \/>\n169 &nbsp;<br \/>\n170 &nbsp; &nbsp; &nbsp; &nbsp;Skip_Counter: 0 &nbsp;<br \/>\n171 &nbsp;<br \/>\n172 &nbsp; &nbsp; &nbsp; &nbsp;Exec_Master_Log_Pos: 107 &nbsp;<br \/>\n173 &nbsp;<br \/>\n174 &nbsp; &nbsp; &nbsp; &nbsp;Relay_Log_Space: 560 &nbsp;<br \/>\n175 &nbsp;<br \/>\n176 &nbsp; &nbsp; &nbsp; &nbsp;Until_Condition: None &nbsp;<br \/>\n177 &nbsp;<br \/>\n178 &nbsp; &nbsp; &nbsp; &nbsp;Until_Log_File: &nbsp;<br \/>\n179 &nbsp;<br \/>\n180 &nbsp; &nbsp; &nbsp; &nbsp;Until_Log_Pos: 0 &nbsp;<br \/>\n181 &nbsp;<br \/>\n182 &nbsp; &nbsp; &nbsp; &nbsp;Master_SSL_Allowed: No &nbsp;<br \/>\n183 &nbsp;<br \/>\n184 &nbsp; &nbsp; &nbsp; &nbsp;Master_SSL_CA_File: &nbsp;<br \/>\n185 &nbsp;<br \/>\n186 &nbsp; &nbsp; &nbsp; &nbsp;Master_SSL_CA_Path: &nbsp;<br \/>\n187 &nbsp;<br \/>\n188 &nbsp; &nbsp; &nbsp; &nbsp;Master_SSL_Cert: &nbsp;<br \/>\n189 &nbsp;<br \/>\n190 &nbsp; &nbsp; &nbsp; &nbsp;Master_SSL_Cipher: &nbsp;<br \/>\n191 &nbsp;<br \/>\n192 &nbsp; &nbsp; &nbsp; &nbsp;Master_SSL_Key: &nbsp;<br \/>\n193 &nbsp;<br \/>\n194 &nbsp; &nbsp; &nbsp; &nbsp;Seconds_Behind_Master: 0 &nbsp;<br \/>\n195 &nbsp;<br \/>\n196 &nbsp; &nbsp; &nbsp; &nbsp;Master_SSL_Verify_Server_Cert: No &nbsp;<br \/>\n197 &nbsp;<br \/>\n198 &nbsp; &nbsp; &nbsp; &nbsp;Last_IO_Errno: 0 &nbsp;<br \/>\n199 &nbsp;<br \/>\n200 &nbsp; &nbsp; &nbsp; &nbsp;Last_IO_Error: &nbsp;<br \/>\n201 &nbsp;<br \/>\n202 &nbsp; &nbsp; &nbsp; &nbsp;Last_SQL_Errno: 0 &nbsp;<br \/>\n203 &nbsp;<br \/>\n204 &nbsp; &nbsp; &nbsp; &nbsp;Last_SQL_Error: &nbsp;<br \/>\n205 &nbsp;<br \/>\n206 &nbsp; &nbsp; &nbsp; &nbsp;Replicate_Ignore_Server_Ids: &nbsp;<br \/>\n207 &nbsp;<br \/>\n208 &nbsp; &nbsp; &nbsp; &nbsp;Master_Server_Id: 1 &nbsp;<br \/>\n209 &nbsp;<br \/>\n210 &nbsp; &nbsp; &nbsp; &nbsp;1 row in set (0.00 sec) &nbsp;<br \/>\n211 &nbsp;<br \/>\n212 &nbsp; &nbsp; &nbsp; &nbsp;mysql&amp;gt; &nbsp;<br \/>\n213 &nbsp;<br \/>\n214 &nbsp; &nbsp; &nbsp; &nbsp;\u6ce8\u610f\u67e5\u770b\uff1a &nbsp;<br \/>\n215 &nbsp;<br \/>\n216 &nbsp; &nbsp; &nbsp; &nbsp;Slave_IO_Running: Yes &nbsp;<br \/>\n217 &nbsp;<br \/>\n218 &nbsp; &nbsp; &nbsp; &nbsp;Slave_SQL_Running: Yes &nbsp;<br \/>\n219 &nbsp;<br \/>\n220 &nbsp; &nbsp; &nbsp; &nbsp;\u4ee5\u4e0a\u8fd9\u4e24\u4e2a\u53c2\u6570\u7684\u503c\u4e3aYes\uff0c\u5373\u8bf4\u660e\u914d\u7f6e\u6210\u529f\uff01 &nbsp;<br \/>\n221 &nbsp;<br \/>\n222 &nbsp; &nbsp; &nbsp; &nbsp;\u6d4b\u8bd5\u7bc7 &nbsp;<br \/>\n223 &nbsp;<br \/>\n224 &nbsp; &nbsp; &nbsp; &nbsp;\u6d4b\u8bd5MySQL\u4e3b\u4ece\u670d\u52a1\u5668\u662f\u5426\u6b63\u5e38\u8fd0\u884c &nbsp;<br \/>\n225 &nbsp;<br \/>\n226 &nbsp; &nbsp; &nbsp; &nbsp;1\u3001\u8fdb\u5165MySQL\u4e3b\u670d\u52a1\u5668\uff08192.168.117.118\uff09 &nbsp;<br \/>\n227 &nbsp;<br \/>\n228 &nbsp; &nbsp; &nbsp; &nbsp;mysql -u root -p &nbsp;#\u8fdb\u5165MySQL\u63a7\u5236\u53f0 &nbsp;<br \/>\n229 &nbsp;<br \/>\n230 &nbsp; &nbsp; &nbsp; &nbsp;use osyunweidb &nbsp; #\u8fdb\u5165\u6570\u636e\u5e93 &nbsp;<br \/>\n231 &nbsp;<br \/>\n232 &nbsp; &nbsp; &nbsp; &nbsp;CREATE TABLE test ( id int not null primary key,name char(20) ); &nbsp; #\u521b\u5efatest\u8868 &nbsp;<br \/>\n233 &nbsp;<br \/>\n234 &nbsp; &nbsp; &nbsp; &nbsp;2\u3001\u8fdb\u5165MySQL\u4ece\u670d\u52a1\u5668 &nbsp;<br \/>\n235 &nbsp;<br \/>\n236 &nbsp; &nbsp; &nbsp; &nbsp;mysql -u root -p &nbsp;#\u8fdb\u5165MySQL\u63a7\u5236\u53f0 &nbsp;<br \/>\n237 &nbsp;<br \/>\n238 &nbsp; &nbsp; &nbsp; &nbsp;use osyunweidb &nbsp; #\u8fdb\u5165\u6570\u636e\u5e93 &nbsp;<br \/>\n239 &nbsp;<br \/>\n240 &nbsp; &nbsp; &nbsp; &nbsp;show &nbsp;tables; &nbsp;#\u67e5\u770bosyunweidb\u8868\u7ed3\u6784\uff0c\u4f1a\u770b\u5230\u6709\u4e00\u4e2a\u65b0\u5efa\u7684\u8868test\uff0c\u8868\u793a\u6570\u636e\u5e93\u540c\u6b65\u6210\u529f &nbsp;<br \/>\n241 &nbsp;<br \/>\n242 &nbsp; &nbsp; &nbsp; &nbsp;mysql&amp;gt; show &nbsp;tables; &nbsp;<br \/>\n243 &nbsp;<br \/>\n244 &nbsp; &nbsp; &nbsp; &nbsp;+----------------------+ &nbsp;<br \/>\n245 &nbsp;<br \/>\n246 &nbsp; &nbsp; &nbsp; &nbsp;| Tables_in_osyunweidb | &nbsp;<br \/>\n247 &nbsp;<br \/>\n248 &nbsp; &nbsp; &nbsp; &nbsp;+----------------------+ &nbsp;<br \/>\n249 &nbsp;<br \/>\n250 &nbsp; &nbsp; &nbsp; &nbsp;| test &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | &nbsp;<br \/>\n251 &nbsp;<br \/>\n252 &nbsp; &nbsp; &nbsp; &nbsp;+----------------------+ &nbsp;<br \/>\n253 &nbsp;<br \/>\n254 &nbsp; &nbsp; &nbsp; &nbsp;1 row in set (0.00 sec) &nbsp;<br \/>\n255<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<p>3.\u5728java\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u914d\u7f6e\u4e24\u4e2a\u6570\u636e\u6e90\u5730\u5740<\/p>\n<p>4.\u5728java\u914d\u7f6e\u6587\u4ef6\u4e2d\u8fdb\u884c\u6570\u636e\u6e90\u914d\u7f6e\u7ba1\u7406<\/p>\n<pre>\n\n<div class=\"codecolorer-container text solarized-dark language-java\" style=\"overflow:auto;white-space:nowrap;width:800px;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/>32<br \/>33<br \/>34<br \/>35<br \/>36<br \/>37<br \/>38<br \/>39<br \/>40<br \/>41<br \/>42<br \/>43<br \/>44<br \/>45<br \/>46<br \/>47<br \/>48<br \/>49<br \/>50<br \/>51<br \/>52<br \/>53<br \/>54<br \/>55<br \/>56<br \/>57<br \/>58<br \/>59<br \/>60<br \/>61<br \/>62<br \/>63<br \/>64<br \/>65<br \/>66<br \/>67<br \/>68<br \/>69<br \/>70<br \/>71<br \/>72<br \/>73<br \/>74<br \/>75<br \/>76<br \/>77<br \/>78<br \/>79<br \/>80<br \/>81<br \/>82<br \/>83<br \/>84<br \/>85<br \/>86<br \/>87<br \/>88<br \/>89<br \/>90<br \/>91<br \/>92<br \/>93<br \/>94<br \/>95<br \/>96<br \/>97<br \/>98<br \/>99<br \/>100<br \/>101<br \/>102<br \/>103<br \/>104<br \/>105<br \/>106<br \/>107<br \/>108<br \/>109<br \/>110<br \/>111<br \/><\/div><\/td><td><div class=\"text codecolorer\">1package com.company.test.base.config;<br \/>\n2<br \/>\n3import java.util.HashMap;<br \/>\n4import java.util.Map;<br \/>\n5import java.util.Properties;<br \/>\n6<br \/>\n7import javax.sql.DataSource;<br \/>\n8<br \/>\n9import org.apache.ibatis.session.SqlSessionFactory;<br \/>\n10import org.mybatis.spring.SqlSessionFactoryBean;<br \/>\n11import org.mybatis.spring.annotation.MapperScan;<br \/>\n12import org.springframework.beans.factory.annotation.Autowired;<br \/>\n13import org.springframework.beans.factory.annotation.Qualifier;<br \/>\n14import org.springframework.context.annotation.Bean;<br \/>\n15import org.springframework.context.annotation.Configuration;<br \/>\n16import org.springframework.context.annotation.Primary;<br \/>\n17import org.springframework.core.env.Environment;<br \/>\n18import org.springframework.core.io.support.PathMatchingResourcePatternResolver;<br \/>\n19import org.springframework.jdbc.datasource.DataSourceTransactionManager;<br \/>\n20import org.springframework.transaction.annotation.EnableTransactionManagement;<br \/>\n21<br \/>\n22import com.alibaba.druid.pool.DruidDataSourceFactory;<br \/>\n23<br \/>\n24<br \/>\n25<br \/>\n26\/**<br \/>\n27 * <br \/>\n28 * springboot\u96c6\u6210mybatis\u7684\u57fa\u672c\u5165\u53e3 1\uff09\u521b\u5efa\u6570\u636e\u6e90(\u5982\u679c\u91c7\u7528\u7684\u662f\u9ed8\u8ba4\u7684tomcat-jdbc\u6570\u636e\u6e90\uff0c\u5219\u4e0d\u9700\u8981)<br \/>\n29 * 2\uff09\u521b\u5efaSqlSessionFactory 3\uff09\u914d\u7f6e\u4e8b\u52a1\u7ba1\u7406\u5668\uff0c\u9664\u975e\u9700\u8981\u4f7f\u7528\u4e8b\u52a1\uff0c\u5426\u5219\u4e0d\u7528\u914d\u7f6e<br \/>\n30 *\/<br \/>\n31@Configuration \/\/ \u8be5\u6ce8\u89e3\u7c7b\u4f3c\u4e8espring\u914d\u7f6e\u6587\u4ef6<br \/>\n32@MapperScan(basePackages = &amp;quot;com.company.test.dao&amp;quot;) \/\/\u914d\u7f6emapper\u63a5\u53e3\u7684\u4f4d\u7f6e<br \/>\n33@EnableTransactionManagement &nbsp;\/\/Spring\u4e8b\u52a1\u7ba1\u7406\u5668<br \/>\n34public class MyBatisConfig {<br \/>\n35\/**<br \/>\n36 \u4f5c\u7528\uff1a<br \/>\n37<br \/>\n38\u901a\u8fc7\u8bfb\u53d6application.properties\u6587\u4ef6\u751f\u6210\u4e24\u4e2a\u6570\u636e\u6e90\uff08data1\u3001data5\uff09<br \/>\n39\u4f7f\u7528\u4ee5\u4e0a\u751f\u6210\u7684\u4e24\u4e2a\u6570\u636e\u6e90\u6784\u9020\u52a8\u6001\u6570\u636e\u6e90dataSource<br \/>\n40&nbsp; @Primary\uff1a\u6307\u5b9a\u5728\u540c\u4e00\u4e2a\u63a5\u53e3\u6709\u591a\u4e2a\u5b9e\u73b0\u7c7b\u53ef\u4ee5\u6ce8\u5165\u7684\u65f6\u5019\uff0c\u9ed8\u8ba4\u9009\u62e9\u54ea\u4e00\u4e2a\uff0c\u800c\u4e0d\u662f\u8ba9@Autowire\u6ce8\u89e3\u62a5\u9519\uff08\u4e00\u822c\u7528\u4e8e\u591a\u6570\u636e\u6e90\u7684\u60c5\u51b5\u4e0b\uff09<br \/>\n41&nbsp; @Qualifier\uff1a\u6307\u5b9a\u540d\u79f0\u7684\u6ce8\u5165\uff0c\u5f53\u4e00\u4e2a\u63a5\u53e3\u6709\u591a\u4e2a\u5b9e\u73b0\u7c7b\u7684\u65f6\u5019\u4f7f\u7528\uff08\u5728\u672c\u4f8b\u4e2d\uff0c\u6709\u4e24\u4e2aDataSource\u7c7b\u578b\u7684\u5b9e\u4f8b\uff0c\u9700\u8981\u6307\u5b9a\u540d\u79f0\u6ce8\u5165\uff09<br \/>\n42&nbsp; @Bean\uff1a\u751f\u6210\u7684bean\u5b9e\u4f8b\u7684\u540d\u79f0\u662f\u65b9\u6cd5\u540d\uff08\u4f8b\u5982\u4e0a\u8fb9\u7684@Qualifier\u6ce8\u89e3\u4e2d\u4f7f\u7528\u7684\u540d\u79f0\u662f\u524d\u8fb9\u4e24\u4e2a\u6570\u636e\u6e90\u7684\u65b9\u6cd5\u540d\uff0c\u800c\u8fd9\u4e24\u4e2a\u6570\u636e\u6e90\u4e5f\u662f\u4f7f\u7528@Bean\u6ce8\u89e3\u8fdb\u884c\u6ce8\u5165\u7684\uff09<br \/>\n43\u901a\u8fc7\u52a8\u6001\u6570\u636e\u6e90\u6784\u9020SqlSessionFactory\u548c\u4e8b\u52a1\u7ba1\u7406\u5668\uff08\u5982\u679c\u4e0d\u9700\u8981\u4e8b\u52a1\uff0c\u540e\u8005\u53ef\u4ee5\u53bb\u6389\uff09 <br \/>\n44 * <br \/>\n45 *\/<br \/>\n46 &nbsp; &nbsp;@Autowired<br \/>\n47 &nbsp; &nbsp;private Environment env;<br \/>\n48<br \/>\n49 &nbsp; &nbsp;\/**<br \/>\n50 &nbsp; &nbsp; * \u521b\u5efa\u6570\u636e\u6e90(\u6570\u636e\u6e90\u7684\u540d\u79f0\uff1a\u65b9\u6cd5\u540d\u53ef\u4ee5\u53d6\u4e3aXXXDataSource(),XXX\u4e3a\u6570\u636e\u5e93\u540d\u79f0,\u8be5\u540d\u79f0\u4e5f\u5c31\u662f\u6570\u636e\u6e90\u7684\u540d\u79f0)<br \/>\n51 &nbsp; &nbsp; *\/<br \/>\n52 &nbsp; &nbsp;@Bean<br \/>\n53 &nbsp; &nbsp;public DataSource myTestDbDataSource() throws Exception {<br \/>\n54 &nbsp; &nbsp; &nbsp; &nbsp;Properties props = new Properties();<br \/>\n55 &nbsp; &nbsp; &nbsp; &nbsp;props.put(&amp;quot;driverClassName&amp;quot;, env.getProperty(&amp;quot;jdbc.driverClassName&amp;quot;));<br \/>\n56 &nbsp; &nbsp; &nbsp; &nbsp;props.put(&amp;quot;url&amp;quot;, env.getProperty(&amp;quot;jdbc.url&amp;quot;));<br \/>\n57 &nbsp; &nbsp; &nbsp; &nbsp;props.put(&amp;quot;username&amp;quot;, env.getProperty(&amp;quot;jdbc.username&amp;quot;));<br \/>\n58 &nbsp; &nbsp; &nbsp; &nbsp;props.put(&amp;quot;password&amp;quot;, env.getProperty(&amp;quot;jdbc.password&amp;quot;));<br \/>\n59 &nbsp; &nbsp; &nbsp; &nbsp;return DruidDataSourceFactory.createDataSource(props);<br \/>\n60 &nbsp; &nbsp;}<br \/>\n61<br \/>\n62 &nbsp; &nbsp;@Bean<br \/>\n63 &nbsp; &nbsp;public DataSource myTestDb2DataSource() throws Exception {<br \/>\n64 &nbsp; &nbsp; &nbsp; &nbsp;Properties props = new Properties();<br \/>\n65 &nbsp; &nbsp; &nbsp; &nbsp;props.put(&amp;quot;driverClassName&amp;quot;, env.getProperty(&amp;quot;jdbc2.driverClassName&amp;quot;));<br \/>\n66 &nbsp; &nbsp; &nbsp; &nbsp;props.put(&amp;quot;url&amp;quot;, env.getProperty(&amp;quot;jdbc2.url&amp;quot;));<br \/>\n67 &nbsp; &nbsp; &nbsp; &nbsp;props.put(&amp;quot;username&amp;quot;, env.getProperty(&amp;quot;jdbc2.username&amp;quot;));<br \/>\n68 &nbsp; &nbsp; &nbsp; &nbsp;props.put(&amp;quot;password&amp;quot;, env.getProperty(&amp;quot;jdbc2.password&amp;quot;));<br \/>\n69 &nbsp; &nbsp; &nbsp; &nbsp;return DruidDataSourceFactory.createDataSource(props);<br \/>\n70 &nbsp; &nbsp;}<br \/>\n71<br \/>\n72 &nbsp; &nbsp;\/**<br \/>\n73 &nbsp; &nbsp; * @Primary \u8be5\u6ce8\u89e3\u8868\u793a\u5728\u540c\u4e00\u4e2a\u63a5\u53e3\u6709\u591a\u4e2a\u5b9e\u73b0\u7c7b\u53ef\u4ee5\u6ce8\u5165\u7684\u65f6\u5019\uff0c\u9ed8\u8ba4\u9009\u62e9\u54ea\u4e00\u4e2a\uff0c\u800c\u4e0d\u662f\u8ba9@autowire\u6ce8\u89e3\u62a5\u9519<br \/>\n74 &nbsp; &nbsp; * @Qualifier \u6839\u636e\u540d\u79f0\u8fdb\u884c\u6ce8\u5165\uff0c\u901a\u5e38\u662f\u5728\u5177\u6709\u76f8\u540c\u7684\u591a\u4e2a\u7c7b\u578b\u7684\u5b9e\u4f8b\u7684\u4e00\u4e2a\u6ce8\u5165\uff08\u4f8b\u5982\u6709\u591a\u4e2aDataSource\u7c7b\u578b\u7684\u5b9e\u4f8b\uff09<br \/>\n75 &nbsp; &nbsp; *\/<br \/>\n76 &nbsp; &nbsp;@Bean<br \/>\n77 &nbsp; &nbsp;@Primary<br \/>\n78 &nbsp; &nbsp;public DynamicDataSource dataSource(@Qualifier(&amp;quot;myTestDbDataSource&amp;quot;) DataSource myTestDbDataSource,<br \/>\n79 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@Qualifier(&amp;quot;myTestDb2DataSource&amp;quot;) DataSource myTestDb2DataSource) {<br \/>\n80 &nbsp; &nbsp; &nbsp; &nbsp;Map&amp;lt;Object, Object&amp;gt; targetDataSources = new HashMap&amp;lt;&amp;gt;();<br \/>\n81 &nbsp; &nbsp; &nbsp; &nbsp;targetDataSources.put(DatabaseType.data, myTestDbDataSource);<br \/>\n82 &nbsp; &nbsp; &nbsp; &nbsp;targetDataSources.put(DatabaseType.data5, myTestDb2DataSource);<br \/>\n83 &nbsp; &nbsp; &nbsp; &nbsp;DynamicDataSource dataSource = new DynamicDataSource();<br \/>\n84 &nbsp; &nbsp; &nbsp; &nbsp;dataSource.setTargetDataSources(targetDataSources);\/\/ \u8be5\u65b9\u6cd5\u662fAbstractRoutingDataSource\u7684\u65b9\u6cd5<br \/>\n85\/\/ &nbsp; &nbsp; &nbsp; &nbsp;dataSource.setDefaultTargetDataSource(myTestDb2DataSource);\/\/ \u9ed8\u8ba4\u7684datasource\u8bbe\u7f6e\u4e3amyTestDbDataSource<br \/>\n86 &nbsp; &nbsp; &nbsp; &nbsp;return dataSource;<br \/>\n87 &nbsp; &nbsp;}<br \/>\n88 &nbsp; &nbsp;\/**<br \/>\n89 &nbsp; &nbsp; * \u6839\u636e\u6570\u636e\u6e90\u521b\u5efaSqlSessionFactory<br \/>\n90 &nbsp; &nbsp; *\/<br \/>\n91 &nbsp; &nbsp;@Bean(name=&amp;quot;sqlSessionFactory&amp;quot;)<br \/>\n92 &nbsp; &nbsp;public SqlSessionFactory sqlSessionFactory(DynamicDataSource ds) throws Exception {<br \/>\n93 &nbsp; &nbsp; &nbsp; &nbsp;SqlSessionFactoryBean fb = new SqlSessionFactoryBean();<br \/>\n94 &nbsp; &nbsp; &nbsp; &nbsp;fb.setDataSource(ds);\/\/ \u6307\u5b9a\u6570\u636e\u6e90(\u8fd9\u4e2a\u5fc5\u987b\u6709\uff0c\u5426\u5219\u62a5\u9519)<br \/>\n95 &nbsp; &nbsp; &nbsp; &nbsp;\/\/ \u4e0b\u8fb9\u4e24\u53e5\u4ec5\u4ec5\u7528\u4e8e*.xml\u6587\u4ef6\uff0c\u5982\u679c\u6574\u4e2a\u6301\u4e45\u5c42\u64cd\u4f5c\u4e0d\u9700\u8981\u4f7f\u7528\u5230xml\u6587\u4ef6\u7684\u8bdd\uff08\u53ea\u7528\u6ce8\u89e3\u5c31\u53ef\u4ee5\u641e\u5b9a\uff09\uff0c\u5219\u4e0d\u52a0<br \/>\n96 &nbsp; &nbsp; &nbsp; &nbsp;fb.setTypeAliasesPackage(env.getProperty(&amp;quot;mybatis.typeAliasesPackage&amp;quot;));\/\/ \u6307\u5b9a\u57fa\u5305<br \/>\n97 &nbsp; &nbsp; &nbsp; &nbsp;fb.setMapperLocations(<br \/>\n98 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new PathMatchingResourcePatternResolver().getResources(env.getProperty(&amp;quot;mybatis.mapperLocations&amp;quot;)));\/\/<br \/>\n99<br \/>\n100 &nbsp; &nbsp; &nbsp; &nbsp;return fb.getObject();<br \/>\n101 &nbsp; &nbsp;}<br \/>\n102 &nbsp; &nbsp;\/**<br \/>\n103 &nbsp; &nbsp; * \u914d\u7f6e\u4e8b\u52a1\u7ba1\u7406\u5668<br \/>\n104 &nbsp; &nbsp; *\/<br \/>\n105 &nbsp; &nbsp;@Bean<br \/>\n106 &nbsp; &nbsp;public DataSourceTransactionManager transactionManager(DynamicDataSource dataSource) throws Exception {<br \/>\n107 &nbsp; &nbsp; &nbsp; &nbsp;return new DataSourceTransactionManager(dataSource);<br \/>\n108 &nbsp; &nbsp;}<br \/>\n109<br \/>\n110}<br \/>\n111<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<pre>\n\n<div class=\"codecolorer-container text solarized-dark language-bash\" style=\"overflow:auto;white-space:nowrap;width:800px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/><\/div><\/td><td><div class=\"text codecolorer\">15.\u4f7f\u7528Spring \u5207\u5165\u70b9\u52a8\u6001\u5207\u6362\u6570\u636e\u6e90 \u00a0\u67e5\u6570\u636e\u5230 data5\u6570\u636e\u6e90 \u589e\u5220\u6539\u67e5\u5230 data1\u6570\u636e\u6e90 <br \/>\n2<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<pre>\n\n<div class=\"codecolorer-container text solarized-dark language-java\" style=\"overflow:auto;white-space:nowrap;width:800px;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/>32<br \/>33<br \/>34<br \/>35<br \/>36<br \/>37<br \/>38<br \/><\/div><\/td><td><div class=\"text codecolorer\">1package com.company.test.base.config;<br \/>\n2<br \/>\n3import org.apache.commons.lang3.StringUtils;<br \/>\n4import org.aspectj.lang.JoinPoint;<br \/>\n5import org.aspectj.lang.annotation.Aspect;<br \/>\n6import org.aspectj.lang.annotation.Before;<br \/>\n7import org.aspectj.lang.annotation.Pointcut;<br \/>\n8import org.springframework.stereotype.Component;<br \/>\n9<br \/>\n10<br \/>\n11@Aspect<br \/>\n12@Component<br \/>\n13public class DataSourceAspect {<br \/>\n14 &nbsp; &nbsp;\/**<br \/>\n15 &nbsp; &nbsp; * \u4f7f\u7528\u7a7a\u65b9\u6cd5\u5b9a\u4e49\u5207\u70b9\u8868\u8fbe\u5f0f<br \/>\n16 &nbsp; &nbsp; *\/<br \/>\n17 &nbsp; &nbsp;@Pointcut(&amp;quot;execution(* com.company.test.dao.*.*(..))&amp;quot;)<br \/>\n18 &nbsp; &nbsp;public void declareJointPointExpression() {<br \/>\n19 &nbsp; &nbsp;}<br \/>\n20<br \/>\n21 &nbsp; &nbsp;\/**<br \/>\n22 &nbsp; &nbsp; * \u4f7f\u7528\u5b9a\u4e49\u5207\u70b9\u8868\u8fbe\u5f0f\u7684\u65b9\u6cd5\u8fdb\u884c\u5207\u70b9\u8868\u8fbe\u5f0f\u7684\u5f15\u5165<br \/>\n23 &nbsp; &nbsp; *\/<br \/>\n24 &nbsp; &nbsp;@Before(&amp;quot;declareJointPointExpression()&amp;quot;)<br \/>\n25 &nbsp; &nbsp;\/\/\u91c7\u7528Mysql\u4e3b\u4ece\u590d\u5236 &nbsp;\u8bfb\u5199\u5206\u79bb &nbsp; &nbsp;\u8bfb\u6570\u636e\u5728data5 \u5199\u6570\u636e\u5728data1\u6570\u636e\u5e93 <br \/>\n26 &nbsp; &nbsp;public void setDataSourceKey(JoinPoint point) {<br \/>\n27 &nbsp; &nbsp;&nbsp; String methodName = point.getSignature().getName(); &nbsp; \/\/ \u83b7\u53d6Method\u540d\u79f0<br \/>\n28 &nbsp; &nbsp;&nbsp; boolean flag = false;<br \/>\n29 &nbsp; &nbsp;&nbsp; flag = StringUtils.startsWithAny(methodName, &amp;quot;query&amp;quot;, &amp;quot;find&amp;quot;, &amp;quot;get&amp;quot;); &nbsp;<br \/>\n30 &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if(flag){<br \/>\n31 &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DatabaseContextHolder.setDatabaseType(DatabaseType.data5);<br \/>\n32 &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; }else{<br \/>\n33 &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DatabaseContextHolder.setDatabaseType(DatabaseType.data);<br \/>\n34 &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; }<br \/>\n35 &nbsp; &nbsp;}<br \/>\n36<br \/>\n37}<br \/>\n38<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<pre>\n\n<div class=\"codecolorer-container text solarized-dark language-bash\" style=\"overflow:auto;white-space:nowrap;width:800px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/><\/div><\/td><td><div class=\"text codecolorer\">16.\u4ee5Controller\u5c42\u65b9\u6cd5\u540d\u79f0\u8fdb\u884c\u533a\u5206 &nbsp;<br \/>\n2<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u56db\uff1amysql\u4e3b\u4ece\u590d\u5236\uff0c\u8bfb\u5199\u5206\u79bb 1.\u9996\u5148\u628amysql\u6e90\u7801\u5305\u6587\u4ef6\u62f7\u5230\u4e24\u53f0linux\u670d\u52a1\u5668\u4e0a\uff0c\u7136\u540e\u5728\u4e24\u53f0\u670d\u52a1\u5668\u4e0a\u5b89\u88c5Mysql\u6570\u636e\u5e93 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394951\u5b89\u88c5 MySQL &#038;nb<\/p>\n","protected":false},"author":1,"featured_media":6522,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[7],"tags":[292,17,187,181,14,23,26,25,21,10,500,289,159,18],"collection":[],"_links":{"self":[{"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/posts\/16784"}],"collection":[{"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/comments?post=16784"}],"version-history":[{"count":0,"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/posts\/16784\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/media\/6522"}],"wp:attachment":[{"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/media?parent=16784"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/categories?post=16784"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/tags?post=16784"},{"taxonomy":"collection","embeddable":true,"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/collection?post=16784"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}