{"id":52123,"date":"2024-12-03T14:18:09","date_gmt":"2024-12-03T06:18:09","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52123\/"},"modified":"2024-12-03T14:18:09","modified_gmt":"2024-12-03T06:18:09","slug":"linux%e5%a6%82%e4%bd%95%e8%bf%90%e8%a1%8csql%e6%96%87%e4%bb%b6%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52123\/","title":{"rendered":"linux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>linux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4<\/h1>\n<p>\u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300alinux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<\/p>\n<blockquote>\n<p>linux\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u662f\u201cpsql -f test.sql\u201d\uff0c\u5176Linux\u8fd0\u884csql\u811a\u672c\u7684\u65b9\u6cd5\u662f\uff1a1\u3001\u4f7f\u7528shell\u5de5\u5177\u767b\u5f55\u5230\u5b89\u88c5postgresql\u7684\u670d\u52a1\u5668\uff1b2\u3001\u7f16\u8f91sql\u811a\u672c\u5185\u5bb9\uff1b3\u3001\u901a\u8fc7\u201cpsql -f test.sql\u201d\u547d\u4ee4\u6267\u884c\u201ctest.sql\u201d\u811a\u672c\u5373\u53ef\u3002<\/p>\n<\/blockquote>\n<p>Linux\u8fd0\u884csql\u811a\u672c\u7684\u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<p>1\u3001\u4f7f\u7528shell\u5de5\u5177\u767b\u9646\u5230\u5b89\u88c5postgresql\u7684\u670d\u52a1\u5668\uff0c\u5207\u6362\u5230postgres\u7528\u6237\uff0cpostgresql\u9ed8\u8ba4\u7684\u64cd\u4f5c\u7528\u6237\uff0c\u547d\u4ee4\u662f\uff1asu &#8211; postgres\uff0c\u67e5\u770b\u5f53\u524d\u8def\u5f84\u662f\/var\/lib\/psql\uff0c\u521b\u5efa\u4e00\u4e2atest.sql\u811a\u672c\u6587\u4ef6\uff0c\u547d\u4ee4\u662f\uff1avim test.sql\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240411\/17128391656617d9fdd064c.jpg\" class=\"aligncenter\" title=\"linux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u63d2\u56fe\" alt=\"linux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u63d2\u56fe\" \/><\/p>\n<p>2\u3001sql\u811a\u672c\u5185\u5bb9\u662f\uff1acreate table test (id int not null primary key,name text);insert into test valus(1, &#8216;t1&#8217;);<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240411\/17128391656617d9fdd3543.jpg\" class=\"aligncenter\" title=\"linux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u63d2\u56fe1\" alt=\"linux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u63d2\u56fe1\" \/><\/p>\n<p>3\u3001\u6267\u884ctest.sql\u811a\u672c\uff0c\u547d\u4ee4\u662f\uff1apsql -f test.sql<\/p>\n<p>\u8fd9\u91cc\u662f\u56e0\u4e3apostgresql\u5b89\u88c5\u672c\u673a\u4e0a\uff0c\u5728\u7b2c\u4e00\u6b65\u4e2d\u6211\u4eec\u5207\u6362\u5230\u4e86postgres\u7528\u6237\uff0c\u56e0\u6b64\u8fd9\u91cc\u9ed8\u8ba4\u5c31\u662fpostgres\u7528\u6237\u6765\u64cd\u4f5c\uff0c\u4e0d\u7528\u5e26\u4e0a\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002\u6267\u884c\u7ed3\u679c\u5982\u4e0b\uff0c\u53ef\u4ee5\u770b\u5230\u6709\u4e24\u4e2a\u63d0\u793a\uff1a<\/p>\n<p>create table<\/p>\n<p>insert 0 1<\/p>\n<p>\u6267\u884c\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u767b\u5165\u6570\u636e\u5e93\uff0c\u547d\u4ee4\u662f\uff1apsql<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240411\/17128391656617d9fdd47e7.jpg\" class=\"aligncenter\" title=\"linux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u63d2\u56fe2\" alt=\"linux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u63d2\u56fe2\" \/><\/p>\n<p>4\u3001\u8fdb\u5165psql\u4ea4\u4e92\u5f0f\u547d\u4ee4\u884c\u540e\uff0c\u6211\u4eec\u6267\u884c\u4e24\u4e2a\u67e5\u770b\u547d\u4ee4\uff1a\\d<\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u8868test\u786e\u5b9e\u5df2\u7ecf\u521b\u5efa\u6210\u529f\uff0c\u7136\u540e\u6267\u884c\u547d\u4ee4\uff1a\\d test<\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u8868\u4e2d\u5b57\u6bb5\u662fid\u548cname\uff0c\u548c\u6211\u4eec\u521b\u5efa\u8bed\u53e5\u4e2d\u5185\u5bb9\u4e00\u6837\uff0c\u8bf4\u660e\u7b2c\u4e00\u6761\u8bed\u53e5\u6267\u884c\u6210\u529f\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240411\/17128391656617d9fdd5cbc.jpg\" class=\"aligncenter\" title=\"linux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u63d2\u56fe3\" alt=\"linux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u63d2\u56fe3\" \/><\/p>\n<p>5\u3001\u67e5\u770b\u8868\u4e2d\u6570\u636e\uff0c\u547d\u4ee4\u662f\uff1aselect * from test;<\/p>\n<p>\u663e\u793a\u51fa\u6765\u7684\u503c\u662f1\uff0ct1\uff0c\u8bf4\u660e\u7b2c\u4e8c\u6761\u6267\u884c\u8bed\u53e5\u4e5f\u6267\u884c\u6210\u529f\uff0c\u8bf4\u660etest.sql\u811a\u672c\u6267\u884c\u6210\u529f\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240411\/17128391656617d9fdd8d1d.jpg\" class=\"aligncenter\" title=\"linux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u63d2\u56fe4\" alt=\"linux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u63d2\u56fe4\" \/><\/p>\n<p>6\u3001\u9ed8\u8ba4\u662fpostgres\u7528\u6237\uff0c\u672c\u673a\u64cd\u4f5c\u662f\uff0c\u4e0d\u9700\u8981\u7528\u6237\u548c\u5bc6\u7801\uff0c\u73b0\u5728\u6211\u4eec\u6765\u8bd5\u8bd5\u64cd\u4f5c\u8fdc\u7a0blinux\u670d\u52a1\u5668\u4e0a\u7684postgresql\uff0c\u4e5f\u5c31\u662f\u8bf4\u6267\u884c\u672c\u5730\u7684\u811a\u672c\u6587\u4ef6\uff0c\u5728\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u521b\u5efa\u8868\u3002\u5982\u4e0b\u9762\u56fe\u4e2d\u6240\u793a\uff0c\u547d\u4ee4\u662f\uff1apsql -U test1 -h 192.168.1.194 -f test.sql\uff0c\u8f93\u5165\u5bf9\u5e94\u7528\u6237\u7684\u5bc6\u7801\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240411\/17128391656617d9fdda0e3.jpg\" class=\"aligncenter\" title=\"linux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u63d2\u56fe5\" alt=\"linux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u63d2\u56fe5\" \/><\/p>\n<p>7\u3001\u767b\u9646\u5230\u8fd9\u4e2a\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\uff0c\u547d\u4ee4\u662f\uff1apsql -U test -h 192.168.194<\/p>\n<p>\u6267\u884c\u67e5\u770b\u547d\u4ee4\uff1a\\d\uff0c\\d test<\/p>\n<p>\u6700\u540e\u67e5\u8be2\u6570\u636e\u5e93\uff1aselect * from test;\u7ed3\u679c\u548c\u4e0a\u9762\u90fd\u4e00\u81f4\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240411\/17128391656617d9fddb356.jpg\" class=\"aligncenter\" title=\"linux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u63d2\u56fe6\" alt=\"linux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u63d2\u56fe6\" \/><\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300alinux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>linux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4 \u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300alinux\u5982\u4f55\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 linux\u8fd0\u884csql\u6587\u4ef6\u547d\u4ee4\u662f\u201cpsql -f test.sql\u201d\uff0c\u5176Linux\u8fd0\u884csql\u811a\u672c\u7684\u65b9\u6cd5\u662f\uff1a1\u3001\u4f7f\u7528shell\u5de5\u5177\u767b\u5f55\u5230\u5b89\u88c5postgresql\u7684\u670d\u52a1\u5668\uff1b2\u3001\u7f16\u8f91sql\u811a\u672c\u5185\u5bb9\uff1b3\u3001\u901a\u8fc7\u201cpsql -f test.sql\u201d\u547d\u4ee4\u6267\u884c\u201ctest.sql\u201d\u811a\u672c\u5373\u53ef\u3002 Linux\u8fd0\u884csql\u811a\u672c\u7684\u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4\u5982\u4e0b\uff1a 1\u3001\u4f7f\u7528shell\u5de5\u5177\u767b\u9646\u5230\u5b89\u88c5postgresql\u7684\u670d\u52a1\u5668\uff0c\u5207\u6362\u5230postgres\u7528\u6237\uff0cpostgresql\u9ed8\u8ba4\u7684\u64cd\u4f5c\u7528\u6237\uff0c\u547d\u4ee4\u662f\uff1asu &#8211; postgres\uff0c\u67e5\u770b\u5f53\u524d\u8def\u5f84\u662f\/var\/lib\/psql\uff0c\u521b\u5efa\u4e00\u4e2atest.sql\u811a\u672c\u6587\u4ef6\uff0c\u547d\u4ee4\u662f\uff1avim test.sql\u3002 2\u3001sql\u811a\u672c\u5185\u5bb9\u662f\uff1acreate table test (id int not null primary key,name text);insert into test valus(1, &#8216;t1&#8217;); 3\u3001\u6267\u884ctest.sql\u811a\u672c\uff0c\u547d\u4ee4\u662f\uff1apsql -f test.sql \u8fd9\u91cc\u662f\u56e0\u4e3apostgresql\u5b89\u88c5\u672c\u673a\u4e0a\uff0c\u5728\u7b2c\u4e00\u6b65\u4e2d\u6211\u4eec\u5207\u6362\u5230\u4e86postgres\u7528\u6237\uff0c\u56e0\u6b64\u8fd9\u91cc\u9ed8\u8ba4\u5c31\u662fpostgres\u7528\u6237\u6765\u64cd\u4f5c\uff0c\u4e0d\u7528\u5e26\u4e0a\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002\u6267\u884c\u7ed3\u679c\u5982\u4e0b\uff0c\u53ef\u4ee5\u770b\u5230\u6709\u4e24\u4e2a\u63d0\u793a\uff1a create table insert 0 1 \u6267\u884c\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u767b\u5165\u6570\u636e\u5e93\uff0c\u547d\u4ee4\u662f\uff1apsql 4\u3001\u8fdb\u5165psql\u4ea4\u4e92\u5f0f\u547d\u4ee4\u884c\u540e\uff0c\u6211\u4eec\u6267\u884c\u4e24\u4e2a\u67e5\u770b\u547d\u4ee4\uff1a\\d \u53ef\u4ee5\u770b\u5230\u8868test\u786e\u5b9e\u5df2\u7ecf\u521b\u5efa\u6210\u529f\uff0c\u7136\u540e\u6267\u884c\u547d\u4ee4\uff1a\\d test \u53ef\u4ee5\u770b\u5230\u8868\u4e2d\u5b57\u6bb5\u662fid\u548cname\uff0c\u548c\u6211\u4eec\u521b\u5efa\u8bed\u53e5\u4e2d\u5185\u5bb9\u4e00\u6837\uff0c\u8bf4\u660e\u7b2c\u4e00\u6761\u8bed\u53e5\u6267\u884c\u6210\u529f\u3002 5\u3001\u67e5\u770b\u8868\u4e2d\u6570\u636e\uff0c\u547d\u4ee4\u662f\uff1aselect * from test; \u663e\u793a\u51fa\u6765\u7684\u503c\u662f1\uff0ct1\uff0c\u8bf4\u660e\u7b2c\u4e8c\u6761\u6267\u884c\u8bed\u53e5\u4e5f\u6267\u884c\u6210\u529f\uff0c\u8bf4\u660etest.sql\u811a\u672c\u6267\u884c\u6210\u529f\u3002 6\u3001\u9ed8\u8ba4\u662fpostgres\u7528\u6237\uff0c\u672c\u673a\u64cd\u4f5c\u662f\uff0c\u4e0d\u9700\u8981\u7528\u6237\u548c\u5bc6\u7801\uff0c\u73b0\u5728\u6211\u4eec\u6765\u8bd5\u8bd5\u64cd\u4f5c\u8fdc\u7a0blinux\u670d\u52a1\u5668\u4e0a\u7684postgresql\uff0c\u4e5f\u5c31\u662f\u8bf4\u6267\u884c\u672c\u5730\u7684\u811a\u672c\u6587\u4ef6\uff0c\u5728\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u521b\u5efa\u8868\u3002\u5982\u4e0b\u9762\u56fe\u4e2d\u6240\u793a\uff0c\u547d\u4ee4\u662f\uff1apsql -U test1 -h 192.168.1.194 -f test.sql\uff0c\u8f93\u5165\u5bf9\u5e94\u7528\u6237\u7684\u5bc6\u7801\u3002 7\u3001\u767b\u9646\u5230\u8fd9\u4e2a\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\uff0c\u547d\u4ee4\u662f\uff1apsql -U test [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-52123","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=52123"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52123\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}