{"id":456,"date":"2010-06-17T18:44:03","date_gmt":"2010-06-17T18:44:03","guid":{"rendered":""},"modified":"2010-06-17T18:44:03","modified_gmt":"2010-06-17T18:44:03","slug":"456","status":"publish","type":"post","link":"https:\/\/www.poloo.org\/?p=456","title":{"rendered":"Ubuntu\u5b89\u88c5\u4e0e\u914d\u7f6eMySQL\u6570\u636e\u5e93\u7684\u65b9\u6848\u4e0e\u64cd\u4f5c"},"content":{"rendered":"<p>\u4e09\u79cd\u5b89\u88c5\u65b9\u5f0f\uff1a<\/p>\n<p>1. \u4ece\u7f51\u4e0a\u5b89\u88c5 sudo apt-get install mysql-server\u3002\u88c5\u5b8c\u5df2\u7ecf\u81ea\u52a8\u914d\u7f6eMysql\u597d\u73af\u5883\u53d8\u91cf\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528mysql\u7684\u547d\u4ee4\u3002<\/p>\n<p>\u6ce8\uff1a\u5efa\u8bae\u5c06\/etc\/apt\/source.list\u4e2d\u7684cn\u6539\u6210us\uff0c\u7f8e\u56fd\u7684\u670d\u52a1\u5668\u6bd4\u4e2d\u56fd\u7684\u5feb\u5f88\u591a\u3002<\/p>\n<p>2. \u5b89\u88c5\u79bb\u7ebf\u5305\uff0c\u4ee5mysql-5.0.45-linux-i686-icc-glibc23.tar.gz\u4e3a\u4f8b\u3002<\/p>\n<p>3. \u4e8c\u8fdb\u5236\u5305\u5b89\u88c5\uff1a\u5b89\u88c5\u5b8c\u6210\u5df2\u7ecf\u81ea\u52a8\u914d\u7f6eMysql\u597d\u73af\u5883\u53d8\u91cf\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528mysql\u547d\u4ee4<\/p>\n<p>\u7f51\u4e0a\u5b89\u88c5\u548c\u4e8c\u8fdb\u5236\u5305\u5b89\u88c5\u6bd4\u8f83\u7b80\u5355\uff0c\u91cd\u70b9\u8bf4\u5b89\u88c5\u79bb\u7ebf\u5305\u3002<\/p>\n<p>1. groupadd mysql<\/p>\n<p>2. mkdir \/home\/mysql<\/p>\n<p>3. useradd -g MySQL-d \/home\/MySQLmysql<\/p>\n<p>4. copy mysql-5.0.45-linux-i686-icc-glibc23.tar.gz\u5230\/usr\/local\u76ee\u5f55<\/p>\n<p>5. \u89e3\u538b\uff1atar zxvf mysql-5.0.45-linux-i686-icc-glibc23.tar.gz<\/p>\n<p>6. ln -s mysql-5.0.45-linux-i686-icc-glibc23 mysql<\/p>\n<p>7. cd \/usr\/local\/mysql<\/p>\n<p>8. chown -R MySQL.<\/p>\n<p>9. chgrp -R MySQL.<\/p>\n<p>10. scripts\/mysql_install_db &#8211;user=MySQL(\u4e00\u5b9a\u8981\u5728mysql\u76ee\u5f55\u4e0b\u6267\u884c\uff0c\u6ce8\u610f\u8f93\u51fa\u7684\u6587\u5b57\uff0c\u91cc\u8fb9\u6709\u4fee\u6539root\u5bc6\u7801\u548c\u542f\u52a8mysql\u7684\u547d\u4ee4\uff09<\/p>\n<p>11. \u4e3aroot\u8bbe\u7f6e\u5bc6\u7801\uff1a .\/bin\/mysqladmin -u root password &#8216;passw0rd&#8217;<\/p>\n<p><strong>\u914d\u7f6eMySQL\u548c\u7ba1\u7406MySQL<\/strong><\/p>\n<p>1. \u4fee\u6539mysql\u6700\u5927\u8fde\u63a5\u6570\uff1acp support-files\/my-medium.cnf .\/my.cnf\uff0cvim my.cnf\uff0c\u589e\u52a0\u6216\u4fee\u6539max_connections=1024<\/p>\n<p>\u5173\u4e8emy.cnf\uff1amysql\u6309\u7167\u4e0b\u5217\u987a\u5e8f\u641c\u7d22my.cnf:\/etc,mysql\u5b89\u88c5\u76ee\u5f55\uff0c\u5b89\u88c5\u76ee\u5f55\u4e0b\u7684data\u3002\/etc\u4e0b\u7684\u662f\u5168\u5c40\u8bbe\u7f6e\u3002<\/p>\n<p>2. \u542f\u52a8mysql\uff1a\/usr\/local\/mysql\/bin\/mysqld_safe &#8211;user=MySQL&#038;<\/p>\n<p>\u67e5\u770bmysql\u7248\u672c\uff1amysqladmin -u root -p version<\/p>\n<p>\u6ce8\uff1a\u7f51\u4e0a\u5b89\u88c5\u6216\u8005\u4e8c\u8fdb\u5236\u5b89\u88c5\u7684\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u542f\u52a8\u548c\u505c\u6b62mysql: \/etc\/init.d\/MySQLstart|stop|restart<\/p>\n<p>3. \u505c\u6b62mysql\uff1amysqladmin -uroot -ppassw0rd shutdown \u6ce8\u610f\uff0cu,p\u540e\u6ca1\u6709\u7a7a\u683c<\/p>\n<p>4. \u8bbe\u7f6emysql\u81ea\u542f\u52a8\uff1a\u628a\u542f\u52a8\u547d\u4ee4\u52a0\u5165\/etc\/rc.local\u6587\u4ef6\u4e2d<\/p>\n<p>5. \u5141\u8bb8root\u8fdc\u7a0b\u767b\u9646\uff1a<\/p>\n<p>1\uff09\u672c\u673a\u767b\u9646mysql\uff1aMySQL-u root -p \uff08-p\u4e00\u5b9a\u8981\u6709\uff09\uff1b\u6539\u53d8\u6570\u636e\u5e93\uff1ause mysql;<\/p>\n<p>2\uff09\u4ece\u6240\u6709\u4e3b\u673a\uff1agrant all privileges on *.* to root@&#8221;%&#8221; identified by &#8220;passw0rd&#8221; with grant option;<\/p>\n<p>3\uff09\u4ece\u6307\u5b9a\u4e3b\u673a\uff1agrant all privileges on *.* to root@&#8221;192.168.11.205&#8243; identified by &#8220;passw0rd&#8221; with grant option; flush privileges;<\/p>\n<p>4) \u8fdbmysql\u5e93\u67e5\u770bhost\u4e3a%\u7684\u6570\u636e\u662f\u5426\u6dfb\u52a0\uff1ause mysql; select * from user;<\/p>\n<p>6. \u521b\u5efa\u6570\u636e\u5e93\uff0c\u521b\u5efauser\uff1a<\/p>\n<p>1) \u5efa\u5e93\uff1acreate database test1;<\/p>\n<p>2) \u5efa\u7528\u6237\uff0c\u8d4b\u6743\uff1agrant all privileges on test1.* to user_test@&#8221;%&#8221; identified by &#8220;passw0rd&#8221; with grant option;<\/p>\n<p>3\uff09\u5220\u9664\u6570\u636e\u5e93\uff1adrop database test1;<\/p>\n<p>7. \u5220\u9664\u6743\u9650\uff1a<\/p>\n<p>1) revoke all privileges on test1.* from test1@&#8221;%&#8221;;<\/p>\n<p>2) use mysql;<\/p>\n<p>3) delete from user where user=&#8221;root&#8221; and host=&#8221;%&#8221;;<\/p>\n<p>4) flush privileges;<\/p>\n<p>8. \u663e\u793a\u6240\u6709\u7684\u6570\u636e\u5e93\uff1ashow databases; \u663e\u793a\u5e93\u4e2d\u6240\u6709\u7684\u8868\uff1ashow tables;<\/p>\n<p>9. \u8fdc\u7a0b\u767b\u5f55mysql\uff1aMySQL-h ip -u user -p<\/p>\n<p>10. \u8bbe\u7f6e\u5b57\u7b26\u96c6\uff08\u4ee5utf8\u4e3a\u4f8b\uff09\uff1a<\/p>\n<p>1\uff09 \u67e5\u770b\u5f53\u524d\u7684\u7f16\u7801\uff1ashow variables like &#8216;character%&#8217;;<\/p>\n<p>2)\u3000\u4fee\u6539my.cnf\uff0c\u5728[client]\u4e0b\u6dfb\u52a0default-character-set=utf8<\/p>\n<p>3\uff09 \u5728[server]\u4e0b\u6dfb\u52a0default-character-set=utf8\uff0cinit_connect=&#8217;SET NAMES utf8;&#8217;<\/p>\n<p>4\uff09 \u91cd\u542fmysql\u3002<\/p>\n<p>\u6ce8\uff1a\u53ea\u6709\u4fee\u6539\/etc\u4e0b\u7684my.cnf\u624d\u80fd\u4f7fclient\u7684\u8bbe\u7f6e\u8d77\u6548\uff0c\u5b89\u88c5\u76ee\u5f55\u4e0b\u7684\u8bbe\u7f6e\u53ea\u80fd\u4f7fserver\u7684\u8bbe\u7f6e\u6709\u6548\u3002<\/p>\n<p>\u4e8c\u8fdb\u5236\u5b89\u88c5\u7684\u4fee\u6539\/etc\/mysql\/my.cnf\u5373\u53ef<\/p>\n<p>11. \u65e7\u6570\u636e\u5347\u7ea7\u5230utf8\uff08\u65e7\u6570\u636e\u4ee5latin1\u4e3a\u4f8b\uff09\uff1a<\/p>\n<p>1\uff09 \u5bfc\u51fa\u65e7\u6570\u636e\uff1amysqldump &#8211;default-character-set=latin1 -hlocalhost -uroot -B dbname &#8211;tables old_table &gt;old.sql<\/p>\n<p>2\uff09 \u8f6c\u6362\u7f16\u7801(Linux\u548cUNIX)\uff1aiconv -t utf-8 -f gb2312 -c old.sql &gt; new.sql<\/p>\n<p>\u8fd9\u91cc\u5047\u5b9a\u539f\u8868\u7684\u6570\u636e\u4e3agb2312\uff0c\u4e5f\u53ef\u4ee5\u53bb\u6389-f\uff0c\u8ba9iconv\u81ea\u52a8\u5224\u65ad\u539f\u6765\u7684\u5b57\u7b26\u96c6\u3002<\/p>\n<p>3\uff09 \u5bfc\u5165\uff1a\u4fee\u6539new.sql\uff0c\u5728\u63d2\u5165\u6216\u4fee\u6539\u8bed\u53e5\u524d\u52a0\u4e00\u53e5\u8bdd\uff1a&#8221;SET NAMES utf8;&#8221;\uff0c\u5e76\u4fee\u6539\u6240\u6709\u7684gb2312\u4e3autf8\uff0c\u4fdd\u5b58\u3002<\/p>\n<p>MySQL-hlocalhost -uroot -p dbname &lt; new.sql<\/p>\n<p>\u5982\u679c\u62a5max_allowed_packet\u7684\u9519\u8bef\uff0c\u662f\u56e0\u4e3a\u6587\u4ef6\u592a\u5927\uff0cmysql\u9ed8\u8ba4\u7684\u8fd9\u4e2a\u53c2\u6570\u662f1M\uff0c\u4fee\u6539my.cnf\u4e2d\u7684\u503c\u5373\u53ef\uff08\u9700\u8981\u91cd\u542fmysql)\u3002<\/p>\n<p>12. \u652f\u6301utf8\u7684\u5ba2\u6237\u7aef\uff1aMysql-Front,Navicat,PhpMyAdmin\uff0cLinux Shell\uff08\u8fde\u63a5\u540e\u6267\u884cSET NAMES utf8;\u540e\u5c31\u53ef\u4ee5\u8bfb\u5199utf8\u7684\u6570\u636e\u4e86\u300210.4\u8bbe\u7f6e\u5b8c\u6bd5\u540e\u5c31\u4e0d\u7528\u518d\u6267\u884c\u8fd9\u53e5\u8bdd\u4e86\uff09<\/p>\n<p>13. \u5907\u4efd\u548c\u6062\u590d<\/p>\n<p>\u5907\u4efd\u5355\u4e2a\u6570\u636e\u5e93\uff1amysqldump -uroot -p -B dbname &gt; dbname.sql<\/p>\n<p>\u5907\u4efd\u5168\u90e8\u6570\u636e\u5e93\uff1amysqldump -uroot -p &#8211;all-databases &gt; all.sql<\/p>\n<p>\u5907\u4efd\u8868\uff1a mysqldump -uroot -p -B dbname &#8211;table tablename &gt; tablename.sql<\/p>\n<p>\u6062\u590d\u6570\u636e\u5e93\uff1aMySQL-uroot -p &lt; name.sql<\/p>\n<p>\u6062\u590d\u8868\uff1aMySQL-uroot -p dbname &lt; name.sql (\u5fc5\u987b\u6307\u5b9a\u6570\u636e\u5e93)<\/p>\n<p>14. \u590d\u5236<\/p>\n<p>Mysql\u652f\u6301\u5355\u5411\u7684\u5f02\u6b65\u590d\u5236\uff0c\u5373\u4e00\u4e2a\u670d\u52a1\u5668\u505a\u4e3b\u670d\u52a1\u5668\uff0c\u5176\u4ed6\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u670d\u52a1\u5668\u505a\u4ece\u670d\u52a1\u5668\u3002\u590d\u5236\u662f\u901a\u8fc7\u4e8c\u8fdb\u5236\u65e5\u5fd7\u5b9e\u73b0\u7684\uff0c\u4e3b\u670d\u52a1\u5668\u5199\u5165\uff0c\u4ece\u670d\u52a1\u5668\u8bfb\u53d6\u3002\u53ef\u4ee5\u5b9e\u73b0\u591a\u4e2a\u4e3b\u670d\u52a1\u5668\uff0c\u4f46\u662f\u4f1a\u78b0\u5230\u5355\u4e2a\u670d\u52a1\u5668\u4e0d\u66fe\u9047\u5230\u7684\u95ee\u9898\uff08\u4e0d\u63a8\u8350\uff09\u3002<\/p>\n<p>1). \u5728\u4e3b\u670d\u52a1\u5668\u4e0a\u5efa\u7acb\u4e00\u4e2a\u4e13\u95e8\u7528\u6765\u505a\u590d\u5236\u7684\u7528\u6237\uff1agrant replication slave on *.* to &#8216;replicationuser&#8217;@&#8217;192.168.0.87&#8217; identified by &#8216;iverson&#8217;;<\/p>\n<p>2). \u5237\u65b0\u4e3b\u670d\u52a1\u5668\u4e0a\u6240\u6709\u7684\u8868\u548c\u5757\u5199\u5165\u8bed\u53e5\uff1aflush tables with read lock; \u7136\u540e\u8bfb\u53d6\u4e3b\u670d\u52a1\u5668\u4e0a\u7684\u4e8c\u8fdb\u5236\u4e8c\u8fdb\u5236\u6587\u4ef6\u540d\u548c\u5206\u652f\uff1aSHOW MASTER STATUS;\u5c06File\u548cPosition\u7684\u503c\u8bb0\u5f55\u4e0b\u6765\u3002\u8bb0\u5f55\u540e\u5173\u95ed\u4e3b\u670d\u52a1\u5668\uff1amysqladmin -uroot -ppassw0rd shutdown<\/p>\n<p>\u5982\u679c\u8f93\u51fa\u4e3a\u7a7a\uff0c\u8bf4\u660e\u670d\u52a1\u5668\u6ca1\u6709\u542f\u7528\u4e8c\u8fdb\u5236\u65e5\u5fd7\uff0c\u5728my.cnf\u6587\u4ef6\u4e2d[mysqld]\u4e0b\u6dfb\u52a0log-bin=mysql-bin\uff0c\u91cd\u542f\u540e\u5373\u6709\u3002<\/p>\n<p>3). \u4e3a\u4e3b\u670d\u52a1\u5668\u5efa\u7acb\u5feb\u7167\uff08snapshot\uff09<\/p>\n<p>\u9700\u8981\u4e3a\u4e3b\u670d\u52a1\u5668\u4e0a\u7684\u9700\u8981\u590d\u5236\u7684\u6570\u636e\u5e93\u5efa\u7acb\u5feb\u7167\uff0cWindows\u53ef\u4ee5\u4f7f\u7528zip\u683c\u5f0f\uff0cLinux\u548cUnix\u6700\u597d\u4f7f\u7528tar\u547d\u4ee4\u3002\u7136\u540e\u4e0a\u4f20\u5230\u4ece\u670d\u52a1\u5668mysql\u7684\u6570\u636e\u76ee\u5f55\uff0c\u5e76\u89e3\u538b\u3002<\/p>\n<p><code><br \/>cd mysql-data-dir&nbsp;&nbsp;<br \/>tar cvzf mysql-snapshot.tar .\/mydb&nbsp;&nbsp;<br \/><\/code><br \/>\u6ce8\u610f\uff1a\u5feb\u7167\u4e2d\u4e0d\u5e94\u8be5\u5305\u542b\u4efb\u4f55\u65e5\u5fd7\u6587\u4ef6\u6216*.info\u6587\u4ef6\uff0c\u53ea\u5e94\u8be5\u5305\u542b\u8981\u590d\u5236\u7684\u6570\u636e\u5e93\u7684\u6570\u636e\u6587\u4ef6\uff08*.frm\u548c*.opt\uff09\u6587\u4ef6\u3002<\/p>\n<p>\u53ef\u4ee5\u7528\u6570\u636e\u5e93\u5907\u4efd(mysqldump)\u4e3a\u4ece\u670d\u52a1\u5668\u505a\u4e00\u6b21\u6570\u636e\u6062\u590d\uff0c\u4fdd\u8bc1\u6570\u636e\u7684\u4e00\u81f4\u6027\u3002<\/p>\n<p>4). \u786e\u8ba4\u4e3b\u670d\u52a1\u5668\u4e0amy.cnf\u6587\u4ef6\u7684[mysqld]section\u5305\u542blog-bin\u9009\u9879\u548cserver-id\uff0c\u5e76\u542f\u52a8\u4e3b\u670d\u52a1\u5668\uff1a<\/p>\n<p><code><br \/>[mysqld]&nbsp;&nbsp;<br \/>log-bin=mysql-bin&nbsp;&nbsp;<br \/>server-id=1 <br \/><\/code><br \/>5). \u505c\u6b62\u4ece\u670d\u52a1\u5668\uff0c\u52a0\u5165server-id\uff0c\u7136\u540e\u542f\u52a8\u4ece\u670d\u52a1\u5668\uff1a<\/p>\n<p><code><br \/>[mysqld]&nbsp;&nbsp;<br \/>server-id=2 <br \/><\/code><br \/>\u6ce8\uff1a\u8fd9\u91cc\u7684server-id\u662f\u4ece\u670d\u52a1\u5668\u7684id\uff0c\u5fc5\u987b\u4e0e\u4e3b\u670d\u52a1\u5668\u548c\u5176\u4ed6\u4ece\u670d\u52a1\u5668\u4e0d\u4e00\u6837\u3002<\/p>\n<p>\u53ef\u4ee5\u5728\u4ece\u670d\u52a1\u5668\u7684\u914d\u7f6eMysql\u6587\u4ef6\u4e2d\u52a0\u5165read-only\u9009\u9879\uff0c\u8fd9\u6837\u4ece\u670d\u52a1\u5668\u5c31\u53ea\u63a5\u53d7\u6765\u81ea\u4e3b\u670d\u52a1\u5668\u7684SQL\uff0c\u786e\u4fdd\u6570\u636e\u4e0d\u4f1a\u88ab\u5176\u4ed6\u9014\u7ecf\u4fee\u6539\u3002<\/p>\n<p>6). \u5728\u4ece\u670d\u52a1\u5668\u4e0a\u6267\u884c\u5982\u4e0b\u8bed\u53e5\uff0c\u7528\u7cfb\u7edf\u771f\u5b9e\u503c\u4ee3\u66ff\u9009\u9879\uff1a<\/p>\n<p><code><br \/>change master to MASTER_HOST='master_host', MASTER_USER='replication_user',MASTER_PASSWORD='replication_pwd',&nbsp;&nbsp;MASTER_LOG_FILE='recorded_log_file_name',MASTER_LOG_POS=log_position;&nbsp;&nbsp;<br \/><\/code><br \/>7). \u542f\u52a8\u4ece\u7ebf\u7a0b\uff1amysql&gt; START SLAVE; \u505c\u6b62\u4ece\u7ebf\u7a0b\uff1astop slave;\uff08\u6ce8\u610f\uff1a\u4e3b\u670d\u52a1\u5668\u7684\u9632\u706b\u5899\u5e94\u8be5\u5141\u8bb83306\u7aef\u53e3\u8fde\u63a5\uff09<\/p>\n<p>\u9a8c\u8bc1\uff1a\u6b64\u65f6\u4e3b\u670d\u52a1\u5668\u548c\u4ece\u670d\u52a1\u5668\u4e0a\u7684\u6570\u636e\u5e94\u8be5\u662f\u4e00\u81f4\u7684\uff0c\u5728\u4e3b\u670d\u52a1\u5668\u4e0a\u63d2\u5165\u4fee\u6539\u5220\u9664\u6570\u636e\u90fd\u4f1a\u66f4\u65b0\u5230\u4ece\u670d\u52a1\u5668\u4e0a\uff0c\u5efa\u8868\uff0c\u5220\u8868\u7b49\u4e5f\u662f\u4e00\u6837\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e09\u79cd\u5b89\u88c5\u65b9\u5f0f\uff1a 1. \u4ece\u7f51\u4e0a\u5b89\u88c5 sudo apt-get inst&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-456","post","type-post","status-publish","format-standard","hentry","category-DB"],"_links":{"self":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/456","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=456"}],"version-history":[{"count":0,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/456\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}