{"id":551,"date":"2014-07-11T14:29:16","date_gmt":"2014-07-11T14:29:16","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=551"},"modified":"2014-07-11T14:29:16","modified_gmt":"2014-07-11T14:29:16","slug":"%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e7%9a%84%e8%a1%a8%e5%90%8d%e3%80%81%e5%ba%93%e5%90%8d%e7%ad%89%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/551.html","title":{"rendered":"\u5982\u4f55\u4fee\u6539MySQL\u6570\u636e\u5e93\u7684\u8868\u540d\u3001\u5e93\u540d\u7b49\u4fe1\u606f"},"content":{"rendered":"<p>\u4e4b\u524d\u56e0\u4e3a\u81ea\u5df1\u7684\u4e00\u4e9b\u5931\u8bef\u5bfc\u81f4\u67d0\u4e9b\u914d\u7f6e\u6587\u4ef6\u53ef\u88ab\u76f4\u63a5\u4e0b\u8f7d\uff08\u540e\u6765\u901a\u8fc7\u6392\u67e5nginx\u7684\u65e5\u5fd7\u6587\u4ef6\u540e\u53d1\u73b0\u8fd8\u6ca1\u6709\u5bfc\u81f4\u4fe1\u606f\u6cc4\u9732\uff0c\u4e0d\u8fc7\u4e5f\u7ed9\u6211\u63d0\u4e86\u4e2a\u9192\uff0c\u4ee5\u540e\u5728\u7f16\u8f91\u6587\u4ef6\u7684\u65f6\u5019\u5f97\u6ce8\u610f\uff0c\u5907\u4efd\u6587\u4ef6\u7684\u65b9\u6cd5\u548c\u65b9\u5f0f\u9700\u8981\u8003\u8651\u5f97\u66f4\u5168\u9762\uff0c\u5728\u65b0\u529f\u80fd\u4e0a\u7ebf\u4e4b\u524d\u81ea\u5df1\u4e00\u5b9a\u8981\u597d\u597d\u68c0\u67e5\u4e4b\u540e\u518d\u53d1\u5e03\u51fa\u6765\uff09\u3002<\/p>\n<h5>1.MySQL\u4fee\u6539\u5bc6\u7801<\/h5>\n<p>$ mysql -uroot -p<br \/>\n&#8230;<br \/>\nmysql&gt; select Host,User,Password from mysql.user;<br \/>\nmysql&gt; update mysql.user set Password=password(&#8216;new_password&#8217;) WHERE User=&#8217;acer&#8217;;<br \/>\nmysql&gt; FLUSH PRIVILEGES;<\/p>\n<h5>2.\u4fee\u6539MySQL\u7528\u6237\u540d\uff1a<\/h5>\n<p>mysql&gt; use mysql;<br \/>\nmysql&gt; update user set user=&#8221;\u65b0\u7528\u6237\u540d&#8221; where user=&#8221;\u65e7\u7528\u6237\u540d&#8221;;<br \/>\nmysql&gt; flush privileges;<br \/>\nmysql&gt; exit<\/p>\n<h5>3.\u4fee\u6539MySQL\u6570\u636e\u5e93\u7684\u8868\u540d\uff1a<\/h5>\n<p>\u8fd0\u884c\u547d\u4ee4\uff1a<br \/>\nALTER TABLE \u539f\u8868\u540d RENAME TO \u65b0\u8868\u540d;<br \/>\n\u5982\uff1a<br \/>\nALTER TABLE old_post RENAME TO new_post;<\/p>\n<h5>4.\u4fee\u6539MySQL\u6307\u5b9a\u6570\u636e\u5e93\u540d\u7684\u65b9\u6cd5\uff1a<\/h5>\n<p>\u5047\u8bbe\u6e90\u5e93\u540d\u662f &#8220;srcDB&#8221;\uff0c\u76ee\u6807\u5e93\u540d\u662f &#8220;targetDB&#8221;<br \/>\n\u9996\u5148\u521b\u5efa\u76ee\u6807\u5e93\uff1a<br \/>\ncreate database targetDB;<br \/>\n\u83b7\u53d6\u6240\u6709\u6e90\u5e93\u7684\u8868\u540d\uff1a<br \/>\nuse information_schema;<br \/>\nselect table_name from TABLES where TABLE_SCHEMA=&#8217;srcDB&#8217;;<br \/>\n\u7136\u540e\u6309\u7167\u4ee5\u4e0b\u547d\u4ee4\u4e00\u4e2a\u4e2a\u4fee\u6539\uff1a<br \/>\nrename table srcDB.[tablename] to targetDB.[tablename];<br \/>\n\u4e00\u4e2a\u4e2a\u6267\u884c\u4e0b\u6765\u4e4b\u540e\u8868\u5c31\u8f6c\u5230\u65b0\u7684\u5e93\u91cc\u9762\u4e86\u3002<\/p>\n<h5>5.MySQL\u4fee\u6539\u6570\u636e\u5e93\u540d\u79f0\u7684\u65b9\u6cd5\u603b\u7ed3<\/h5>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/67093\/how-do-i-quickly-rename-a-mysql-database-change-schema-name\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/67093\/how-do-i-quickly-rename-a-mysql-database-change-schema-name<\/a><br \/>\n\u4e0a\u9762\u8fd9\u4e2astackoverflow\u4e2d\u4ecb\u7ecd\u4e86\u591a\u79cd\u5b9e\u9645\u53ef\u884c\u7684\u65b9\u6cd5\uff0c\u8d85\u7ed9\u529b\uff01<\/p>\n<p>&#8212;&#8211;<\/p>\n<div>\n<div><span style=\"color: #0000ff; font-family: \u5b8b\u4f53; font-size: large;\"><strong>Windows7\u4e0bMySQL5.6\u5fd8\u8bb0root\u5bc6\u7801<\/strong><\/span><\/div>\n<div>\u4ee5\u4e0b\u6b65\u9aa4\u5982\u679c\u6dfb\u52a0\u4e86MySQL\u7684\u73af\u5883\u53d8\u91cf\uff0c\u5219\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884cmysql\u6709\u5173\u547d\u4ee4\uff0c\u5426\u5219\u5fc5\u987b\u5230mysql\u5b89\u88c5\u76ee\u5f55\u7684bin\u76ee\u5f55\u4e0b\u64cd\u4f5c\u3002<br \/>\n\u6b65\u9aa4\u5982\u4e0b\uff1a<br \/>\n1.\u505c\u6b62mysql\u670d\u52a1\u3002<\/div>\n<div><span style=\"color: #000000; font-family: \u5b8b\u4f53; font-size: medium;\">2.[<strong><span style=\"color: #ff0000;\">\u4ee5\u7ba1\u7406\u5458\u8eab\u4efd\u6267\u884c\u547d\u4ee4<\/span><\/strong>]\u4f7f\u7528\u00a0mysqld\u00a0&#8211;skip-grant-tables\u00a0\u547d\u4ee4\u542f\u52a8mysql\u6570\u636e\u5e93\u3002<\/span><\/div>\n<div><span style=\"color: #000000; font-size: medium;\">3.<strong>\u65b0\u6253\u5f00\u4e00\u4e2aCMD\u7a97\u53e3<\/strong>\uff0c\u8fdb\u884c\u5982\u4e0b\u64cd\u4f5c\uff1a<\/span><\/div>\n<div>C:WindowsSystem32&gt;<span style=\"color: #ff0000;\"><strong>mysql -u root<\/strong><\/span><br \/>\nWelcome to the MySQL monitor.\u00a0 Commands end with ; or g.<br \/>\nYour MySQL connection id is 4<br \/>\nServer version: 5.6.15 MySQL Community Server (GPL)<\/div>\n<div><\/div>\n<div>Copyright (c) 2000, 2013, Oracle and\/or its affiliates. All rights reserved.<\/div>\n<div><\/div>\n<div>Oracle is a registered trademark of Oracle Corporation and\/or its<br \/>\naffiliates. Other names may be trademarks of their respective<br \/>\nowners.<\/div>\n<div><\/div>\n<div>Type &#8216;help;&#8217; or &#8216;h&#8217; for help. Type &#8216;c&#8217; to clear the current input statement.<\/div>\n<div><\/div>\n<div>mysql&gt; update mysql.user set password=password(&#8216;new_password&#8217;) where user=&#8217;root&#8217;;<br \/>\nQuery OK, 0 rows affected (0.00 sec)<br \/>\nRows matched: 3\u00a0 Changed: 0\u00a0 Warnings: 0<\/div>\n<div><\/div>\n<div>mysql&gt; flush privileges;<br \/>\nQuery OK, 0 rows affected (0.05 sec)<\/div>\n<div><\/div>\n<div>\u56e0\u4e3a\u6267\u884c\u8fc7\u547d\u4ee4\u201cmysqld\u00a0&#8211;skip-grant-tables\u201d\uff0c\u6240\u4ee5\u73b0\u5728\u4efb\u4f55\u4eba\u90fd\u53ef\u4ee5\u76f4\u63a5\u5728CMD\u7a97\u53e3\u4e2d\u8f93\u5165\u201cmysql\u201d\u547d\u4ee4\u76f4\u63a5\u767b\u5f55\uff0c\u65e0\u9700\u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1\uff0c\u5982\u4f55\u89e3\u51b3\uff1f<\/div>\n<div>\u5176\u5b9e\u90fd\u4e0d\u7528\u7ba1\u7684\uff0c\u76f4\u63a5\u5728\u4efb\u52a1\u7ba1\u7406\u5668\u4e2d\u505c\u6389mysqld.exe\u8fd9\u4e2a\u8fdb\u7a0b\u5373\u53ef\uff0c\u5982\u679c\u9700\u8981\u6bcf\u6b21\u542f\u52a8MySQL\u7684\u65f6\u5019\u90fd\u4e0d\u7528\u8f93\u5165\u5bc6\u7801\uff0c\u5219\u53ef\u53c2\u8003\u4e0b\u9762\u7684\u6587\u7ae0\u8fdb\u884c\u914d\u7f6e\uff08\u7f16\u8f91my.ini\u6587\u4ef6\u5185\u5bb9\u5373\u53ef\uff09<\/div>\n<div><\/div>\n<div>\u53c2\u8003\u6587\u7ae0\uff1a<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/resetting-permissions.html\" target=\"_blank\">http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/resetting-permissions.html<\/a><\/div>\n<\/div>\n<div><span style=\"color: #000000; font-size: medium;\">UPDATE mysql.user SET Password=PASSWORD(&#8216;MyNewPass&#8217;) WHERE User=&#8217;root&#8217;;<br \/>\nFLUSH PRIVILEGES;<br \/>\n<\/span><\/div>\n<div>&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/div>\n<div>\u4e0b\u9762\u662f\u4ece\u00a0<a href=\"http:\/\/www.51php.com\/mysql\/7967.html\" target=\"_blank\">http:\/\/www.51php.com\/mysql\/7967.html<\/a>\u00a0\u90a3\u91cc\u627e\u5230\u7684\u6279\u91cf\u4fee\u6539MySQL\u6570\u636e\u5e93\u8868\u524d\u7f00\u7684PHP\u4ee3\u7801\uff08\u8fd9\u5bf9\u4e8e\u6709\u5927\u91cf\u8868\u524d\u7f00\u9700\u8981\u4fee\u6539\u7684\u6570\u636e\u5e93\u6765\u8bf4\u662f\u4e2a\u5f88\u5927\u7684\u5e2e\u52a9\uff01\uff09\uff1a<\/div>\n<div>\n<pre class=\"lang:default decode:true \">&lt;?php\n$dbserver='localhost';\/\/\u8fde\u63a5\u7684\u670d\u52a1\u5668\u4e00\u822c\u4e3alocalhost\n$dbname='your_DBname';\/\/\u6570\u636e\u5e93\u540d\n$dbuser='UserName';\/\/\u6570\u636e\u5e93\u7528\u6237\u540d\n$dbpassword='UserPass';\/\/\u6570\u636e\u5e93\u5bc6\u7801\n$old_prefix='ecs_';\/\/\u6570\u636e\u5e93\u7684\u524d\u7f00\n$new_prefix='new__';\/\/\u6570\u636e\u5e93\u7684\u524d\u7f00\u4fee\u6539\u4e3a\nif ( !is_string($dbname) || !is_string($old_prefix)|| !is_string($new_prefix) ){\n\treturn false;\n}\nif (!mysql_connect($dbserver, $dbuser, $dbpassword)) {\n\tprint 'Could not connect to mysql';\n\texit;\n}\n\/\/\u53d6\u5f97\u6570\u636e\u5e93\u5185\u6240\u6709\u7684\u8868\u540d\n$result = mysql_list_tables($dbname);\t\/\/ This extension is deprecated as of PHP 5.5.0, and will be removed in the future.\nif (!$result) {\n\tprint \"DB Error, could not list tablesn\";\n\tprint 'MySQL Error: ' . mysql_error();\n\texit;\n}\n\/\/\u628a\u8868\u540d\u5b58\u8fdb$data\u6570\u7ec4\nwhile ($row = mysql_fetch_row($result)) {\n\t$data[] = $row[0];\n}\n\/\/\u8fc7\u6ee4\u8981\u4fee\u6539\u524d\u7f00\u7684\u8868\u540d\nforeach($data as $k =&gt; $v) {\n\t$preg = preg_match(\"\/^($old_prefix{1})([a-zA-Z0-9_-]+)\/i\", $v, $v1);\n\tif($preg){\n\t\t$tab_name[$k] = $v1[2];\n\t\t\/\/$tab_name[$k] = str_replace($old_prefix, '', $v);\n\t}\n}\nif($preg) {\n\t\/\/ echo '&lt;pre&gt;';\n\t\/\/ print_r($tab_name);\n\t\/\/ exit();\n\t\/\/ \u6279\u91cf\u91cd\u547d\u540d\n\tforeach($tab_name as $k =&gt; $v){\n\t\t$sql = 'RENAME TABLE `'.$old_prefix.$v.'` TO `'.$new_prefix.$v.'`';\n\t\tmysql_query($sql);\n\t}\n\tprint \"\u6570\u636e\u8868\u524d\u7f00\uff1a\".$old_prefix.\"&lt;br&gt;\u5df2\u7ecf\u4fee\u6539\u4e3a\uff1a\".$new_prefix.\"&lt;br&gt;\";\n} else { print \"\u60a8\u7684\u6570\u636e\u5e93\u8868\u7684\u524d\u7f00 \".$old_prefix.\" \u8f93\u5165\u9519\u8bef\u3002\u8bf7\u68c0\u67e5\u76f8\u5173\u7684\u6570\u636e\u5e93\u8868\u7684\u524d\u7f00\";\n\tif ( mysql_free_result($result) ) {\n\t\treturn true;\n\t}\n}\n?&gt;<\/pre>\n<p>\u4e0d\u8fc7\u9700\u8981\u6ce8\u610f\u7684\u4e00\u70b9\u5c31\u662f\uff1amysql_list_tables()\u8fd9\u4e2a\u6269\u5c55\u5728PHP5.5\u4ee5\u540e\u7684\u7248\u672c\u4e2d\u5df2\u7ecf\u88ab\u5f03\u7528\u4e86\uff0c\u6240\u4ee5\u8fd9\u4e2a\u811a\u672c\u4e0d\u652f\u6301PHP5.5\u53ca\u4ee5\u540e\u7684\u7248\u672c\uff0c\u8fd9\u65f6\u4f60\u53ef\u4ee5\u901a\u8fc7\u4e4b\u524d\u7ed9\u51fa\u7684stackoverflow\u7684\u90a3\u4e2a\u94fe\u63a5\u627e\u5230\u9002\u5408\u4f60\u81ea\u5df1\u7684\u65b9\u6cd5\u3002<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u56e0\u4e3a\u81ea\u5df1\u7684\u4e00\u4e9b\u5931\u8bef\u5bfc\u81f4\u67d0\u4e9b\u914d\u7f6e\u6587\u4ef6\u53ef\u88ab\u76f4\u63a5\u4e0b\u8f7d\uff08\u540e\u6765\u901a\u8fc7\u6392\u67e5nginx\u7684\u65e5\u5fd7\u6587\u4ef6\u540e\u53d1\u73b0\u8fd8\u6ca1\u6709\u5bfc\u81f4\u4fe1\u606f\u6cc4\u9732\uff0c [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,23],"tags":[16],"class_list":["post-551","post","type-post","status-publish","format-standard","hentry","category-database","category-knowledgebase-2","tag-mysql"],"views":4007,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=551"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/551\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}