{"id":27,"date":"2017-10-30T23:30:22","date_gmt":"2017-10-30T15:30:22","guid":{"rendered":"http:\/\/kkong.net\/?p=27"},"modified":"2018-03-25T13:33:45","modified_gmt":"2018-03-25T05:33:45","slug":"linux-%e6%93%8d%e4%bd%9cmysql%e6%95%b0%e6%8d%ae%e5%ba%93-%e5%88%9b%e5%bb%ba%e5%ba%93-%e5%af%bc%e5%85%a5%e3%80%81%e5%88%a0%e9%99%a4%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/kkong.net\/?p=27","title":{"rendered":"Linux \u64cd\u4f5cmysql\u6570\u636e\u5e93 \u521b\u5efa\u5e93 \u5bfc\u5165\u3001\u5220\u9664\u8868,\u91cd\u88c5"},"content":{"rendered":"<p><strong>linux mysql \u5fd8\u8bb0root\u7684\u5bc6\u7801\u65e0\u6cd5\u767b\u9646\u8fdbmysql<\/strong><\/p>\n<p>1\u3001\u4fee\u6539MySQL\u7684\u914d\u7f6e\u6587\u4ef6\/etc\/my.conf\u5728[mysqld]\u4e0b\u9762\u589e\u52a0\u4e00\u884c<strong>skip-grant-table<\/strong>;<\/p>\n<p>2\u3001\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u540e\u91cd\u542fMySQL <strong>service mysqld restart<\/strong><\/p>\n<p>3\u3001\u7136\u540e\u4f7f\u7528\u5e38\u89c4\u7684\u547d\u4ee4\u8fdb\u884c\u767b\u9646<strong>mysql mysql -u root -p<\/strong> \u5728\u63d0\u793a\u8f93\u5165\u5bc6\u7801\u7684\u65f6\u5019\u76f4\u63a5\u70b9\u51fb\u56de\u8f66\u5c31\u597d<\/p>\n<p>4\u3001\u767b\u9646\u8fdbmysql\u540e\u6267\u884c\u4fee\u6539\u5bc6\u7801\u7684\u8bed\u53e5 <strong>update set password=passeord('root') where user ='root';<\/strong>\u8fd9\u4e2a\u65f6\u5019passeord('root')\u4e2d<strong>root<\/strong>\u5c31\u662f\u6700\u65b0\u8bbe\u7f6e\u597d\u7684root\u7528\u6237\u7684\u5bc6\u7801<\/p>\n<p>5\u3001\u5728\u6267\u884c\u7b2c\u4e00\u6b65\uff0c\u5c06\u81ea\u5df1\u6dfb\u52a0\u7684skip-grant-table\u53bb\u6389\uff0c\u7136\u540e\u91cd\u542fmysql<\/p>\n<p>\u4e00\u3001Linux MySQL\u521b\u5efa \u3001\u5220\u9664\u6570\u636e\u5e93<\/p>\n<p>\u4f7f\u7528\u547d\u4ee4\u8fdb\u5165mysql<\/p>\n<p>create\u00a0database \u6570\u636e\u5e93\u540d;<\/p>\n<p>\u8fd9\u6837\u5c31\u521b\u5efa\u4e86\u4e00\u4e2a\u81ea\u5df1\u660e\u660e\u7684\u6570\u636e\u5e93<\/p>\n<p>\u4f7f\u7528 show databases;\u53ef\u4ee5\u67e5\u770b\u6240\u6709\u7684\u6570\u636e\u5e93<\/p>\n<p>\u4e8c\u3001\u5220\u9664\u6570\u636e\u5e93<\/p>\n<p>\u6267\u884c\u547d\u4ee4drop databases \u6570\u636e\u5e93\u540d;<\/p>\n<p>\u5220\u9664\u6570\u636e\u5e93\u4e2d\u7684\u8868\u540c\u7406<\/p>\n<p>\u6267\u884c\u547d\u4ee4DROP TABLE tbl_name; \u6216\u8005\u662f DROP TABLE IF EXISTS tbl_name;<\/p>\n<p>\u4e09\u3001mysql \u5bfc\u5165\u3001\u5bfc\u51fa\u6570\u636e\u5e93<\/p>\n<p>\u65b9\u6cd5\u4e00\uff1a<\/p>\n<p><strong>\u5982\u679c\u6ca1\u6709\u6570\u636e\u5e93\u7684\u8bdd\u5219\u9700\u8981\u5148\u5efa\u7acb\u6570\u636e\u5e93\u901a\u8fc7 create tables \u8868\u540d;\u7136\u540e\u4f7f\u7528show databases;\u67e5\u770b\u6570\u636e\u5e93<\/strong><\/p>\n<p><strong>\u6570\u636e\u5e93\u5982\u679c\u5b58\u5728\u7684\u4f7f\u7528use \u6570\u636e\u5e93\u540d;\u8fd9\u4e2a\u547d\u4ee4\u53ef\u4ee5\u8fdb\u5230\u6570\u636e\u5e93\u5185source \/root\/my.sql; \u00a0 \u00a0 \u00a0 \u00a0source \/root\/my.sql;\u8fd9\u4e2a\u547d\u4ee4\u662f\u5c06\u540d\u4e3amy.sql\u7684\u6570\u636e\u6587\u4ef6\u5bfc\u5165\u5230\u6570\u636e\u5e93\u5185\u4f46\u662f\/root\/\u8fd9\u662fLinux\u4e0a\u9762\u5b58\u653emysql\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u6839\u636e\u81ea\u5df1\u7684\u586b\u5199<\/strong><\/p>\n<p>\u65b9\u6cd5\u4e8c\uff1a<\/p>\n<p>\/usr\/local\/mysql\/bin\/mysql -u root -p \u6570\u636e\u5e93\u540d &lt; \/root\/test.sql;<\/p>\n<p><strong>\/usr\/local\/mysql\/bin\/mysql -u root -p \u9700\u8981\u5bfc\u5165\u5230\u54ea\u4e2a\u6570\u636e\u5e93\u7684\u6570\u636e\u5e93\u540d &lt; \u9700\u8981\u5bfc\u5165\u7684\u6570\u636e\u5e93\u6587\u4ef6\uff1b\u4f8b\u5982\u547d\u4ee4\uff1a\/usr\/local\/mysql\/bin\/mysql -u root -p daobidao &lt; \/root\/test.sql \u00a0 \u5c06\u6570\u636e\u5e93\u6587\u4ef6test.sql\u6587\u4ef6\u5bfc\u5165\u5230daobidao\u6570\u636e\u5e93\u4e2d\uff1b\u00a0\uff08\u4f46\u9700\u8981\u5bfc\u5165\u5230\u54ea\u4e2a\u6570\u636e\u5e93\u5fc5\u987b\u8981\u5b58\u5728\uff09<\/strong><\/p>\n<p><strong>MySql\u4e2d\u6dfb\u52a0\u7528\u6237,\u65b0\u5efa\u6570\u636e\u5e93,\u7528\u6237\u6388\u6743,\u5220\u9664\u7528\u6237,\u4fee\u6539\u5bc6\u7801(\u6ce8\u610f\u6bcf\u884c\u540e\u8fb9\u90fd\u8ddf\u4e2a;\u8868\u793a\u4e00\u4e2a\u547d\u4ee4\u8bed\u53e5\u7ed3\u675f):<\/strong><\/p>\n<p><strong>1.\u65b0\u5efa\u7528\u6237<\/strong><\/p>\n<p><strong>1.1 \u767b\u5f55MYSQL\uff1a<\/strong><\/p>\n<p>@&gt;mysql -u root -p<\/p>\n<p>@&gt;\u5bc6\u7801<\/p>\n<p><strong>1.2 \u521b\u5efa\u7528\u6237\uff1a<\/strong><\/p>\n<p>mysql&gt; insert into mysql.user(Host,User,Password) values(\"localhost\",\"test\",password(\"1234\"));<\/p>\n<p>\u8fd9\u6837\u5c31\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a\uff1atest \u5bc6\u7801\u4e3a\uff1a1234 \u7684\u7528\u6237\u3002<\/p>\n<p>\u6ce8\u610f\uff1a\u6b64\u5904\u7684\"localhost\"\uff0c\u662f\u6307\u8be5\u7528\u6237\u53ea\u80fd\u5728\u672c\u5730\u767b\u5f55\uff0c\u4e0d\u80fd\u5728\u53e6\u5916\u4e00\u53f0\u673a\u5668\u4e0a\u8fdc\u7a0b\u767b\u5f55\u3002\u5982\u679c\u60f3\u8fdc\u7a0b\u767b\u5f55\u7684\u8bdd\uff0c\u5c06\"localhost\"\u6539\u4e3a\"%\"\uff0c\u8868\u793a\u5728\u4efb\u4f55\u4e00\u53f0\u7535\u8111\u4e0a\u90fd\u53ef\u4ee5\u767b\u5f55\u3002\u4e5f\u53ef\u4ee5\u6307\u5b9a\u67d0\u53f0\u673a\u5668\u53ef\u4ee5\u8fdc\u7a0b\u767b\u5f55\u3002<\/p>\n<p><strong>1.3 \u7136\u540e\u767b\u5f55\u4e00\u4e0b\uff1a<\/strong><\/p>\n<p>mysql&gt;exit;<\/p>\n<p>@&gt;mysql -u\u00a0test -p<\/p>\n<p>@&gt;\u8f93\u5165\u5bc6\u7801<\/p>\n<p>mysql&gt;\u767b\u5f55\u6210\u529f<\/p>\n<p>&nbsp;<\/p>\n<p><strong>2.\u4e3a\u7528\u6237\u6388\u6743<\/strong><\/p>\n<p>\u6388\u6743\u683c\u5f0f\uff1agrant \u6743\u9650 on \u6570\u636e\u5e93.* to \u7528\u6237\u540d@\u767b\u5f55\u4e3b\u673a identified by \"\u5bc6\u7801\";<\/p>\n<p><strong>2.1 \u767b\u5f55MYSQL\uff08\u6709ROOT\u6743\u9650\uff09\uff0c\u8fd9\u91cc\u4ee5ROOT\u8eab\u4efd\u767b\u5f55\uff1a<\/strong><\/p>\n<p>@&gt;mysql -u root -p<\/p>\n<p>@&gt;\u5bc6\u7801<\/p>\n<p><strong>2.2 \u9996\u5148\u4e3a\u7528\u6237\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93(testDB)\uff1a<\/strong><\/p>\n<p>mysql&gt;create database testDB;<\/p>\n<p><strong>2.3 \u6388\u6743test\u7528\u6237\u62e5\u6709testDB\u6570\u636e\u5e93\u7684\u6240\u6709\u6743\u9650\uff08\u67d0\u4e2a\u6570\u636e\u5e93\u7684\u6240\u6709\u6743\u9650\uff09\uff1a<\/strong><\/p>\n<p>mysql&gt;grant all privileges on testDB.* to test@localhost identified by '1234';<\/p>\n<p>mysql&gt;flush privileges;\/\/\u5237\u65b0\u7cfb\u7edf\u6743\u9650\u8868<\/p>\n<p>\u683c\u5f0f\uff1agrant\u00a0\u6743\u9650 on \u6570\u636e\u5e93.* to \u7528\u6237\u540d@\u767b\u5f55\u4e3b\u673a identified by \"\u5bc6\u7801\";<\/p>\n<p><strong>2.4 \u5982\u679c\u60f3\u6307\u5b9a\u90e8\u5206\u6743\u9650\u7ed9\u4e00\u7528\u6237\uff0c\u53ef\u4ee5\u8fd9\u6837\u6765\u5199:<\/strong><\/p>\n<p>mysql&gt;grant select,update on testDB.* to test@localhost identified by '1234';<\/p>\n<p>mysql&gt;flush privileges; \/\/\u5237\u65b0\u7cfb\u7edf\u6743\u9650\u8868<\/p>\n<p><strong>2.5 \u6388\u6743test\u7528\u6237\u62e5\u6709\u6240\u6709\u6570\u636e\u5e93\u7684\u67d0\u4e9b\u6743\u9650\uff1a\u00a0\u3000\u00a0<\/strong><\/p>\n<p>mysql&gt;grant select,delete,update,create,drop on *.* to test@\"%\" identified by \"1234\";<\/p>\n<p>\/\/test\u7528\u6237\u5bf9\u6240\u6709\u6570\u636e\u5e93\u90fd\u6709select,delete,update,create,drop \u6743\u9650\u3002<\/p>\n<p>\/\/@\"%\" \u8868\u793a\u5bf9\u6240\u6709\u975e\u672c\u5730\u4e3b\u673a\u6388\u6743\uff0c\u4e0d\u5305\u62eclocalhost\u3002\uff08localhost\u5730\u5740\u8bbe\u4e3a127.0.0.1\uff0c\u5982\u679c\u8bbe\u4e3a\u771f\u5b9e\u7684\u672c\u5730\u5730\u5740\uff0c\u4e0d\u77e5\u9053\u662f\u5426\u53ef\u4ee5\uff0c\u6ca1\u6709\u9a8c\u8bc1\u3002\uff09<\/p>\n<p>\/\/\u5bf9localhost\u6388\u6743\uff1a\u52a0\u4e0a\u4e00\u53e5grant all privileges on testDB.* to test@localhost identified by '1234';\u5373\u53ef\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong>3. \u5220\u9664\u7528\u6237<\/strong><\/p>\n<p>@&gt;mysql -u root -p<\/p>\n<p>@&gt;\u5bc6\u7801<\/p>\n<p>mysql&gt;Delete FROM user Where User='test' and Host='localhost';<\/p>\n<p>mysql&gt;flush privileges;<\/p>\n<p>mysql&gt;drop database testDB; \/\/\u5220\u9664\u7528\u6237\u7684\u6570\u636e\u5e93<\/p>\n<p>\u5220\u9664\u8d26\u6237\u53ca\u6743\u9650\uff1a&gt;drop user \u7528\u6237\u540d@'%';<\/p>\n<p>&gt;drop user \u7528\u6237\u540d@\u00a0localhost;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>4. \u4fee\u6539\u6307\u5b9a\u7528\u6237\u5bc6\u7801<\/strong><\/p>\n<p>@&gt;mysql -u root -p<\/p>\n<p>@&gt;\u5bc6\u7801<\/p>\n<p>mysql&gt;update mysql.user set password=password('\u65b0\u5bc6\u7801') where User=\"test\" and Host=\"localhost\";<\/p>\n<p>mysql&gt;flush privileges;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>5. \u5217\u51fa\u6240\u6709\u6570\u636e\u5e93<\/strong><\/p>\n<p>mysql&gt;show database;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>6. \u5207\u6362\u6570\u636e\u5e93<\/strong><\/p>\n<p>mysql&gt;use '\u6570\u636e\u5e93\u540d';<\/p>\n<p>&nbsp;<\/p>\n<p><strong>7. \u5217\u51fa\u6240\u6709\u8868<\/strong><\/p>\n<p>mysql&gt;show tables;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>8. \u663e\u793a\u6570\u636e\u8868\u7ed3\u6784<\/strong><\/p>\n<p>mysql&gt;describe \u8868\u540d;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>9. \u5220\u9664\u6570\u636e\u5e93\u548c\u6570\u636e\u8868<\/strong><\/p>\n<p>mysql&gt;drop database \u6570\u636e\u5e93\u540d;<\/p>\n<p>mysql&gt;drop table \u6570\u636e\u8868\u540d;<\/p>\n<h4><strong>\u4e8c\u3001\u8fdc\u7a0b\u8fde\u63a5\u65b9\u6cd5\uff01<\/strong><\/h4>\n<p>1\uff0c\u521a\u5f00\u59cb\u6211\u4f7f\u7528\u7684\u662fNavicat for MySQL\u5de5\u5177\u8fde\u63a5\u8fdc\u7a0b\u7684mysql\u7684\u6570\u636e\u5e93\u3002<\/p>\n<p>\u62a5\u9519\u4e86\u3002\u62a5\u9519\u4fe1\u606f\u662f Error 1130: Host '192.168.1.80' is not allowed to connect to this MySQL server\u3002<\/p>\n<p>\u6211\u67e5\u8be2\u7f51\u4e0a\u7684\u89e3\u51b3\u65b9\u6cd5\u5171\u6709\u4e24\u79cd\uff1a<\/p>\n<p>a. \u8be5\u8868\u6cd5\u3002\u53ef\u80fd\u662f\u4f60\u7684\u8d26\u53f7\u4e0d\u5141\u8bb8\u4ece\u8fdc\u7a0b\u767b\u9646\uff0c\u53ea\u80fd\u5728localhost\u3002\u8fd9\u4e2a\u65f6\u5019\u53ea\u8981\u5728localhost\u7684\u90a3\u53f0\u7535\u8111\uff0c\u767b\u5f55mysql\u540e\uff0c\u66f4\u6539\u201cmysql\u201d\u6570\u636e\u5e93\u91cc\u7684'user'\u8868\u7684\"host\"\u9879\uff0c\u4ece\u201clocalhost\u201d\u6539\u79f0\u201c%\u201d<\/p>\n<p>b. \u6388\u6743\u6cd5\u3002\u5728mysql1.5.6\u81ea\u5e26\u7684\u547d\u4ee4\u5de5\u5177\u4e2d\u8f93\u5165\uff1a<\/p>\n<p>mysql&gt; grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;<br \/>\nmysql&gt; flush privileges;\/\/\u5237\u65b0\u4e00\u4e0b\u6743\u9650\uff0c\u4e0d\u9700\u8981\u91cd\u542fmysql<\/p>\n<p>\u4e0a\u9762\u6240\u4f7f\u7528\u7684\u65b9\u6cd5\uff0c\u8981\u5728\u88c5\u6709mysql\u90a3\u4e2a\u8fdc\u7a0b\u673a\u5668\u4e0a\u8fd0\u884c\u3002<\/p>\n<p>c\u3001\u4fee\u6539my.cnf\u914d\u7f6e\u6587\u4ef6<\/p>\n<p>\u8fd9\u4e2a\u662fmysql\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5982\u679c\u4f60\u65e0\u6807\u9898\u6587\u7ae0\u627e\u4e0d\u5230\u5728\u54ea\u91cc\u7684\u8bdd\uff0c\u53ef\u4ee5\u8f93\u5165find \/* -name my.cnf \u627e\u5230<\/p>\n<p>\u901a\u8fc7vim\u7f16\u8f91\u8be5\u6587\u4ef6\uff0c\u627e\u5230bind-address = 127.0.0.1\u8fd9\u4e00\u53e5\uff0c\u7136\u540e\u5728\u524d\u9762\u52a0\u4e2a#\u53f7\u6ce8\u91ca\u6389\uff0c\u4fdd\u5b58\u9000\u51fa<\/p>\n<p>d\u3001\u91cd\u542f\u670d\u52a1<\/p>\n<p align=\"left\">e\uff0c\u7136\u540e\u6211\u5728\u672c\u5730\u4f7f\u7528Navicat for MySQL\u5de5\u5177\u8fde\u63a5\u8fdc\u7a0b\u7684mysql\u6570\u636e\u5e93\u3002<\/p>\n<p align=\"left\">\u62a5\u9519\u4e86\u30022003 - Can't connect to MySQL server on '192.168.1.80'(10038)\u3002<\/p>\n<p align=\"left\">\u8fd9\u4e2a\u9519\u8bef\u5c31\u662f\u670d\u52a1\u5668\u7684\u9632\u706b\u5899\u62e6\u622a\u4e86\u60a8\u7684\u8fde\u63a5\u3002\u7136\u540e\u628a\u9632\u706b\u5899\u5173\u95ed\u4e4b\u540e\u5c31\u80fd\u8fde\u63a5\u4e0a\u4e86\u3002<\/p>\n<p align=\"left\">\n<p>\u8f6c\u81ea\uff1ahttp:\/\/www.jianshu.com\/p\/c76b31df5d09<br \/>\n\u9996\u5148\u5220\u9664mysql:root\u6743\u9650\u4e0b<br \/>\napt-get remove mysql-*<br \/>\n\u7136\u540e\u6e05\u7406\u6b8b\u7559\u7684\u6570\u636e<\/p>\n<p>dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P<\/p>\n<p>\u5b83\u4f1a\u8df3\u51fa\u4e00\u4e2a\u5bf9\u8bdd\u6846\uff0c\u4f60\u9009\u62e9yes\u5c31\u597d\u4e86<br \/>\n\u7136\u540e\u5b89\u88c5mysql<br \/>\nsudo apt-get install mysql-client mysql-server<br \/>\n\u5b89\u88c5\u7684\u65f6\u5019\u4f1a\u63d0\u793a\u8981\u8bbe\u7f6eroot\u5bc6\u7801\uff0c\u5982\u679c\u4f60\u6ca1\u6709\u5728\u5378\u8f7d\u7684\u65f6\u5019\u53bb\u6e05\u7406\u6b8b\u7559\u6570\u636e\u662f\u4e0d\u4f1a\u63d0\u793a\u4f60\u53bb\u8bbe\u7f6eroot\u5bc6\u7801\u7684<br \/>\n\u68c0\u67e5mysql\u662f\u4e0d\u662f\u5728\u8fd0\u884c<br \/>\nservice mysql status<br \/>\n\u4e00\u822c\u5b89\u88c5\u5b8c\u6210\u4e4b\u540e\u90fd\u662f\u4f1a\u81ea\u52a8\u8fd0\u884c\u7684\u3002<br \/>\n\u5982\u679c\u6ca1\u6709\u8fd0\u884c\u4f60\u53ef\u4ee5<br \/>\nservice mysql start<\/p>\n<p>\u8fd0\u884c\u5b83<\/p>\n","protected":false},"excerpt":{"rendered":"<p>linux mysql \u5fd8\u8bb0root\u7684\u5bc6\u7801\u65e0\u6cd5\u767b\u9646\u8fdbmysql 1\u3001\u4fee\u6539MySQL\u7684\u914d\u7f6e\u6587\u4ef6\/etc\/my.c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[18,19],"_links":{"self":[{"href":"https:\/\/kkong.net\/index.php?rest_route=\/wp\/v2\/posts\/27"}],"collection":[{"href":"https:\/\/kkong.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kkong.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kkong.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kkong.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=27"}],"version-history":[{"count":5,"href":"https:\/\/kkong.net\/index.php?rest_route=\/wp\/v2\/posts\/27\/revisions"}],"predecessor-version":[{"id":165,"href":"https:\/\/kkong.net\/index.php?rest_route=\/wp\/v2\/posts\/27\/revisions\/165"}],"wp:attachment":[{"href":"https:\/\/kkong.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kkong.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kkong.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}