{"id":4078,"date":"2012-10-18T08:52:27","date_gmt":"2012-10-18T00:52:27","guid":{"rendered":"http:\/\/jpuyy.com\/?p=4078"},"modified":"2015-11-25T16:37:16","modified_gmt":"2015-11-25T08:37:16","slug":"bash-create-mysql-database","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=4078","title":{"rendered":"bash\u521b\u5efamysql\u6570\u636e\u5e93\u811a\u672c"},"content":{"rendered":"<p>\u9700\u8981<code>\u6279\u91cf\u521b\u5efa\u6570\u636e\u5e93\u53ca\u6570\u636e\u5e93\u5bf9\u5e94\u7528\u6237<\/code>\uff0c\u5199\u4e86\u4e00\u4e2a\u5bf9\u4e8emysql\u7684\u6267\u884c\u811a\u672c\u3002<\/p>\n<pre>#!\/bin\/bash\r\n #\u7528\u6cd5\uff1a\u5c06\u6570\u636e\u5e93\u540d\/\u7528\u6237\u540d\u7528:\u5206\u9694\u5f00\uff0c\u6bcf\u4e2a\u4e00\u884c\uff0c\u5199\u5165\u4e00\u4e2a\u6587\u4ef6\uff0c\u6267\u884c\u811a\u672c+\u6587\u4ef6\u540d\uff0c\u53ef\u521b\u5efa\u6570\u636e\u5e93\uff0c\u5e76\u4e3a\u5176\u5206\u914d\u540c\u540d\u7528\u6237\r\n IFS=:\r\n while read dbname dbpassword\r\n do\r\n sql_user='root'\r\n sql_pass='root'\r\n mysql -u $sql_user -p$sql_pass -s &lt;&lt;EOT\r\n create database if not exists $dbname default charset utf8 collate utf8_general_ci;\r\n QUIT\r\n EOT\r\n mysql -u $sql_user -p$sql_pass -s &lt;&lt; EOF\r\n insert into mysql.user (Host,User,Password) values (\"localhost\",\"$dbname\",PASSWORD(\"$dbpassword\"));\r\n flush privileges;\r\n grant all on $dbname.* to $dbname@localhost;\r\n flush privileges;\r\n QUIT\r\n EOF\r\ndone &lt; $1<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u8981\u6279\u91cf\u521b\u5efa\u6570\u636e\u5e93\u53ca\u6570\u636e\u5e93\u5bf9\u5e94\u7528\u6237\uff0c\u5199\u4e86\u4e00\u4e2a\u5bf9\u4e8emysql\u7684\u6267\u884c\u811a\u672c\u3002 #!\/bin\/bash #\u7528\u6cd5\uff1a\u5c06\u6570\u636e\u5e93\u540d\/\u7528\u6237\u540d\u7528:\u5206\u9694\u5f00\uff0c\u6bcf\u4e2a\u4e00\u884c\uff0c\u5199\u5165\u4e00\u4e2a\u6587\u4ef6\uff0c\u6267\u884c\u811a\u672c+\u6587\u4ef6\u540d\uff0c\u53ef\u521b\u5efa\u6570\u636e\u5e93\uff0c\u5e76\u4e3a\u5176\u5206\u914d\u540c\u540d\u7528\u6237 IFS=: while read dbname dbpassword do sql_user=&#8217;root&#8217; sql_pass=&#8217;root&#8217; mysql -u $sql_user -p$sql_pass -s &lt;&lt;EOT create database if not exists $dbname default charset utf8 collate utf8_general_ci; QUIT EOT mysql -u $sql_user -p$sql_pass -s &lt;&lt; EOF insert into mysql.user (Host,User,Password) values (&#8220;localhost&#8221;,&#8221;$dbname&#8221;,PASSWORD(&#8220;$dbpassword&#8221;)); flush privileges; grant all on $dbname.* to $dbname@localhost; flush privileges; QUIT EOF [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-4078","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/4078","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4078"}],"version-history":[{"count":12,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/4078\/revisions"}],"predecessor-version":[{"id":7613,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/4078\/revisions\/7613"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4078"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4078"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4078"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}