{"id":230478,"date":"2021-11-23T08:19:59","date_gmt":"2021-11-23T00:19:59","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=230478"},"modified":"2021-11-19T11:20:49","modified_gmt":"2021-11-19T03:20:49","slug":"sqlite-basic-cmd","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/sqlite-basic-cmd.html","title":{"rendered":"SQLite \u57fa\u672c\u547d\u4ee4\u4f7f\u7528\u65b9\u5f0f"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u672c\u6587\u4ecb\u7ecd\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u6570\u636e\u5e93\uff0c\u5e76\u80fd\u591f\u5728\u9700\u8981\u7684\u65f6\u95f4\u548c\u5730\u70b9\u5feb\u901f\u4f7f\u7528\u5b83\u4eec\u3002SQLite \u5728\u4e16\u754c\u8303\u56f4\u5185\u7684\u8bb8\u591a\u8bbe\u5907\u4e2d\u4f7f\u7528\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u4ec0\u4e48\u662fSQLite\uff1f<\/strong><\/div>\n

SQLite\u662f\u4e00\u4e2a\u8fdb\u7a0b\u5185\u7684\u5e93\uff0c\u5b9e\u73b0\u4e86\u81ea\u7ed9\u81ea\u8db3\u7684\u3001\u65e0\u670d\u52a1\u5668\u7684\u3001\u96f6\u914d\u7f6e\u7684\u3001\u4e8b\u52a1\u6027\u7684 SQL \u6570\u636e\u5e93\u5f15\u64ce\u3002\u5b83\u662f\u4e00\u4e2a\u96f6\u914d\u7f6e\u7684\u6570\u636e\u5e93\uff0c\u8fd9\u610f\u5473\u7740\u4e0e\u5176\u4ed6\u6570\u636e\u5e93\u4e0d\u4e00\u6837\uff0c\u4e0d\u9700\u8981\u5728\u7cfb\u7edf\u4e2d\u914d\u7f6e\u3002<\/p>\n

\u5b89\u88c5<\/strong><\/div>\n

\u4e0b\u9762\u5728Centos8\u4e2d\u5b89\u88c5SQLite\uff1a<\/p>\n

\r\n[root@localhost ~]# yum -y install sqlite\r\n<\/pre>\n

\u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\u8fd0\u884csqlite\u5427\uff1a<\/p>\n

\r\n[root@localhost ~]# sqlite3 \r\nSQLite version 3.26.0 2018-12-01 12:34:55\r\nEnter \".help\" for usage hints.\r\nConnected to a transient in-memory database.\r\nUse \".open FILENAME\" to reopen on a persistent database.\r\nsqlite>\r\n<\/pre>\n

\"\"
\nsqlite><\/code> \u63d0\u793a\u7b26\u7684\u610f\u601d\u662f SQLite \u6b63\u5728\u8fd0\u884c\u5e76\u51c6\u5907\u597d\u6267\u884c\u4efb\u4f55\u64cd\u4f5c\u3002\u73b0\u5728\uff0c\u901a\u8fc7\u952e\u5165 ^D<\/code> \u6216 .exit<\/code> \u9000\u51fa\u3002<\/p>\n

\u793a\u4f8b\uff1a\u5047\u8bbe\u4e00\u4e2a\u94b1\u5e01\u6536\u85cf\u5bb6\u3002\u6570\u636e\u5e93\u5c06\u88ab\u79f0\u4e3a numismatists.db\uff0c\u6570\u636e\u8868\u88ab\u79f0\u4e3acoins<\/code>\u3002\u6709\u5f88\u591a\u65b9\u6cd5\u4f7f\u7528 SQLite\u3002\u6211\u4eec\u5c06\u4ece\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\u5f00\u59cb\u3002\u56e0\u6b64\uff0c\u6253\u5f00\u6587\u672c\u7f16\u8f91\u5668\u5e76\u7f16\u8f91 numismatist.sql<\/code> \u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n

\r\n[root@localhost ~]# vim numismatists.db\r\n<\/pre>\n

\u590d\u5236\u4e00\u4e0b\u5185\u5bb9\u5230numismatists.db<\/code>\u6587\u4ef6\u4e2d\uff1a<\/p>\n

\r\n\/*\r\n * numismatist.sql\tBeginner's database\r\n *\/\r\n\r\nPRAGMA foreign_keys=OFF;\r\nBEGIN TRANSACTION;\r\n\r\nCreate Table coins(\r\ndenomination TEXT,\r\nvalue  FLOAT,\r\ncomments TEXT\r\n);\r\n\r\nInsert into coins values(\r\n'Quarter',\r\n30.35,\r\n'Gift from Grandpa'\r\n);\r\n\r\nCOMMIT;\r\n<\/pre>\n

\"\"
\n\u521b\u5efa\u8868\u548c\u521b\u5efa\u6570\u636e\u7684\u683c\u5f0f\u548cMysql\u7c7b\u4f3c\uff1a<\/p>\n

\u521b\u5efa\u8868\u683c\u7684\u683c\u5f0f\uff1acreate table tablename (....);<\/code><\/p>\n

\u521b\u5efa\u8bb0\u5f55\u7684\u683c\u5f0f\uff1ainsert into tablename values(..., ..., ...);<\/code><\/p>\n

\u63a5\u4e0b\u6765\uff0c\u544a\u8bc9 SQLite \u4f7f\u7528\u6211\u4eec\u521a\u521a\u521b\u5efa\u7684\u6587\u4ef6\u4e2d\u7684\u547d\u4ee4\u521b\u5efa\u6211\u4eec\u7684\u6570\u636e\u5e93\u3002<\/p>\n

\r\n[root@localhost ~]# cat numismatists.sql | sqlite3 numismatists.db\r\n<\/pre>\n

\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6d4b\u8bd5\u5b83\u662f\u5426\u6709\u6548\uff0c\u6765\u67e5\u770bcoins\u8868\u7684\u5185\u5bb9\uff1a<\/p>\n

\r\n[root@localhost ~]# sqlite3 numismatists.db 'select * from coins'\r\nQuarter|30.35|Gift from Grandpa\r\n<\/pre>\n

\"\"
\n\u6240\u6709\u8fd9\u4e9b\u64cd\u4f5c\u90fd\u53ef\u4ee5\u5728 SQLite \u5185\u90e8\u5b8c\u6210\uff0c\u8f93\u5165sqlite3<\/code>\u8fdb\u5165sqlite\u63a7\u5236\u53f0\uff1a<\/p>\n

\r\n[root@localhost ~]# sqlite3 numismatists.db\r\nSQLite version 3.26.0 2018-12-01 12:34:55\r\nEnter \".help\" for usage hints.\r\nsqlite> select * from coins;\r\nQuarter|30.35|Gift from Grandpa\r\nsqlite> \r\n<\/pre>\n

\"\"
\n\u53ef\u4ee5\u770b\u5230\u67e5\u8be2\u5230\u7684\u5185\u5bb9\u4e86\u3002<\/p>\n

sqlite\u63a7\u5236\u53f0\u4e2d\u57fa\u672c\u547d\u4ee4\uff1a<\/p>\n

    \n
  • .q<\/code> \u9000\u51fa\u63a7\u5236\u53f0<\/li>\n
  • .database<\/code> \u5217\u51fa\u6570\u636e\u5e93<\/li>\n
  • .table<\/code> \u5217\u51fa\u8868<\/li>\n<\/ul>\n
    \u5982\u4f55\u4f7f\u7528\u6570\u636e\u5e93<\/strong><\/div>\n

    \u73b0\u5728\u6211\u4eec\u6709\u4e86\u6700\u57fa\u672c\u6570\u636e\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u63a2\u7d22\u968f\u7740\u8fd9\u4e2a\u6570\u636e\u5e93\u89c4\u6a21\u7684\u589e\u957f\u4f1a\u53d1\u751f\u4ec0\u4e48\u3002\u6570\u636e\u5e93\u901a\u5e38\u5f88\u5927\uff0c\u4e0d\u662f\u5417\uff1f\u90a3\u4e48\u6211\u4eec\u5982\u4f55\u5728\u6570\u636e\u5e93\u4e2d\u8f93\u5165\u65e0\u6570\u884c\u8fdb\u884c\u6d4b\u8bd5\u5462\uff1f\u6ca1\u6709\u4eba\u4f1a\u8fd9\u6837\u505a\uff01\u7b80\u5355\uff0c\u65b9\u6cd5\u5982\u4e0b\uff08\u5982\u679c\u60a8\u4f7f\u7528 bash\uff09\uff0c\u53ea\u9700\u4f7f\u7528\u6b64\u811a\u672c\uff1a<\/p>\n

    \r\n[root@localhost ~]# vim sqlite.sh\r\n#!\/bin\/bash\r\nfunction my_insert() {\r\n      echo \"insert into coins values('$1', $2, 'From Grandpa');\"\r\n}\r\ni=1.25        # establish minimum coin value\r\nfor a in `seq 1 10000` ; do\r\n      new_val=`echo \"$i + $RANDOM \/ 1000\" | bc`\r\n      my_insert \"Quarter-$a\" $new_val >> big_add-list\r\n      #printf \"Processing %i\\n\" $a # modulo 100 == 0 would be better\r\n      echo \"Processing $a\"\r\ndone\r\n<\/pre>\n

    \"\"
    \n\u73b0\u5728\uff0c\u5c06\u65b0\u6570\u636e\u5408\u5e76\u5230\u73b0\u6709\u6570\u636e\u5e93\u4e2d\uff1a<\/p>\n

    \r\n[root@localhost ~]# cat big_add-list | sqlite3 numismatists.db\r\n<\/pre>\n

    \"\"
    \n\u53ef\u4ee5\u770b\u5230\u5df2\u7ecf\u5bfc\u51651166\u6761\u8bb0\u5f55\u4e86\u3002\u56e0\u4e3a\u6211\u6ca1\u6709\u8ba9\u811a\u672c\u751f\u621010000\u6761\u8bb0\u5f55\u3002<\/p>\n

    \u603b\u7ed3<\/strong><\/div>\n

    \u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u770b\u5230\u521b\u5efa\u6570\u636e\u5e93\u662f\u4e00\u9879\u975e\u5e38\u7b80\u5355\u7684\u4efb\u52a1\u3002\u4e0e SQLite \u7ed3\u5408\u4f7f\u7528\u65f6\uff0c\u4efb\u4f55\u4eba\u90fd\u53ef\u4ee5\u5927\u5927\u7b80\u5316\u901a\u5e38\u7531\u6570\u636e\u5e93\u5904\u7406\u7684\u4efb\u52a1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

    SQLite\u662f\u4e00\u4e2a\u8fdb\u7a0b\u5185\u7684\u5e93\uff0c\u5b9e\u73b0\u4e86\u81ea\u7ed9\u81ea\u8db3\u7684\u3001\u65e0\u670d\u52a1\u5668\u7684\u3001\u96f6\u914d\u7f6e\u7684\u3001\u4e8b\u52a1\u6027\u7684 SQL \u6570\u636e\u5e93\u5f15\u64ce\u3002\u5b83\u662f\u4e00\u4e2a\u96f6 […]<\/p>\n","protected":false},"author":309,"featured_media":230479,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-230478","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/230478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/309"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=230478"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/230478\/revisions"}],"predecessor-version":[{"id":230486,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/230478\/revisions\/230486"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/230479"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=230478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=230478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=230478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}