{"id":3151,"date":"2020-08-25T19:11:13","date_gmt":"2020-08-25T11:11:13","guid":{"rendered":"http:\/\/www.fatesky.com\/?p=3151"},"modified":"2024-03-19T21:58:10","modified_gmt":"2024-03-19T13:58:10","slug":"%e3%80%90uos%e8%bf%90%e7%bb%b4%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0%e3%80%91-%e6%95%b0%e6%8d%ae%e5%ba%93%e7%ae%a1%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.fatesky.com\/?p=3151","title":{"rendered":"\u3010UOS\u8fd0\u7ef4\u5b66\u4e60\u7b14\u8bb0\u3011- \u6570\u636e\u5e93\u7ba1\u7406"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u7b80\u4ecb<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/s1.ax1x.com\/2020\/08\/25\/dg0qgI.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/s1.ax1x.com\/2020\/08\/25\/dg0qgI.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\"\/><\/div><\/figure>\n\n\n\n<p><strong>1\u3001\u4ec0\u4e48\u662f\u6570\u636e\u5e93?<\/strong><br>\u6570\u636e\u5e93\u662f\u201c\u6309\u7167\u6570\u636e\u7ed3\u6784\u6765\u7ec4\u7ec7\u3001\u5b58\u50a8\u548c\u7ba1\u7406\u6570\u636e\u7684\u4ed3\u5e93\u201d\u3002\u662f\u4e00\u4e2a\u957f\u671f\u5b58\u50a8\u5728\u8ba1\u7b97\u673a\u5185\u7684\u3001\u6709\u7ec4\u7ec7\u7684\u3001\u53ef\u5171\u4eab\u7684\u3001\u7edf\u4e00\u7ba1\u7406\u7684\u5927\u91cf\u6570\u636e\u7684\u96c6\u5408\u3002<br>\u6570\u636e\u5e93\u662f\u4ee5\u4e00\u5b9a\u65b9\u5f0f\u50a8\u5b58\u5728\u4e00\u8d77\u3001\u80fd\u4e0e\u591a\u4e2a\u7528\u6237\u5171\u4eab\u3001\u5177\u6709\u5c3d\u53ef\u80fd\u5c0f\u7684\u5197\u4f59\u5ea6\u3001\u4e0e\u5e94\u7528\u7a0b\u5e8f\u5f7c\u6b64\u72ec\u7acb\u7684\u6570\u636e\u96c6\u5408\uff0c\u53ef\u89c6\u4e3a[\u7535\u5b50\u5316]\u7684\u6587\u4ef6\u67dc\u2014\u2014\u5b58\u50a8\u7535\u5b50\u6587\u4ef6\u7684\u5904\u6240\uff0c\u7528\u6237\u53ef\u4ee5\u5bf9\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u8fdb\u884c\u65b0\u589e\u3001\u67e5\u8be2\u3001\u66f4\u65b0\u3001\u5220\u9664\u7b49\u64cd\u4f5c<br><strong>2\u3001\u4e92\u8054\u7f51\u4e0a\u7684\u5e38\u7528\u6570\u636e\u5e93<\/strong><br>Oracle<br>SQL Server<br>mysql<br>DB2<br><strong>3\u3001mariadb \u6570\u636e\u5e93\u7b80\u4ecb<\/strong><br>\u81ea\u7532\u9aa8\u6587\u516c\u53f8\u6536\u8d2d MySQL \u540e\uff0c\u5176\u5728\u5546\u4e1a\u6570\u636e\u5e93\u4e0e\u5f00\u6e90\u6570\u636e\u5e93\u9886\u57df\u5e02\u573a\u7684\u5360\u6709\u4efd\u989d\u90fd\u8dc3\u5c45\u7b2c\u4e00\uff0c\u8fd9\u6837\u7684\u683c\u5c40\u5f15\u8d77\u4e86\u4e1a\u5185\u5f88\u591a\u7684\u4eba\u58eb\u7684\u62c5\u5fe7\uff0c\u56e0\u4e3a\u5546\u4e1a\u6570\u636e\u5e93\u7684\u8001\u5927\u6709\u53ef\u80fd\u5c06 MySQL \u95ed\u6e90\u3002\u4e3a\u4e86\u907f\u514d Oracle \u5c06 MySQL \u95ed\u6e90\uff0c\u800c\u65e0\u5f00\u6e90\u7684\u7c7b MySQL \u6570\u636e\u5e93\u53ef\u7528\uff0cMySQL \u793e\u533a\u91c7\u7528\u5206\u652f\u7684\u65b9\u5f0f\u6765\u907f\u5f00\u8fd9\u4e2a\u98ce\u9669\u3002MariaDB \u6570\u636e\u5e93\u5c31\u8fd9\u6837\u8bde\u751f\u4e86\uff0cMariaDB \u662f\u4e00\u4e2a\u5411\u540e\u517c\u5bb9\uff0c\u53ef\u80fd\u5728\u4ee5\u540e\u66ff\u4ee3 MySQL \u7684\u6570\u636e\u5e93\u4ea7\u54c1\uff0c\u5176\u5b98\u65b9\u5730\u5740\u4e3a\uff1ahttps:\/\/mariadb.org\/ \u3002mariadb \u548c mysql \u51e0\u4e4e\u662f\u4e00\u6837\u7684\u3002\u9996\u5148\uff0cmariadb \u5c31\u662f\u7531 mysql \u7684\u521b\u59cb\u4eba\u8d1f\u8d23\u7ef4\u62a4\u7684\u3002\u800c mariadb \u5c31\u662f mysql \u521b\u59cb\u4eba\u5973\u513f\u7684\u540d\u5b57\u3002\u4f7f\u7528\u65b9\u6cd5\u548c mysql \u76f8\u540c<br><strong>4\u3001mariadb \u4e0e mysql \u7684\u533a\u522b\uff1a<\/strong><br>MariaDB \u4e0d\u4ec5\u4ec5\u662f Mysql \u7684\u4e00\u4e2a\u66ff\u4ee3\u54c1\uff0cMariaDB \u5305\u62ec\u7684\u4e00\u4e9b\u65b0\u7279\u6027\u4f7f\u5b83\u4f18\u4e8e MySQL<br>MariaDB \u8ddf MySQL \u5728\u7edd\u5927\u591a\u6570\u65b9\u9762\u662f\u517c\u5bb9\u7684\uff0c\u5bf9\u4e8e\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u51e0\u4e4e\u611f\u89c9\u4e0d\u5230\u4efb\u4f55\u4e0d\u540c\u3002\u76ee\u524d MariaDB \u662f\u53d1\u5c55\u6700\u5feb\u7684 MySQL \u5206\u652f\u7248\u672c\uff0c\u65b0\u7248\u672c\u53d1\u5e03\u901f\u5ea6\u5df2\u7ecf\u8d85\u8fc7\u4e86 Oracle \u5b98\u65b9\u7684 MySQL \u7248\u672c\u3002MariaDB \u662f\u4e00\u4e2a\u91c7\u7528 Aria \u5b58\u50a8\u5f15\u64ce\u7684 MySQL \u5206\u652f\u7248\u672c\uff0c \u8fd9\u4e2a\u9879\u76ee\u7684\u66f4\u591a\u7684\u4ee3\u7801\u90fd\u6539\u7f16\u4e8e MySQL 6.0\u901a\u8fc7\u5168\u9762\u6d4b\u8bd5\u53d1\u73b0\uff0cMariaDB \u7684\u67e5\u8be2\u6548\u7387\u63d0\u5347\u4e86 3%-15%\uff0c\u5e73\u5747\u63d0\u5347\u4e86 8%\uff0c\u800c\u4e14\u6ca1\u6709\u4efb\u4f55\u5f02\u5e38\u53d1\u751f\uff1b\u4ee5 qp \u4e3a\u5355\u4f4d\uff0c\u541e\u5410\u91cf\u63d0\u5347\u4e86 2%-10%\u3002<br>MariaDB \u867d\u7136\u88ab\u89c6\u4e3a MySQL \u6570\u636e\u5e93\u7684\u66ff\u4ee3\u54c1\uff0c\u4f46\u5b83\u5728\u6269\u5c55\u529f\u80fd\u3001\u5b58\u50a8\u5f15\u64ce\u4ee5\u53ca\u4e00\u4e9b\u65b0\u7684\u529f\u80fd\u6539\u8fdb\u65b9\u9762\u90fd\u5f3a\u8fc7 MySQL\u3002\u800c\u4e14\u4ece MySQL \u8fc1\u79fb\u5230 MariaDB \u4e5f\u662f\u975e\u5e38\u7b80\u5355\u7684\uff1a<br>1\u3001\u6570\u636e\u548c\u8868\u5b9a\u4e49\u6587\u4ef6\uff08.frm\uff09\u662f\u4e8c\u8fdb\u5236\u517c\u5bb9\u7684<br>2\u3001\u6240\u6709\u5ba2\u6237\u7aef API\u3001\u534f\u8bae\u548c\u7ed3\u6784\u90fd\u662f\u5b8c\u5168\u4e00\u81f4\u7684<br>3\u3001\u6240\u6709\u6587\u4ef6\u540d\u3001\u4e8c\u8fdb\u5236\u3001\u8def\u5f84\u3001\u7aef\u53e3\u7b49\u90fd\u662f\u4e00\u81f4\u7684<br>4\u3001\u6240\u6709\u7684 MySQL \u8fde\u63a5\u5668\uff0c\u6bd4\u5982 PHP\u3001Perl\u3001Python\u3001Java\u3001.NET\u3001MyODBC\u3001Ruby \u4ee5\u53caMySQL C connector \u7b49\u5728 MariaDB \u4e2d\u90fd\u4fdd\u6301\u4e0d\u53d8<br>5\u3001mysql-client \u5305\u5728 MariaDB \u670d\u52a1\u5668\u4e2d\u4e5f\u80fd\u591f\u6b63\u5e38\u8fd0\u884c<br>6\u3001\u5171\u4eab\u7684\u5ba2\u6237\u7aef\u5e93\u4e0e MySQL \u4e5f\u662f\u4e8c\u8fdb\u5236\u517c\u5bb9\u7684<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001Mariadb<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/s1.ax1x.com\/2020\/08\/25\/dg0b8A.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/s1.ax1x.com\/2020\/08\/25\/dg0b8A.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\"\/><\/div><\/figure>\n\n\n\n<p>\uff081\uff09\u5b89\u88c5 mariadb \u6570\u636e\u5e93<br>apt install mariadb-server #\u5b89\u88c5 mariadb \u670d\u52a1\u7aef\u7a0b\u5e8f<br>systemctl restart mariadb.service #\u542f\u52a8\u7a0b\u5e8f<br>systemctl enable mariadb.service #\u8bbe\u4e3a\u5f00\u673a\u81ea\u542f\u52a8<br>\uff082\uff09\u6570\u636e\u5e93\u8fde\u63a5\u53ca\u5b89\u5168\u521d\u59cb\u5316<br>\u8fde\u63a5\u6570\u636e\u5e93<br>mysql \u5de5\u5177\u662f MySQL \u5b98\u65b9\u63d0\u4f9b\u7684\u8fde\u63a5\u5de5\u5177\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7 mysql \u8fde\u63a5\u5230 mysqld\u4e0a\u8fdb\u884c\u4e00\u7cfb\u5217\u7684 SQL \u64cd\u4f5c\u3002<br>mysql \u5de5\u5177\u6709\u4e24\u79cd\u6a21\u5f0f\uff1a\u4ea4\u4e92\u6a21\u5f0f\u548c\u547d\u4ee4\u884c\u6a21\u5f0f\u3002\u4ea4\u4e92\u6a21\u5f0f\u6307\u4ee4\u9700\u8981\u8fde\u63a5\u5230 mysql\u670d\u52a1\u5668\u4e0b\u8fbe\uff0c\u547d\u4ee4\u884c\u6a21\u5f0f\u901a\u8fc7\u7279\u5b9a\uff08-e\uff09\u53c2\u6570\u8bfb\u53d6 shell \u547d\u4ee4\u884c\u4f20\u9012\u7684\u6307\u4ee4\u5230\u670d\u52a1\u5668\u3002<br>\u547d\u4ee4\u683c\u5f0f\uff1a<br>mysql [OPTIONS] [database]<br>-h, &#8211;help \u663e\u793a\u5e2e\u52a9\u4fe1\u606f<br>-e, &#8211;execute=name \u6267\u884c\u6307\u5b9a\u547d\u4ee4\uff0c\u547d\u4ee4\u884c\u6a21\u5f0f<br>-u, &#8211;user=name \u6307\u5b9a\u8fde\u63a5\u7684\u7528\u6237<br>-h, &#8211;host=name \u6307\u5b9a\u4e3b\u673a\u540d<br>-p, &#8211;password \u6307\u5b9a\u5bc6\u7801<br>-P, &#8211;port \u6307\u5b9a\u7aef\u53e3<br>\u793a\u4f8b\uff1a<br>\uff081\uff09\u4f7f\u7528 root \u8d26\u53f7\u8fde\u63a5\u670d\u52a1\u5668\uff0c\u65e0\u5bc6\u7801\u767b\u5f55<br>mysql -u root<br>\uff082\uff09\u4f7f\u7528 root \u8d26\u53f7\u8fde\u63a5\u670d\u52a1\u5668\uff0c\u4f7f\u7528\u5bc6\u7801\u767b\u5f55<br>mysql -u root -p&#8217;passwd&#8217;<br>\uff083\uff09\u66f4\u6539\u5bc6\u7801<br>mysqladmin -u root password &#8216;123456&#8217; mysql -u root -p&#8217;123456&#8242; \u5728 linux \u4e2d\u4fee\u6539\u5bc6\u7801<br>mysqladmin -u root -p password &#8216;123456&#8217; #\u9700\u8f93\u5165 root \u539f\u59cb\u5bc6\u7801\u5728\u6570\u636e\u5e93\u4e2d\u4fee\u6539<br>set password=password(&#8216;uos&#8217;); #\u5bf9\u5f53\u524d\u7528\u6237\u8bbe\u7f6e\u5bc6\u7801\uff0c\u7acb\u523b\u751f\u6548<br>set password for uos@&#8217;localhost&#8217;=password(&#8216;123456&#8217;);#\u5bf9\u4efb\u610f\u7528\u6237\u8bbe\u7f6e\u5bc6\u7801<br>use mysql<br>update user set password=password(&#8216;uos&#8217;) where user=&#8217;root&#8217; and host=&#8217;localhost&#8217;;#\u4fee\u6539\u5bc6\u7801\u540e\u9700\u8981 flush privileges;\u5237\u65b0\u6743\u9650\u8868\uff0c\u6216\u91cd\u542f\u670d\u52a1<br>\uff084\uff09mariadb \u5fd8\u8bb0 root \u5bc6\u7801<br>vim \/etc\/mysql\/mariadb.conf.d\/50-server.cnf<br>[mysqld]<br>skip-grant-tables # \u5728 [mysqld] \u4e0b\u6dfb\u52a0\u6b64\u5b57\u6bb5\uff0c\u8fdb\u5165\u4f46\u7528\u6237\u6a21\u5f0f<br>systemctl restart mariadb.service<br>\u8f93 \u5165 mysql \u547d\u4ee4\u65e0\u9700\u5bc6\u7801\u76f4\u63a5\u8fdb\u5165\u6570\u636e\u5e93<br>use mysql<br>update user set password=password(\\&#8217;uos\\&#8217;) where user=\\&#8217;root\\&#8217;;<br>\u4ece 5.5.7 \u7248\u672c\u4e2d mysql \u6570\u636e\u5e93\u4e2d\u5c31\u5f00\u59cb\u5f15\u5165 plugin \u8fd9\u9879\u914d\u7f6e\uff0c\u7528\u6765\u8fdb\u884c\u7528\u6237\u5bc6\u7801\u9a8c\u8bc1<br>update user set plugin=\\&#8217;\\&#8217; where user=\\&#8217;root\\&#8217;;<br>\u505c\u6b62 mariadb \u670d\u52a1\uff0c\u5220\u9664\u914d\u7f6e\u6587\u4ef6\u7684 skip-grant-tables \u9009\u9879\uff0c\u91cd\u542f mariadb \u670d\u52a1\uff0c\u4f7f\u7528\u65b0\u5bc6\u7801\u8fdb\u5165<br>\uff085\uff09\u63d0\u9ad8 mariadb \u7684\u5b89\u5168\u6027<br>1\u3001\u6570\u636e\u5e93\u7684\u8d77\u59cb\u72b6\u6001\u8bbe\u5b9a\u4fe1\u606f\u662f\u4e0d\u5b89\u5168\u7684\uff0c\u9700\u8981\u505a\u4ee5\u4e0b\u8bbe\u5b9a\uff1a<br>mysql_secure_installation<br>Enter current password for root (enter for none): #\u8f93\u5165\u5f53\u524d root \u7684\u5bc6\u7801\uff0c\u5bc6\u7801\u4e3a\u7a7a\u76f4\u63a5\u56de\u8f66\u5373\u53ef<br>Change the root password? [Y\/n] #\u662f\u5426\u4fee\u6539 root \u7684\u5bc6\u7801<br>Remove anonymous users? [Y\/n] #\u662f\u5426\u5220\u9664\u533f\u540d\u7528\u6237<br>Disallow root login remotely? [Y\/n] #\u662f\u5426\u4e0d\u5141\u8bb8 root \u8fdc\u7a0b\u767b\u5f55<br>Remove test database and access to it? [Y\/n] #\u662f\u5426\u5220\u9664\u6d4b\u8bd5\u6570\u636e\u5e93 test<br>Reload privilege tables now? [Y\/n] #\u662f\u5426\u91cd\u65b0\u52a0\u8f7d\u6388\u6743\u4fe1\u606f<br>systemctl restart mariadb<br>2\u3001\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6570\u636e\u5e93\u7684\u7f51\u7edc\u63a5\u53e3\u65f6\u6253\u5f00\u7684\uff0c\u4e3a\u4e86\u5b89\u5168\u8d77\u89c1\uff0c\u9700\u8981\u5173\u95ed\u6b64\u63a5\u53e3\uff0c<br>\u6539\u914d\u7f6e\u6587\u4ef6<br>vim \/etc\/mysql\/mariadb.conf.d\/50-server.cnf<br>[mysqld] #\u5728 msqld \u6a21\u5757\u5199\u5165<br>skip-networking=1<br>systemctl restart mariadb #\u91cd\u542f\u7cfb\u7edf\u6570\u636e\u5e93<br>netstat -anplut | grep mysql #\u67e5\u8be2\u4e0d\u5230\u4efb\u4f55\u76d1\u542c\u7aef\u53e3<br>ls -l \/usr\/share\/mysql\/ #\u6709 4 \u4e2a\u89c4\u6a21\u7684\u914d\u7f6e\u6587\u4ef6\u6a21\u677f<br>vim \/etc\/mysql\/my.cnf #\u914d\u7f6e\u6587\u4ef6<br>ls -l \/var\/lib\/mysql #\u6bcf\u4e2a\u6570\u636e\u5e93\u4f1a\u5728\u6b64\u6587\u4ef6\u5939\u4e0b\u5efa\u7acb\u4e00\u4e2a\u5355\u72ec\u76ee\u5f55<br>\uff086\uff09\u6570\u636e\u5e93\u7684\u7ba1\u7406<br>SQL \u8bed\u8a00\u53ef\u4ee5\u7406\u89e3\u6210\u5411\u670d\u52a1\u7aef\u63d0\u95ee\u7684\u8bed\u8a00\uff0cSQL \u8bed\u8a00\u6309\u7167\u529f\u80fd\u53ef\u4ee5\u5206\u4e3a\u51e0\u79cd\u5b50\u8bed\u8a00\uff1a<br>\u6570\u636e\u5b9a\u4e49\u8bed\u8a00\uff08DDL\uff09\uff1a\u521b\u5efa\u548c\u7ba1\u7406\u6570\u636e\u5e93\uff0c\u5305\u62ec\u521b\u5efa\u4fee\u6539\u8868\uff0c\u5b9a\u4e49\u7d22\u5f15\uff0c\u7ba1\u7406\u7ea6\u675f\u6761\u4ef6\u3002DDL \u64cd\u4f5c\u5bf9\u8c61\u4e3a\u6570\u636e\u5e93\u5185\u90e8\u7684\u5bf9\u8c61\u3002<br>\u6570\u636e\u64cd\u7eb5\u8bed\u8a00\uff08DML\uff09\uff1a\u67e5\u8be2\u548c\u66f4\u65b0\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e,\u7528\u4e8e\u6dfb\u52a0\uff0c\u5220\u9664\uff0c\u66f4\u65b0\uff0c\u67e5\u8be2\u3002DML \u7684\u64cd\u4f5c\u5bf9\u8c61\u662f\u8868\u7684\u5185\u90e8\u6570\u636e\u3002\u800c\u4e0d\u4f1a\u6d89\u53ca\u5230\u8868\u7684\u5b9a\u4e49\uff0c\u7ed3\u6784\u7684\u4fee\u6539\u3002<br>\u6570\u636e\u63a7\u5236\u8bed\u8a00\uff08DCL\uff09 \uff1a\u5bf9\u7528\u6237\u7684\u6743\u9650\u63a7\u5236<br>\u6570\u636e\u67e5\u8be2\u8bed\u8a00\uff08dql\uff09\uff1a\u5bf9\u6570\u636e\u5e93\u67e5\u8be2<\/p>\n\n\n\n<p><br><strong>\u300c1\u300d\u5efa\u7acb scott \u6570\u636e\u5e93\u5feb\u901f\u5efa\u7acb\u811a\u672c<\/strong><br>SCOTT \u662f\u6570\u636e\u5e93\u5185\u90e8\u7684\u4e00\u4e2a\u793a\u4f8b\u7528\u6237\uff0c\u7f3a\u7701\u53e3\u4ee4\u4e3a tiger\uff0c\u4e0b\u9762\u6709\u8868 emp, dept\u7b49\uff0c\u8fd9\u4e9b\u8868\u548c\u8868\u95f4\u7684\u5173\u7cfb\u6f14\u793a\u4e86\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7684\u4e00\u4e9b\u57fa\u672c\u539f\u7406<br>vim \/scott.sql<br>create database scott;<br>use scott<br>create table dept(&#8211; \u90e8\u95e8\u7f16\u53f7<br>deptno int unsigned auto_increment primary key, &#8212; \u90e8\u95e8\u540d\u79f0<br>dname varchar(15) , &#8212; \u90e8\u95e8\u6240\u5728\u4f4d\u7f6e<br>loc varchar(50)<br>)engine = InnoDB;<br>create table emp(&#8211; \u96c7\u5458\u7f16\u53f7<br>empno int unsigned auto_increment primary key, &#8212; \u96c7\u5458\u59d3\u540d<br>ename varchar(15) , &#8212; \u96c7\u5458\u804c\u4f4d<br>job varchar(10) , &#8212; \u96c7\u5458\u5bf9\u5e94\u7684\u9886\u5bfc\u7684\u7f16\u53f7<br>mgr int unsigned , &#8212; \u96c7\u5458\u7684\u96c7\u4f63\u65e5\u671f<br>hiredate date , &#8212; \u96c7\u5458\u7684\u57fa\u672c\u5de5\u8d44<br>sal decimal(7,2) , &#8212; \u5956\u91d1<br>comm decimal(7,2) , &#8212; \u6240\u5728\u90e8\u95e8<br>deptno int unsigned , foreign key(deptno) references dept(deptno)<br>)engine = innodb;<br>create table salgrade(&#8211; \u5de5\u8d44\u7b49\u7ea7<br>grade int unsigned , &#8212; \u6b64\u7b49\u7ea7\u7684\u6700\u4f4e\u5de5\u8d44<br>losal int unsigned , &#8212; \u6b64\u7b49\u7ea7\u7684\u6700\u9ad8\u5de5\u8d44<br>hisal int unsigned<br>)engine=innodb;<br>create table bonus(&#8211; \u96c7\u5458\u59d3\u540d<br>ename varchar(10), &#8212; \u96c7\u5458\u804c\u4f4d<br>job varchar(9), &#8212; \u96c7\u5458\u5de5\u8d44<br>sal decimal(7,2), &#8212; \u96c7\u5458\u8d44\u91d1<br>comm decimal(7,2)<br>)engine=innodb;<br>INSERT INTO dept VALUES (10,&#8217;ACCOUNTING&#8217;,&#8217;NEW YORK&#8217;);<br>INSERT INTO dept VALUES (20,&#8217;RESEARCH&#8217;,&#8217;DALLAS&#8217;);<br>INSERT INTO dept VALUES (30,&#8217;SALES&#8217;,&#8217;CHICAGO&#8217;);<br>INSERT INTO dept VALUES (40,&#8217;OPERATIONS&#8217;,&#8217;BOSTON&#8217;);<br>INSERT INTO emp VALUES (7369,&#8217;SMITH&#8217;,&#8217;CLERK&#8217;,7902,&#8217;1980-12- 17&#8242;,800,NULL,20);<br>INSERT INTO emp VALUES (7499,&#8217;ALLEN&#8217;,&#8217;SALESMAN&#8217;,7698,&#8217;1981-2- 20&#8242;,1600,300,30);<br>INSERT INTO emp VALUES (7521,&#8217;WARD&#8217;,&#8217;SALESMAN&#8217;,7698,&#8217;1981-2- 22&#8242;,1250,500,30);<br>INSERT INTO emp VALUES (7566,&#8217;JONES&#8217;,&#8217;MANAGER&#8217;,7839,&#8217;1981-4- 2&#8242;,2975,NULL,20);<br>INSERT INTO emp VALUES (7654,&#8217;MARTIN&#8217;,&#8217;SALESMAN&#8217;,7698,&#8217;1981-9- 28&#8242;,1250,1400,30);<br>INSERT INTO emp VALUES (7698,&#8217;BLAKE&#8217;,&#8217;MANAGER&#8217;,7839,&#8217;1981-5- 1&#8242;,2850,NULL,30);<br>INSERT INTO emp VALUES (7782,&#8217;CLARK&#8217;,&#8217;MANAGER&#8217;,7839,&#8217;1981-6- 9&#8242;,2450,NULL,10);<br>INSERT INTO emp VALUES (7788,&#8217;SCOTT&#8217;,&#8217;ANALYST&#8217;,7566,&#8217;87-7- 13&#8242;,3000,NULL,20);<br>INSERT INTO emp VALUES (7839,&#8217;KING&#8217;,&#8217;PRESIDENT&#8217;,NULL,&#8217;1981-11- 17&#8242;,5000,NULL,10);<br>INSERT INTO emp VALUES (7844,&#8217;TURNER&#8217;,&#8217;SALESMAN&#8217;,7698,&#8217;1981-9- 8&#8242;,1500,0,30);<br>INSERT INTO emp VALUES (7876,&#8217;ADAMS&#8217;,&#8217;CLERK&#8217;,7788,&#8217;87-7-13&#8242;,1100,NULL,20);<br>INSERT INTO emp VALUES (7900,&#8217;JAMES&#8217;,&#8217;CLERK&#8217;,7698,&#8217;1981-12-3&#8242;,950,NULL,30);<br>INSERT INTO emp VALUES (7902,&#8217;FORD&#8217;,&#8217;ANALYST&#8217;,7566,&#8217;1981-12- 3&#8242;,3000,NULL,20);<br>INSERT INTO emp VALUES (7934,&#8217;MILLER&#8217;,&#8217;CLERK&#8217;,7782,&#8217;1982-1- 23&#8242;,1300,NULL,10);<br>INSERT INTO salgrade VALUES (1,700,1200);<br>INSERT INTO salgrade VALUES (2,1201,1400);<br>INSERT INTO salgrade VALUES (3,1401,2000);<br>INSERT INTO salgrade VALUES (4,2001,3000);<br>INSERT INTO salgrade VALUES (5,3001,9999);<br>\u8c03\u7528\u7cfb\u7edf\u8d44\u6e90<br>mysql -uroot -p<br>system ls -l \/root<br>source \/scott.sql<br><strong>\u300c2\u300d\u66f4\u6539\u5b57\u7b26\u96c6<\/strong><br>\u66f4\u6539\u5b57\u7b26\u96c6<br>\u67e5\u770b Linux \u7684\u5b57\u7b26\u96c6\u7528 locale \u547d\u4ee4<br>status #\u67e5\u770b mariadb \u5c5e\u6027<br>Server characterset: utf8mb4<br>Db characterset: utf8mb4<br>Client characterset: utf8mb4<br>Conn. characterset: utf8mb4<br>\u5ba2\u6237\u7aef\u7684\u5b57\u7b26\u96c6\u8981\u548c\u6570\u636e\u5e93\u7684\u5b57\u7b26\u96c6\u4e00\u81f4\uff0c\u4e0d\u4e00\u81f4\u6709\u53ef\u80fd\u4e71\u7801<br>vim \/etc\/mysql\/mariadb.conf.d\/50-server.cnf<br>character-set-server = utf8<br>collation-server = utf8<br>systemctl restart mariadb.service<br>MariaDB [(none)]> status #\u91cd\u542f\u540e\u53d8\u66f4\u4e3a\u65b0\u5b57\u7b26\u96c6<br>Server characterset: utf8<br>\u67e5\u770b\u6570\u636e\u5e93\u7684\u5b57\u7b26\u96c6<br>create database scott;<br>drop database scott; #\u5220\u9664\u6570\u636e\u5e93<br>source \/scott.sql #\u4f7f\u7528\u811a\u672c\u91cd\u5efa\u6570\u636e\u5e93<br>show create database scott; #\u5728\u66f4\u6539\u5b57\u7b26\u96c6\u4e4b\u540e\u5efa\u7acb\uff0c\u6240\u4ee5\u662f\u5b57\u7b26\u96c6\u662f utf8<br>show create table emp;<br>\u66f4\u6539\u5b57\u7b26\u96c6<br>alter database scott charset utf8;<br>alter table emp charset utf8;<br>select database(); #\u67e5\u770b\u5f53\u524d\u8fdb\u5165\u7684\u6570\u636e\u5e93<br>select user(); #\u67e5\u770b\u5f53\u524d\u767b\u5f55\u7528\u6237<br>show databases; #\u67e5\u770b\u6570\u636e\u5e93<br>use mysql #\u8fdb\u5165 mysql \u6570\u636e\u5e93<br>show tables; #\u67e5\u770b\u6b64\u6570\u636e\u5e93\u7684\u8868\uff0ctest \u6ca1\u8868\uff0c\u53ef\u4ee5\u770b\u5176\u4ed6\u6570\u636e\u5e93\u7684<br>desc user; #\u67e5\u770b\u8868\u7ed3\u679c<br>show variables like &#8216;innodb%&#8217;; #\u67e5\u770b\u73af\u5883\u53d8\u91cf<br>\u6709\u65f6\u547d\u4ee4\u8f93\u9519\u505c\u5728>\u754c\u9762\u51fa\u4e0d\u6765\uff0c\u4e00\u822c\u662f\u5c11\u4e9b\u4e86&#8217;\u6216\u8005\uff1b\u8865\u5168\u5373\u53ef\u9000\u51fa\uff0c\u5b9e\u5728\u4e0d\u884c\u53ef\u4ee5 CTRL+D \u5728\u91cd\u65b0\u767b\u5f55<br><strong>\u300c3\u300d\u67e5\u6570\u636e<\/strong><br>select * from emp;<br>select ename,sal from emp;<br>select ename,(sal+200)*3 as bonus from emp; #\u652f\u6301\u7b97\u6570\u8868<br>\u8fbe\u5f0f\u52a0\u51cf\u4e58\u6570\u548c\u62ec\u53f7\u7b49<br>select ename,sal,comm,sal+ifnull(comm,0) as income from emp; #\u7a7a\u503c<br>\u53c2\u4e0e\u7b97\u672f\u8fd0\u7b97\u4e3a\u7a7a\u503c\uff0c\u5efa\u8bae\u7528 ifnull \u51fd\u6570\u8f6c\u6362<br>select distinct deptno from emp; #\u7528 distinct \u53bb\u9664\u91cd\u590d\u7ed3\u679c<br>select ename,sal,deptno from emp where deptno=30;<br>select * from emp where ename like &#8216;<em>__TT&#8217;; #<\/em>\u4ee3\u8868\u4efb\u610f\u5355\u4e2a\u5b57\u7b26<br>select * from emp where ename like &#8216;%LL%&#8217;; #%\u4ee3\u8868\u4efb\u610f\u5b57\u7b26<br>select ename,sal,deptno from emp where deptno=30 and sal>2000; #\u4e0e<br>select ename,sal,deptno from emp where deptno=30 or sal>2000; #\u6216<br>select ename,sal,deptno from emp where not sal>2000; #\u975e<br>select * from emp order by sal; #\u9ed8\u8ba4\u5347\u5e8f\uff0c\u964d\u5e8f\u52a0 desc<br>select empno,ename,sal,deptno from emp order by deptno,sal desc; #\u591a\u5217\u6392\u5e8f<br>select concat(ename,&#8217;\\&#8217;s sal is &#8216;,sal) from emp; #\u652f\u6301\u591a\u79cd\u51fd\u6570\uff0c\u4e0d\u4e00\u4e00\u4e3e\u4e86<br>select count(*) from emp;<br>select deptno,sum(sal),min(sal),max(sal),avg(sal) from emp group by deptno;<br>select deptno,avg(sal) from emp group by deptno having avg(sal)&lt;2000; select ename,dname from emp,dept; #\u7b1b\u5361\u5c14\u4e58\u79ef select ename,dname from emp,dept where emp.deptno=dept.deptno; select ename,sal,grade from emp join salgrade on sal between losal and hisal; select y.ename yuangong,j.ename jingli from emp y,emp j where y.mgr=j.empno; select ename,dname,sal,grade from emp,dept,salgrade where emp.deptno=dept.deptno and emp.sal between salgrade.losal and salgrade.hisal; select ename,sal from emp where sal=(select max(sal) from emp);#\u5b50\u67e5\u8be2\u627e\u5230\u5de5\u8d44\u6700\u9ad8\u85aa select ename from emp where empno not in (select mgr from emp where mgr is not null); #in \u7ed3\u679c\u96c6\u4e0d\u80fd\u6709\u7a7a\u503c\uff0c\u5426\u5219\u7ed3\u679c\u4e3a\u7a7a \u521b\u5efa\u6570\u636e\u5e93 MariaDB [(none)]> create database uosdata;<br><strong>\u300c4\u300d\u521b\u5efa\u8868<\/strong><br>\u521b\u5efa\u8868\u5e76\u5efa\u7acb\u5b57\u6bb5<br>\u683c \u5f0f \uff1a create table \u6570\u636e\u8868\u540d(\u5b57\u6bb5\u540d\u5b57\u6bb5\u7c7b\u578b);<br>MariaDB [uos]> create table uostable(id int,name varchar(10),mail varchar(30));<br>int\u7c7b\u578b\u8868\u793a\u6b63\u5e38\u5927\u5c0f\u7684\u6574\u6570\uff08\u6570\u5b57\u6570\u636e\u7c7b\u578b\uff09\u3002<br>char \u7c7b\u578b\uff08\u5b57\u7b26\u4e32\u6570\u636e\u7c7b\u578b\uff09\u8868\u793a\u5305\u542b\u6307\u5b9a\u957f\u5ea6\u7684\u7a7a\u683c\u7684\u53f3\u4fa7\u5e26\u6709\u56fa\u5b9a\u957f\u5ea6\u7684\u5b57\u7b26\u4e32\u3002 M \u8868\u793a\u5b57\u7b26\u7684\u5217\u957f\u5ea6\uff0c\u53d6\u503c\u8303\u56f4\u4e3a0 \u301c 255 \uff0c\u7f3a\u7701\u503c\u4e3a1\u3002<br>varchar \u7c7b\u578b\uff08\u5b57\u7b26\u4e32\u6570\u636e\u7c7b\u578b\uff09\u8868\u793a\u4e00\u4e2a\u53ef\u53d8\u957f\u5ea6\u5b57\u7b26\u4e32\uff0cM\u8303\u56f4\uff08\u6700\u5927\u5217\u957f\u5ea6\uff09\u4e3a0\u523065535\u3002<br><strong>\u300c5\u300d\u4fee\u6539\u8868<\/strong><br>create table uos1 like uostable; #\u6ca1\u6709\u6570\u636e\uff0c\u53ea\u662f\u590d\u5236\u4e86\u8868\u7684\u7ed3\u6784<br>insert into uos1 select * from uostable; # \u590d\u5236\u6570\u636e\uff0c\u8868\u4e0d\u5b58\u5728\u65e0\u6cd5\u590d\u5236<br>create table uos2 as select * from uostable; #\u65b0\u5efa\u8868\uff0c\u5e76\u590d\u5236\u6574\u4e2a\u8868\u7ed3\u6784+\u6570\u636e\u67e5\u770b\u8868\u7ed3\u6784<br>\u683c \u5f0f \uff1a desc \u6570 \u636e \u8868 \u540d ;<br>MariaDB [uos]> desc uos;<br>\u5411\u6570\u636e\u8868\u63d2\u5165\u6570\u636e<br>\u683c \u5f0f \uff1a insert into \u6570 \u636e \u8868 \u540d (id,name,mail) values(1,&#8217;uos1&#8242;,&#8217;uos1\\@uos.com&#8217;);<br>insert into uostable(id,name,mail) values(1,&#8217;uos1&#8242;,&#8217;uos1@uos.com&#8217;);<br>insert into uostable values(2,&#8217;uos2&#8242;,&#8217;uos2@uos.com&#8217;); #\u52a0\u5165\u5168\u5217\u6570\u636e\u53ef\u4ee5\u4e0d\u5199\u5217\u540d<br>insert into uostable(id,name) values(3,&#8217;uos3&#8242;); #\u4e0d\u662f\u5168\u5217\u5fc5\u987b\u5199\u5217\u540d<br>insert into uostable<br>values(4,&#8217;uos4&#8242;,&#8217;uos4@uos.com&#8217;),(5,&#8217;uos5&#8242;,&#8217;uos5@uos.com&#8217;),(6,&#8217;uos6&#8242;,&#8217;uos6@uos.com&#8217;);<br>\u66f4\u65b0\u8868<br>update uostable set name=\\&#8217;test\\&#8217; where id=2;<br>\u4fee\u6539\u8868\u7ed3\u6784<br>alter table uostable add newlist varchar(20); # \u589e \u52a0 newlist \u5217<br>alter table uostable drop newlist; # \u5220 \u9664 newlist \u5217<br>alter table uostable add firstlist varchar(20) first; # \u589e\u52a0 firstlist \u5217\u5230\u7b2c\u4e00\u5217<br>alter table uostable add afterid varchar(30) after id; #\u589e\u52a0 afterid \u5217\u5230 id \u5217\u540e\u9762<br><strong>\u300c6\u300d\u5220\u9664\u8868<\/strong><br>delete from uostable where id=4; # \u8981\u52a0\u4e0awhere\u7ea6\u675f\uff0c\u6ca1\u6709where\u5220\u9664\u6574\u4e2a\u8868<br>delete from uos1; #DML\u64cd\u4f5c\uff0c\u6e05\u9664\u8868\u6570\u636e\uff0c\u4fdd\u7559\u8868\u7ed3\u679c<br>truncate uos2; #DDL\u64cd\u4f5c\uff0c\u6e05\u9664\u8868\u6570\u636e\uff0c\u4fdd\u7559\u8868\u7ed3\u679c\uff0c\u66f4\u5f7b\u5e95\uff0c\u964d\u4f4e\u9ad8\u6c34\u4f4d\u7ebf<br>drop table uos1; #\u6e05\u9664\u8868\u7ed3\u6784\u548c\u6570\u636e<br><strong>\u300c7\u300d\u5916\u90e8\u8868<\/strong><br>\u5efa\u7acb\u6d4b\u8bd5\u7528\u5916\u90e8\u8868<br>vim \/uos.txt<br>1,uos1,uos1@uos.com<br>2,uos2,uos2@uos.com<br>3,uos3,uos3@uos.com<br>4,uos4,uos4@uos.com<br>\u5c06\u5916\u90e8\u8868\u5bfc\u5165\u6570\u636e\u5e93<br>create database uosdatabase;<br>create table uostable(id int(4),name varchar(10),email varchar(20));<br>load data infile &#8216;\/uos.txt&#8217; into table uostable fields terminated by &#8216;,&#8217; lines terminated by &#8216;\\n&#8217;;<br>\u5c06\u6570\u636e\u5e93\u5bfc\u51fa\u4e3a\u5916\u90e8\u8868<br>select * from uostable into outfile &#8216;\/var\/lib\/mysql\/uosdatabase\/uostable.txt&#8217; fields terminated<br>by &#8216;,&#8217; lines terminated by &#8216;\\n&#8217;;<br>\u901a\u8fc7\u5916\u90e8\u8868\u5bfc\u5165 scott \u6570\u636e\u5e93<br>\u5c06 scott \u6570\u636e\u5e93\u7684 3 \u4e2a\u6587\u672c\u6587\u4ef6\u62f7\u8d1d\u5230\u6839\u76ee\u5f55<br>vim \/scott.emp.txt<br>7369,&#8217;SMITH&#8217;,&#8217;CLERK&#8217;,7902,800,200,20<br>7499,&#8217;ALLEN&#8217;,&#8217;SALES&#8217;,7698,1600,300,30<br>7521,&#8217;WARD&#8217;,&#8217;SALES&#8217;,7698,1250,500,30<br>7566,&#8217;JONES&#8217;,&#8217;MANAG&#8217;,7839,2975,100,20<br>vim \/scott.dept.txt<br>10,&#8217;ACCOUNTING&#8217;,&#8217;NEW YORK&#8217; 20,&#8217;RESEARCH&#8217;,&#8217;DALLAS&#8217; 30,&#8217;SALES&#8217;,&#8217;CHICAGO&#8217; 40,&#8217;OPERATIONS&#8217;,&#8217;BOSTON&#8217; vim \/scott.salgrade.txt<br>1,700,1200<br>2,1201,1400<br>3,1401,2000<br>create database scott;<br>use scott<br>create table emp(empno int(4),ename varchar(10),job varchar(9),mgr int(4) default null,sal<br>int(7),comm int(7) default null,deptno int(2));<br>load data infile &#8216;\/scott.emp.txt&#8217; into table emp fields terminated by &#8216;,&#8217; lines terminated by &#8216;\\n&#8217;;<br>create table dept(deptno int(2),dname varchar(14),loc varchar(13));<br>load data infile &#8216;\/scott.dept.txt&#8217; into table dept fields terminated by &#8216;,&#8217; lines terminated by &#8216;\\n&#8217;;<br>create table salgrade(grade int,losal int,hisal int);<br>load data infile &#8216;\/scott.salgrade.txt&#8217; into table salgrade fields terminated by &#8216;,&#8217; lines terminated by<br>&#8216;\\n&#8217;;<br>\u5c06 scott \u6570\u636e\u5e93\u5bfc\u51fa\u4e3a\u5916\u90e8\u8868<br>use scott<br>select * from emp into outfile &#8216;\/var\/lib\/mysql\/scott\/scott.emp.txt&#8217; fields terminated by &#8216;,&#8217; lines<br>terminated by &#8216;\\n&#8217;;<br><strong>\u300c8\u300d\u5728 linux \u73af\u5883\u5907\u4efd\u6570\u636e\u5e93<\/strong><br>mysqldump -u root -p scott > \/scott.dump #\u5907\u4efd\u6570\u636e\u5e93<br>mysqldump -u root -p scott emp > \/scott.emp.dump #\u5907\u4efd\u6570\u636e\u5e93\u4e2d\u7684\u8868<br>mysqldump -u root -p scott dept salgrade > \/scott.dept+salgrade.dump #\u5907\u4efd\u6570\u636e\u5e93\u4e2d\u7684\u591a\u4e2a\u8868<br>\u5728 linux \u73af\u5883\u8fd8\u539f\u6570\u636e\u5e93<br>drop database scott;#\u5982\u679c\u62a5\u9519\uff0c\u5220\u9664\/var\/lib\/mysql\/scott\/scott.emp.txt\u6587\u4ef6<br>create database uos; #\u4e0d\u5efa\u7acb\u6570\u636e\u5e93\uff0c\u65e0\u6cd5\u5bfc\u5165\u6574\u5e93,\u968f\u610f\u547d\u540d<br>mysql -u root -p uos &lt; \/scott.dump # \u8fd8\u539f\u6570\u636e\u5e93<br>drop database uos;<br>create database uos; #\u91cd\u5efa\u6570\u636e\u5e93\u7528\u4e8e\u6d4b\u8bd5\u8fd8\u539f\u8868<br>mysql -u root -p uos &lt; \/scott.emp.dump #\u8fd8\u539f\u6570\u636e\u5e93\u4e2d\u7684\u8868<br>mysql -u root -p uos &lt; \/scott.dept+salgrade.dump #\u8fd8\u539f\u6570\u636e\u5e93\u4e2d\u7684\u591a\u4e2a\u8868<br><strong>\u300c9\u300d\u7528\u6237\u548c\u6743\u9650<\/strong><br>mariadb \u7684\u7528\u6237\u767b\u5f55\u5305\u62ec\u7528\u6237\u540d\u548c\u767b\u5f55\u4f4d\u7f6e\u4e24\u90e8\u5206\u3002\u65e9\u671f\u7248\u672c%\u5c31\u53ef\u4ee5\u4ee3\u8868\u6240\u6709\u7684\u8fde\u63a5\uff0c\u540e\u671f\u7248\u672c localhost \u8868\u793a\u672c\u5730\u767b\u5f55\uff0c%\u8868\u793a tcp\/ip \u7684\u8fdc\u7a0b\u767b\u5f55\u7684\u6240\u6709 ip\u3002%\u4e5f\u53ef\u4ee5\u5199\u5177\u4f53\u4e3b\u673a\u6216\u7f51\u6bb5\uff0c\u6bd4\u5982 192.168.200.10\u3001192.168.100.%\u6216\u8005 192.168.200.0\/255.255.255.0\uff0c\u5176\u4ed6\u683c\u5f0f\u4e0d\u8bc6\u522b\u3002\u5982\u679c\u767b\u5f55\u4e3b\u673a\u7b26\u5408\u591a\u4e2a\u8fde\u63a5\u6761\u4ef6\uff0c\u9ed8\u8ba4\u8fde\u63a5\u7b2c\u4e00\u4e2a\u8eab\u4efd\uff0c\u8bbe\u7f6e\u6743\u9650\u7684\u65f6\u5019\u9700\u8981\u6ce8\u610f<br>select user(); # \u67e5\u770b\u5f53\u524d\u767b\u5f55\u7528\u6237<br>use mysql<br>select host,user,password from user; #\u67e5\u770b\u6570\u636e\u5e93\u6240\u6709\u767b\u5f55\u8303\u56f4\u3001\u7528\u6237\u548c\u5bc6\u7801\uff0c4\u4e2aroot\u4e0d\u662f\u540c\u4e00\u4e2a\u7528\u6237\uff0c\u53ef\u4ee5\u5355\u72ec\u8bbe\u7f6e\u5bc6\u7801<br>create user uos@&#8217;localhost&#8217; identified by &#8216;123456&#8217;; #\u5efa\u7acb\u53ef\u4ee5\u672c\u5730\u767b\u5f55\u7684\u7528\u6237 uos\u5e76\u8bbe\u7f6e\u5bc6\u7801123456<br>create user uos@&#8217;%&#8217; identified by &#8216;123456&#8217;; #\u5efa\u7acb\u53ef\u4ee5\u8fdc\u7a0b\u767b\u5f55\u7684\u7528\u6237 uos\u5e76\u8bbe\u7f6e\u5bc6\u7801123456<br>create user test@&#8217;localhost&#8217; identified by &#8216;123456&#8217;; #\u5efa\u7acb\u53ef\u4ee5\u672c\u5730\u767b\u5f55\u7684\u7528\u6237 test\u5e76\u8bbe\u7f6e\u5bc6\u7801123456<br>create user test@&#8217;192.168.200.10&#8242; identified by &#8216;123456&#8217;; # \u5efa\u7acb\u53ef\u4ee5\u4ece 192.168.200.10\u4e3b\u673a\u767b\u5f55\u7684\u7528\u6237 test \u5e76\u8bbe\u7f6e\u5bc6\u7801 123456<br>grant all on <em>.<\/em> to uos@&#8217;localhost&#8217;; #\u6388\u6743\u672c\u5730\u767b\u5f55\u7684\u7528\u6237 uos \u5bf9\u6240\u6709\u6570\u636e\u5e93\u7684\u6240\u6709\u8868\u6709\u6240\u6709\u6743\u9650<br>grant select on scott.* to test@&#8217;localhost&#8217;; #\u6388\u6743\u672c\u5730\u767b\u5f55\u7684\u7528\u6237 test \u53ef\u4ee5\u8bfb\u53d6 scott \u6570\u636e\u5e93\u7684\u6240\u6709\u8868<br>grant all on <em>.<\/em> to uostest@&#8217;%&#8217; identified by &#8216;123456&#8217;; #\u53ef\u4ee5\u5efa\u7acb\u7528\u6237\u3001\u6388\u6743\u3001\u8bbe\u7f6e\u5bc6\u7801\u4e00\u8d77\u505a<br>flush privileges; # \u5237\u65b0\u6388\u6743\u8868<br>show privileges; # \u67e5\u770b\u6240\u6709\u6743\u9650<br>show grants for uos@&#8217;localhost&#8217;; # \u67e5\u770b\u7528\u6237\u6743\u9650<br>show grants for test@&#8217;localhost&#8217;;<br>revoke select on scott.* from test@&#8217;192.168.200.10&#8242;; #\u6536\u56de\u6743\u9650<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001mariadb \u4e3b\u4ece\u590d\u5236<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/s1.ax1x.com\/2020\/08\/25\/dg0Lvt.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/s1.ax1x.com\/2020\/08\/25\/dg0Lvt.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\"\/><\/div><\/figure>\n\n\n\n<p>\u5728 uos1 \u4e0a\uff1a<br>apt install mariadb-server<br>systemctl enable mariadb.service<br>\u914d \u7f6e \u4e3b \u670d \u52a1 \u5668 vim \/etc\/mysql\/mariadb.conf.d\/50-server.cnf<br>[mysqld]<br>server_id = 1<br>log-bin = \/var\/lib\/mysql\/mysql-bin<br>replicate-do-db = uos # \u540c\u6b65\u7684\u6570\u636e\u5e93 uos<br>\u91cd\u542f mariadb \u6570\u636e\u5e93<br>systemctl restart mariadb<br>\u767b\u5f55 mysql \u4e3b\u670d\u52a1\u5668<br>grant replication slave on <em>.<\/em> to &#8216;uos&#8217;@&#8217;192.168.200.11&#8217; identified by &#8216;123&#8217;; #\u5141\u8bb8\u4ece\u670d\u52a1\u5668 slave\u8bbf\u95ee<br>flush privileges; # \u5237\u65b0\u6743\u9650<br>show master status \\G #\u67e5\u770b\u4e3b master \u670d\u52a1\u5668\u72b6\u6001<\/p>\n\n\n\n<p>\u5728 uos2 \u4e0a\uff1a<br>apt install mariadb-server<br>systemctl enable mariadb.service<br>\u914d \u7f6e \u4ece \u670d \u52a1 \u5668 vim \/etc\/mysql\/mariadb.conf.d\/50-server.cnf<br>[mysqld]<br>server_id = 2<br>relay-log = \/var\/lib\/mysql\/relay-bin<br>replicate-do-db = uos<br>\u91cd\u542f mariadb \u6570\u636e\u5e93<br>systemctl restart mariadb<br>\u767b\u5f55 mysql \u4ece\u670d\u52a1\u5668<br>change master to<br>master_host=&#8217;192.168.200.10&#8242;,master_user=&#8217;root&#8217;,master_password=&#8217;123&#8242;,master_log_file=&#8217;mys<br>ql-bin.000001&#8242;,master_log_pos=524; #\u6307\u5b9a master \u4e3b\u670d\u52a1\u5668\u7684 ip\u3001\u7528\u6237\u540d\u5bc6\u7801\u3001\u8d77\u59cb log \u6587\u4ef6\u548c\u504f\u79fb\u4f4d\u7f6e<br>start slave; # \u542f \u52a8 slave \u4ece\u670d\u52a1\u5668<br>show slave status \\G # \u67e5\u770b\u4ece slave \u670d\u52a1\u5668\u72b6\u6001<br>Slave_IO_Running: Yes<br>Slave_SQL_Running: Yes # \u4e3b\u4ece\u590d\u5236\u642d\u5efa\u6210\u529f<\/p>\n\n\n\n<p>\u6d4b\u8bd5 \uff1a<br>\u5728 uos1 \u4e3b\u5e93\u4e2d\u63d2\u5165\u6570\u636e<br>use uos<br>insert into dept values (50,&#8217;SALES&#8217;,&#8217;TOM&#8217;);<br>\u5728 uos2 \u4ece\u5e93\u4e2d\u67e5\u770b<br>select * from uos.dept;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001mycat \u8bfb\u5199\u5206\u79bb<\/h2>\n\n\n\n<p>\u5728\u4e3b\u4ece\u540c\u6b65\u5b9e\u9a8c\u7684\u57fa\u7840\u4e0a<br>\u5728 uos1 \u4e0a\u5b89\u88c5 jre \u8f6f\u4ef6<br>www.oracle.com \u7f51\u7ad9\u4e0b\u8f7d jre-8u251-linux-x64.tar.gz \u538b\u7f29\u5305<br>cd \/root<br>tar -xvzf jre-8u251-linux-x64.tar.gz<br>export JAVA_HOME=\/root\/jre1.8.0_251 # \u52a0\u5165\u73af\u5883\u53d8\u91cf\u4e2d<br>export PATH=$JAVA_HOME\/bin:$PATH<br>export CLASSPATH=.$JAVA_HOME\/lib\/dt.jar:$JAVA_HOME\/lib\/tools.jar<br>\u4e0b\u8f7d mycat \u8f6f\u4ef6<br>wget https:\/\/github.com\/MyCATApache\/Mycat-download\/raw\/master\/1.5-RELEASE\/Mycat- server-1.5.1-RELEASE-20161130213509-linux.tar.gz<br>tar -xvzf Mycat-server-1.5.1-RELEASE-20161130213509-linux.tar.gz<\/p>\n\n\n\n<p>\u914d\u7f6e server.xml \u6587\u4ef6<br>vim \/root\/mycat\/conf\/server.xml<br>druidparser 123 uos<\/p>\n\n\n\n<p>\u914d \u7f6e schema.xml \u6587\u4ef6<br>vim \/root\/mycat\/conf\/schema.xml<br>select user()<br>\u5bf9\u5e94\u6211\u4eec\u7684\u5728 mysql \u4e2d\u9700\u8981\u914d\u7f6e\u8bfb\u5199\u5206\u79bb\u7684\u6570\u636e\u5e93<br>\u548c \u914d\u7f6e\u5199\u670d\u52a1\u5668\u548c\u8bfb\u670d\u52a1\u5668<br>url: \u670d\u52a1\u5668\u7684ip\u5730\u5740\u548c\u7aef\u53e3<br>user: \u670d\u52a1\u5668\u4e0a mysql \u7684\u7528\u6237\u540d<br>password: \u670d\u52a1\u5668\u4e0a mysql \u7684\u7528\u6237\u5bc6\u7801<br>\u5fc3\u8df3\u68c0\u6d4b \uff0c \u65b9\u4fbf\u6211\u4eec\u67e5\u770b\u8bfb\u5199\u5206\u79bb\u60c5\u51b5<br>balance=&#8221;0&#8243;, \u4e0d\u5f00\u542f\u8bfb\u5199\u5206\u79bb\u673a\u5236\uff0c\u6240\u6709\u8bfb\u64cd\u4f5c\u90fd\u53d1\u9001\u5230\u5f53\u524d\u53ef\u7528\u7684 writeHost \u4e0a \u3002<br>balance=&#8221;1&#8243;\uff0c\u5168\u90e8\u7684 readHost \u4e0e stand by writeHost \u53c2\u4e0e select \u8bed\u53e5\u7684\u8d1f\u8f7d\u5747\u8861\uff0c\u7b80\u5355\u7684\u8bf4\uff0c\u5f53\u53cc\u4e3b\u53cc\u4ece\u6a21\u5f0f(M1 ->S1 \uff0c M2->S2\uff0c\u5e76\u4e14 M1 \u4e0e M2 \u4e92\u4e3a\u4e3b\u5907)\uff0c\u6b63\u5e38\u60c5\u51b5\u4e0b\uff0c M2,S1,S2 \u90fd\u53c2\u4e0e select \u8bed\u53e5\u7684\u8d1f\u8f7d\u5747\u8861\u3002<br>balance=&#8221;2&#8243; \uff0c \u6240 \u6709 \u8bfb \u64cd \u4f5c \u90fd \u968f \u673a \u7684 \u5728 writeHost \u3001 readhost \u4e0a\u5206\u53d1\u3002<br>balance=&#8221;3&#8243;\uff0c \u6240\u6709\u8bfb\u8bf7\u6c42\u968f\u673a\u7684\u5206\u53d1\u5230 wiriterHost \u5bf9\u5e94\u7684 readhost \u6267\u884c,writerHost \u4e0d\u8d1f\u62c5\u8bfb\u538b\u529b\uff0c\u6ce8\u610f balance=3\u53ea\u57281.4\u53ca\u5176\u4ee5\u540e\u7248\u672c\u6709\uff0c1.3\u6ca1\u6709\u3002<br>writeType=&#8221;0&#8243;, \u6240\u6709\u5199\u64cd\u4f5c\u53d1\u9001\u5230\u914d\u7f6e\u7684\u7b2c\u4e00\u4e2a writeHost\uff0c\u7b2c\u4e00\u4e2a\u6302\u4e86\u5207\u5230\u8fd8\u751f\u5b58\u7684\u7b2c\u4e8c\u4e2awriteHost \uff0c\u91cd\u65b0\u542f\u52a8\u540e \u5df2\u5207\u6362 \u540e\u7684\u4e3a\u51c6\uff0c\u5207\u6362\u8bb0\u5f55\u5728 \u914d\u7f6e\u6587\u4ef6\u4e2d:dnindex.properties .<br>writeType=&#8221;1&#8243; \uff0c \u6240\u6709\u5199\u64cd\u4f5c\u90fd\u968f\u673a\u7684\u53d1\u9001\u5230\u914d\u7f6e\u7684 writeHost \u3002<br>writeType=&#8221;2&#8243;\uff0c\u6ca1\u5b9e\u73b0\u3002-1 \u8868\u793a\u4e0d\u81ea\u52a8\u5207\u6362 1 \u9ed8\u8ba4\u503c\uff0c\u81ea\u52a8\u5207\u6362 2 \u57fa\u4e8e MySQL \u4e3b\u4ece\u540c\u6b65\u7684\u72b6\u6001\u51b3\u5b9a\u662f\u5426\u5207\u6362<\/p>\n\n\n\n<p>\u914d \u7f6e log4j2.xml<br>\u6587 \u4ef6 vim \/root\/mycat\/conf\/log4j2.xml<br># \u65e5\u5fd7\u7ea7\u522b\u8bbe\u7f6e\u6210 debug<\/p>\n\n\n\n<p>\u914d\u7f6e wrapper.conf \u6587\u4ef6,<br>vim \/root\/mycat\/conf\/wrapper.conf<br>wrapper.java.command=\/root\/jre1.8.0_251\/bin\/java<br>wapper.java.additional.10=-Xmx512M<br>wrapper.java.additional.11=-Xms64M<\/p>\n\n\n\n<p>uos1 \u4e3b\u5e93 \uff1a<br>use mysql<br>update user set host = &#8216;%&#8217; where user = &#8216;root&#8217;;<br>system restart mariadb<\/p>\n\n\n\n<p>uos2 \u4ece\u5e93\uff1a<br>\u4fee\u6539 MySQL \u7684\u914d\u7f6e\u6587\u4ef6\/etc\/mysql\/mariadb.conf.d\/50-server.cnf\uff0c\u56e0\u4e3a\u9ed8\u8ba4 3306 \u7aef\u53e3\u53ea\u5141\u8bb8\u672c\u5730\u8bbf\u95ee\u7684\uff0c\u6ce8\u91ca\u6389\u8fd9\u884c<br>vi \/etc\/mysql\/mariadb.conf.d\/50-server.cnf<br>\/\/ \u627e \u5230 &#8220;bind-address = 127.0.0.1&#8221; \u8fd9\u4e00\u884c\uff0c\u524d\u9762\u6dfb\u52a0#\u9700\u8fdb\u5165\u6570\u636e\u5e93 mysql, \u4fee\u6539 user \u8868 \uff0c\u5982\u679c\u6ca1\u6709\u5bc6\u7801\u8bbe\u7f6e\u65b0\u5bc6\u7801\u4e3a 123<br>use mysql;<br>UPDATE user SET password=PASSWORD(&#8216; \u65b0\u5bc6\u7801 &#8216;) WHERE user=&#8217; \u7528\u6237 &#8216;;<br>flush privileges;<br>systemctl restart mariadb<\/p>\n\n\n\n<p>\u5728 uos1 \u4e0a<br>\/root\/mycat\/bin\/mycat start<br>\u767b\u5f55 mycat<br>mysql -u root -h127.0.0.1 -P8066 -p123 -Duos<br>\u63d2\u5165\u6570\u636e\uff1a<br>insert into dept values (60,&#8217;SALES&#8217;,&#8217;JAM&#8217;);<br>\u67e5\u8be2\u6570\u636e\uff1a<br>select * from dept;<br>\u67e5\u770b mycat \u65e5\u5fd7\u770b\u7ed3\u679c<br>tail -100 \/root\/mycat\/logs\/mycat.log<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u7b80\u4ecb 1\u3001\u4ec0\u4e48\u662f\u6570\u636e\u5e93?\u6570\u636e\u5e93\u662f\u201c\u6309\u7167\u6570\u636e\u7ed3\u6784\u6765\u7ec4\u7ec7\u3001\u5b58\u50a8\u548c\u7ba1\u7406\u6570\u636e\u7684\u4ed3\u5e93\u201d\u3002\u662f\u4e00\u4e2a\u957f\u671f\u5b58\u50a8\u5728\u8ba1\u7b97\u673a\u5185\u7684\u3001 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3170,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[111,104,110],"class_list":["post-3151","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-2","tag-mysql","tag-104","tag-110"],"_links":{"self":[{"href":"https:\/\/www.fatesky.com\/index.php?rest_route=\/wp\/v2\/posts\/3151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fatesky.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fatesky.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fatesky.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fatesky.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3151"}],"version-history":[{"count":1,"href":"https:\/\/www.fatesky.com\/index.php?rest_route=\/wp\/v2\/posts\/3151\/revisions"}],"predecessor-version":[{"id":3274,"href":"https:\/\/www.fatesky.com\/index.php?rest_route=\/wp\/v2\/posts\/3151\/revisions\/3274"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fatesky.com\/index.php?rest_route=\/wp\/v2\/media\/3170"}],"wp:attachment":[{"href":"https:\/\/www.fatesky.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fatesky.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fatesky.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}