﻿{"id":12922,"date":"2022-02-09T10:04:07","date_gmt":"2022-02-09T02:04:07","guid":{"rendered":"https:\/\/www.linuxmi.com\/?p=12922"},"modified":"2022-02-09T10:04:07","modified_gmt":"2022-02-09T02:04:07","slug":"ubuntu-sql-server-sql-server-cli-tool","status":"publish","type":"post","link":"https:\/\/www.linuxmi.com\/ubuntu-sql-server-sql-server-cli-tool.html","title":{"rendered":"\u5982\u4f55\u5728 Ubuntu \u4e0a\u5b89\u88c5 SQL Server \u548c SQL Server CLI \u5de5\u5177"},"content":{"rendered":"<p><strong>\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728 Ubuntu 20.04\uff08Ubuntu 18.04 \u548c Ubuntu 16.04\u4e2d\u4e5f\u7c7b\u4f3c\uff09\u5b89\u88c5 Microsoft SQL Server 2019\u3002\u6b64\u5916\uff0c\u4e5f\u5c06\u5b89\u88c5\u7528\u4e8e\u8fde\u63a5\u6570\u636e\u5e93\u548c\u8fd0\u884c SQL \u67e5\u8be2\u7b49\u7684 SQL Server CLI \u5de5\u5177\u3002Linux \u4e0a\u7684 SQL Server \u662f\u4e00\u79cd\u4f01\u4e1a\u7ea7\u5173\u7cfb\u6570\u636e\u5e93\uff0c\u5177\u6709\u884c\u4e1a\u9886\u5148\u7684\u529f\u80fd\u548c\u5f3a\u5927\u7684\u4e1a\u52a1\u8fde\u7eed\u6027\u3002<\/strong><\/p>\n<p>\u8fd8\u6709\u4e9b\u670b\u53cb\u8ba4\u4e3a SQL Server \u53ea\u80fd\u5728 Windows \u4e0a\u8fd0\u884c\u3002\u4f46\u662f\u4ece SQL Server 2017 \u5f00\u59cb\uff0c\u4f60\u4e5f\u53ef\u4ee5\u5728 Linux \u4e0a\u8fd0\u884cSQL Server \u4e86\u3002SQL Server \u63d0\u4f9b\u4e86\u4e00\u4e9b\u5f00\u6e90\u7248\u672c\u6ca1\u6709\u7684\u529f\u80fd\uff0c\u5e76\u4e14\u6839\u636e\u5e94\u7528\u7a0b\u5e8f\u7684\u8981\u6c42\uff0c\u5b83\u53ef\u80fd\u662f\u5173\u7cfb\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf (RDBMS) \u7684\u6b63\u786e\u9009\u62e9\u3002<\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/linux\/sql-server-linux-overview\" target=\"_blank\" rel=\"noreferrer noopener\">Linux \u4e0a\u7684 SQL Server<\/a>\u76ee\u524d Red Hat\u3001Ubuntu \u548c SUSE\uff0c\u4ee5\u53ca Docker Engine \u652f\u6301\u51e0\u4e2a\u53d1\u884c\u7248\u3002<strong>\u672c\u6587\u6211\u4eec\u5c06\u4ecb\u7ecd\u5728 Ubuntu 20.04\u4e0a\u6f14\u793a\u5b89\u88c5 SQL Server 2019 \u7684\u5168\u90e8\u8fc7\u7a0b\u3002<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-12953 aligncenter\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/microsoft-sql-server-linux.jpg\" alt=\"\" width=\"1024\" height=\"768\" \/><\/p>\n<h2 id=\"sql-server-on-linux-system-requirements\">Linux \u4e0a\u7684 SQL Server \u7cfb\u7edf\u8981\u6c42<\/h2>\n<p>\u5c06\u8fd0\u884c SQL Server \u7684\u786c\u4ef6\u5177\u6709\u4ee5\u4e0b\u6700\u4f4e\u7cfb\u7edf\u8981\u6c42\uff1a<\/p>\n<ul>\n<li><strong>\u5185\u5b58<\/strong>\uff1a2 GB<\/li>\n<li><strong>\u78c1\u76d8\u7a7a\u95f4<\/strong>\uff1a6 GB<\/li>\n<li><strong>CPU<\/strong>\uff1a2 \u6838\uff0c2 GHz\uff0c<\/li>\n<li><strong>\u5904\u7406\u5668\u7c7b\u578b\uff1a<\/strong>\u4ec5\u517c\u5bb9 x-64<\/li>\n<li><strong>\u6587\u4ef6\u7cfb\u7edf\u7c7b\u578b<\/strong>\uff1aXFS \u6216 EXT4\uff08\u4e0d\u652f\u6301\u5176\u4ed6\u6587\u4ef6\u7cfb\u7edf\uff0c\u6bd4\u5982 BTRFS\uff09<\/li>\n<\/ul>\n<h2 id=\"install-sql-server-on-ubuntu\">\u5728 Ubuntu \u4e0a\u5b89\u88c5 SQL Server<\/h2>\n<h4>\u66f4\u65b0\/\u5347\u7ea7\u60a8\u7684\u7cfb\u7edf<\/h4>\n<p>\u786e\u4fdd\u7cfb\u7edf\u5b89\u88c5\u4e86\u6700\u65b0\u7684\u8f6f\u4ef6\u5305\u3002\u5bf9\u4e8e\u6b64\u66f4\u65b0\u548c\u5347\u7ea7\u60a8\u7684\u7cfb\u7edf\u3002<\/p>\n<pre class=\"wp-block-preformatted\"><code><code class=\"null\">linuxmi@linuxmi:~\/www.linuxmi.com$ <\/code>sudo apt update &amp;&amp; sudo apt upgrade<\/code><\/pre>\n<h3>\u6dfb\u52a0\u5b98\u65b9\u5b58\u50a8\u5e93\u4ee5\u5b89\u88c5 MSSQL \u670d\u52a1\u5668\u3002<\/h3>\n<p>\u4e3a\u4e86\u5728 Ubuntu \u4e0a\u5b89\u88c5 SQL Server\uff0c\u6211\u4eec\u9700\u8981\u901a\u8fc7\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5bfc\u5165 Microsoft \u7684\u516c\u5171\u5b58\u50a8\u5e93 GPG \u5bc6\u94a5\uff1a<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\">\n<pre class=\"pure-highlightjs\"><code class=\"null\">linuxmi@linuxmi:~\/www.linuxmi.com$ wget -qO- https:\/\/packages.microsoft.com\/keys\/microsoft.asc | sudo apt-key add -\r\n[sudo] linuxmi \u7684\u5bc6\u7801\uff1a \r\nOK<\/code><\/pre>\n<\/figure>\n<\/div>\n<h3 id=\"add-sql-server-repository\">\u6dfb\u52a0 SQL Server \u5b58\u50a8\u5e93<\/h3>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u6ce8\u518c Microsoft SQL Server \u7684 Ubuntu \u5b58\u50a8\u5e93\u3002<\/p>\n<p id=\"ubuntu-20-04-focal-fossa\"><strong>Ubuntu 20.04 \u201cFocal Fossa\u201d<\/strong><\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">linuxmi@linuxmi:~\/www.linuxmi.com$ sudo add-apt-repository \"$(wget -qO- https:\/\/packages.microsoft.com\/config\/ubuntu\/20.04\/mssql-server-2019.list)\"<\/code><\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12924\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-1.png\" alt=\"\" width=\"1026\" height=\"257\" \/><strong>Ubuntu 18.04 \u201cBionic Beaver\u201d<\/strong><\/figure>\n<\/div>\n<pre class=\"pure-highlightjs\"><code class=\"null\">linuxmi@linuxmi:~\/www.linuxmi.com$ sudo add-apt-repository \"$(wget -qO- https:\/\/packages.microsoft.com\/config\/ubuntu\/18.04\/mssql-server-2019.list)\"<\/code><\/pre>\n<h3 id=\"install-sql-server-on-ubuntu\">\u5728 Ubuntu \u4e0a\u5b89\u88c5 SQL Server<\/h3>\n<p>\u73b0\u5728\u6211\u4eec\u7684 Ubuntu \u7cfb\u7edf\u77e5\u9053 Microsoft SQL \u5b58\u50a8\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5b83<code>apt<\/code>\u6765\u5b89\u88c5<code>mssql-server<\/code>\u5305\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">linuxmi@linuxmi:~\/www.linuxmi.com$ sudo apt install mssql-server<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12925\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-2.png\" alt=\"\" width=\"1026\" height=\"465\" \/><\/p>\n<p>\u7136\u540e\u5b89\u88c5\u7ee7\u7eed\u4e0b\u8f7d\u3001\u89e3\u538b\u548c\u8bbe\u7f6e\u5fc5\u8981\u7684\u5305\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12927\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-3.png\" alt=\"\" width=\"1026\" height=\"673\" \/><\/p>\n<div class=\"wp-block-image\">\u6700\u540e\uff0c\u63d0\u793a\u6211\u4eec\u8fd0\u884c &#8220;sudo \/opt\/mssql\/bin\/mssql-conf setup&#8221; \u5b8c\u6210 Microsoft SQL Server \u7684\u8bbe\u7f6e<\/div>\n<h2 id=\"configure-microsoft-sql-server\">\u914d\u7f6e Microsoft SQL Server<\/h2>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u7cfb\u7edf\u7ba1\u7406\u5458\u5bc6\u7801\u914d\u7f6e\u6211\u4eec\u7684 SQL Server\uff0c\u5e76\u786e\u8ba4\u6211\u4eec\u8981\u4f7f\u7528\u7684\u7248\u672c\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5f00\u59cb\u914d\u7f6e SQL Server\uff1a<\/p>\n<div class=\"wp-block-spacer\" aria-hidden=\"true\">\n<pre class=\"pure-highlightjs\"><code class=\"null\">linuxmi@linuxmi:~\/www.linuxmi.com$ sudo \/opt\/mssql\/bin\/mssql-conf setup<\/code><\/pre>\n<\/div>\n<p>\u9996\u5148\uff0c\u914d\u7f6e\u8981\u6c42\u60a8\u4ece SQL Server \u7684\u53ef\u7528\u7248\u672c\u5217\u8868\u4e2d\u8fdb\u884c\u9009\u62e9\u3002<\/p>\n<figure class=\"wp-block-table is-style-regular\">\n<table>\n<tbody>\n<tr>\n<td>1<\/td>\n<td><strong>\u8bc4\u4f30Evaluation<\/strong>\uff08\u514d\u8d39\uff09<\/td>\n<td>\u7528\u4e8e\u5b66\u4e60\u548c\u5f00\u53d1\u89e3\u51b3\u65b9\u6848\u7684\u529f\u80fd\u9f50\u5168\u4e14\u514d\u8d39\u7684 SQL Server \u5b9e\u4f8b\u3002\u6b64\u7248\u672c\u7684\u5185\u7f6e\u6709\u6548\u671f\u4e3a\u81ea\u60a8\u5b89\u88c5\u4e4b\u65e5\u8d77 180 \u5929\u3002<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td><strong>\u5f00\u53d1\u4eba\u5458Developer<\/strong>\uff08\u514d\u8d39\uff09<\/td>\n<td>\u529f\u80fd\u9f50\u5168\u7684 SQL Server \u4f01\u4e1a\u7248\uff0c\u6388\u6743\u5728\u975e\u751f\u4ea7\u73af\u5883\u4e2d\u7528\u4f5c\u5f00\u53d1\u548c\u6d4b\u8bd5\u6570\u636e\u5e93\u3002<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td><strong>\u8f7b\u91cf\u7ea7 Express<\/strong>\uff08\u514d\u8d39\uff09<\/td>\n<td>SQL Server \u7684\u514d\u8d39\u8f7b\u91cf\u7ea7\u7248\u672c\uff0c\u6709\u4e00\u4e9b\u9650\u5236\uff0c\u53ef\u7528\u4e8e\u751f\u4ea7\u73af\u5883\u3002\u5b83\u53ea\u80fd\u4f7f\u7528 1 \u4e2a CPU \u548c 1 GB \u5185\u5b58\uff0c\u6570\u636e\u5e93\u7684\u6700\u5927\u5927\u5c0f\u4e3a 10 GB\u3002<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td><strong>\u7f51\u7edcWeb<\/strong>\uff08\u4ed8\u8d39\uff09<\/td>\n<td>\u7f51\u7edc\u6258\u7ba1\u5546\u7684\u4f4e\u603b\u62e5\u6709\u6210\u672c\u9009\u9879\u3002<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td><strong>\u6807\u51c6Standard<\/strong>\uff08\u4ed8\u8d39\uff09<\/td>\n<td>\u5f53\u4e0d\u9700\u8981\u9ad8\u7ea7\u529f\u80fd\u65f6\uff0c\u529f\u80fd\u6bd4\u4f01\u4e1a\u7248Enterprise \u5c11\u3002<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td><strong>\u4f01\u4e1a<\/strong> <strong>Enterprise<\/strong>\uff08\u4ed8\u8d39\uff09<\/td>\n<td>\u5177\u6709\u5b8c\u6574\u529f\u80fd\u96c6\u7684\u9ad8\u7aef\u7248\u672c\u3002CPU \u6838\u5fc3\u5229\u7528\u7387\u9650\u5236\u4e3a 20 \u4e2a\u7269\u7406\/40 \u4e2a\u8d85\u7ebf\u7a0b\u3002<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td><strong>\u4f01\u4e1a\u6838\u5fc3Enterprise Core<\/strong>\uff08\u4ed8\u8d39\uff09<\/td>\n<td>\u5177\u6709\u57fa\u4e8e\u6838\u5fc3\u7684\u8bb8\u53ef\u7684\u4f01\u4e1a\u7248\u3002CPU \u6838\u5fc3\u5229\u7528\u7387\u8fbe\u5230\u64cd\u4f5c\u7cfb\u7edf\u6700\u5927\u503c\u3002<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>\u6211\u901a\u8fc7\u96f6\u552e\u6e20\u9053\u8d2d\u4e70\u4e86\u8bb8\u53ef\u8bc1\u5e76\u5177\u6709\u8981\u8f93\u5165\u7684\u4ea7\u54c1\u5bc6\u94a5\u3002<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>\u6211\u5c06\u4f7f\u7528\u5f00\u53d1\u4eba\u5458\u7248\u672c\uff0c\u9009\u62e9<code>2<\/code>\uff0c\u6d4b\u8bd5\u5c31\u7528\u514d\u8d39\u7684\u5427\u3002<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12928\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-4.png\" alt=\"\" width=\"1026\" height=\"621\" \/><\/figure>\n<\/div>\n<p>\u63a5\u4e0b\u6765\uff0c\u60a8\u9700\u8981\u901a\u8fc7\u952e\u5165\u00a0<strong><code>Yes<\/code><\/strong> \u5e76\u6309\u00a0<code>Enter<\/code>\u6765\u63a5\u53d7\u8bb8\u53ef\u6761\u6b3e\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12929\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-5.png\" alt=\"\" width=\"1026\" height=\"335\" \/><\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\">\u9009\u62e9 SQL Server \u7684\u8bed\u8a00\uff0c\u6211\u4eec\u9009\u62e9\u7b80\u4f53\u4e2d\u6587:<\/figure>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12930\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-6.png\" alt=\"\" width=\"1026\" height=\"439\" \/><\/p>\n<\/div>\n<p>\u6700\u540e\uff0c\u60a8\u9700\u8981\u8f93\u5165 SQL Server \u670d\u52a1\u5668\u7ba1\u7406\u5458 (sa) \u5bc6\u7801\uff08LinuxMi.com@888\uff09\u3002\u5bc6\u7801\u81f3\u5c11\u9700\u8981 8 \u4e2a\u5b57\u7b26\uff0c\u5305\u62ec\u5927\u5199\u3001\u5c0f\u5199\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u975e\u5b57\u6bcd\u6570\u5b57\u7b26\u53f7\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12931\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-7.png\" alt=\"\" width=\"1026\" height=\"361\" \/><\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\">\n<pre class=\"pure-highlightjs\"><code class=\"null\">\u8f93\u5165 SQL Server \u7cfb\u7edf\u7ba1\u7406\u5458\u5bc6\u7801:LinuxMi.com@888\r\n\u786e\u8ba4 SQL Server \u7cfb\u7edf\u7ba1\u7406\u5458\u5bc6\u7801:<span style=\"color: #ff0000;\">LinuxMi.com@888<\/span>\r\n\u6b63\u5728\u914d\u7f6e SQL Server...\r\n\r\nForceFlush is enabled for this instance.\r\nForceFlush feature is enabled for log durability.\r\nCreated symlink \/etc\/systemd\/system\/multi-user.target.wants\/mssql-server.service \u2192 \/lib\/systemd\/system\/mssql-server.service.\r\n\u5b89\u88c5\u7a0b\u5e8f\u5df2\u6210\u529f\u5b8c\u6210\u3002SQL Server \u6b63\u5728\u542f\u52a8\u3002<\/code><\/pre>\n<p>\u5b89\u88c5\u5c06\u6210\u529f\u5b8c\u6210\uff0cSQL \u670d\u52a1\u5668\u5c06\u542f\u52a8\u3002\u8981\u9a8c\u8bc1<code>mssql-server<\/code>\u670d\u52a1\u662f\u5426\u6b63\u5728\u8fd0\u884c\uff1a<\/figure>\n<\/div>\n<figure class=\"aligncenter size-large\">\n<pre class=\"pure-highlightjs\"><code class=\"null\">linuxmi@linuxmi:~\/www.linuxmi.com$ sudo systemctl status mssql-server<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12932\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-8.png\" alt=\"\" width=\"1026\" height=\"387\" \/><\/figure>\n<h2>\u4e3a SQL Server \u5b89\u88c5\u547d\u4ee4\u884c\u5de5\u5177mssql-tool<\/h2>\n<p>\u60a8\u9700\u8981<strong><code>sqlcmd<\/code><\/strong>\u5728 Linux \u4e0a\u5b89\u88c5\u7528\u4e8e\u8fde\u63a5 SQL Server \u7684\u5b9e\u7528\u7a0b\u5e8f\u3002\u5b83\u65e8\u5728\u4f18\u5316 SQL \u67e5\u8be2\u5e76\u7b80\u5316\u4e00\u4e9b\u6570\u636e\u5e93\u7ba1\u7406\u4efb\u52a1\u3002<\/p>\n<p>mssql-tool \u5305\u5305\u542b sqlcmd\uff08\u547d\u4ee4\u884c\u67e5\u8be2\uff09\u548c bcp\uff08\u6279\u91cf\u5bfc\u5165-\u5bfc\u51fa\uff09\u5b9e\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u5f53\u7136\uff0c\u5982\u679c\u60a8\u719f\u6089 SQL Server Management Studio\uff0c\u5219\u53ef\u4ee5\u5728 Windows \u4e0a\u4f7f\u7528\u5b83\u6765\u8fdc\u7a0b\u8fde\u63a5\u5230\u65b0\u5b89\u88c5\u7684 SQL Server Linux \u5b9e\u4f8b\u3002<\/p>\n<p>\u5bfc\u5165\u516c\u5171\u5b58\u50a8\u5e93 GPG \u5bc6\u94a5\u5e76\u66f4\u65b0\u8f6f\u4ef6\u5305\u5e93\uff1a<\/p>\n<h3 id=\"ubuntu-2004\">Ubuntu 20.04<\/h3>\n<pre class=\"pure-highlightjs\"><code class=\"null\">linuxmi@linuxmi:~\/www.linuxmi.com$ curl https:\/\/packages.microsoft.com\/config\/ubuntu\/20.04\/prod.list | sudo tee \/etc\/apt\/sources.list.d\/msprod.list\r\nlinuxmi@linuxmi:~\/www.linuxmi.com$ sudo apt update<\/code><\/pre>\n<h3><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12933\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-9.png\" alt=\"\" width=\"1026\" height=\"309\" \/><\/h3>\n<h3 id=\"ubuntu-1804\">Ubuntu 18.04<\/h3>\n<pre class=\"wp-block-code spai-bg-prepared language-bash\" tabindex=\"0\"><code class=\" spai-bg-prepared language-bash\" lang=\"bash\"><span class=\"token function\"><code class=\"null\">linuxmi@linuxmi:~\/www.linuxmi.com$ <\/code>curl<\/span> https:\/\/packages.microsoft.com\/config\/ubuntu\/18.04\/prod.list <span class=\"token operator\">|<\/span> <span class=\"token function\">sudo<\/span> <span class=\"token function\">tee<\/span> \/etc\/apt\/sources.list.d\/msprod.list <span class=\"token function\"><code class=\"null\">linuxmi@linuxmi:~\/www.linuxmi.com$ <\/code>sudo<\/span> <span class=\"token function\">apt<\/span> update<\/code><\/pre>\n<p>\u901a\u8fc7\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5b89\u88c5 SQL Server \u547d\u4ee4\u884c\u5de5\u5177 (\u00a0<code>mssql-tools<\/code>) \u548c\u7528\u4e8e\u57fa\u4e8e Linux \u7684\u7cfb\u7edf\u7684 SQL Server \u9a71\u52a8\u7a0b\u5e8f\uff08<code>unixodbc-dev<\/code>\uff09\uff1a<\/p>\n<div class=\"wp-block-spacer\" aria-hidden=\"true\">\n<pre class=\"pure-highlightjs\"><code class=\"null\">linuxmi@linuxmi:~\/www.linuxmi.com$ sudo apt install mssql-tools unixodbc-dev<\/code><\/pre>\n<\/div>\n<p><strong>\u8fd9\u4e00\u6b65\u51fa\u73b0\u4f9d\u8d56\u95ee\u9898\u89e3\u51b3\u89c1<\/strong>\uff1a<a href=\"http:\/\/www.linuxidc.net\/thread-9941-1-1.html\">http:\/\/www.linuxidc.net\/thread-9941-1-1.html<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12951\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-error.png\" alt=\"\" width=\"1026\" height=\"439\" \/><\/p>\n<p>\u9009\u62e9<strong><code>\u786e\u5b9a\u2014\u2014\u662f<\/code><\/strong>\u63a5\u53d7\u8bb8\u53ef\u6761\u6b3e\u5e76\u7ee7\u7eed\u3002<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12935\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-10.png\" alt=\"\" width=\"1026\" height=\"491\" \/> <img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12936 size-full\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-11.png\" alt=\"\" width=\"1026\" height=\"491\" \/><\/figure>\n<\/div>\n<p>\u63a5\u4e0b\u6765\uff0c\u518d\u6b21\u9009\u62e9 <code>\u786e\u5b9a\u2014\u2014\u662f<\/code>\u00a0\u63a5\u53d7\u8bae<code>mssql-tools<\/code>\u914d\u7f6e\u7684\u8bb8\u53ef\u534f\u8bae\u3002<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12937\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-12.png\" alt=\"\" width=\"1026\" height=\"491\" \/> <img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12938 size-full\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-13.png\" alt=\"\" width=\"1026\" height=\"491\" \/><\/figure>\n<\/div>\n<p>\u4e0a\u9762\u7684\u5b89\u88c5\u4e0d\u4f1a\u4e3a\u6267\u884cmssql tools\u521b\u5efa\u73af\u5883\u53d8\u91cf\u3002\u56e0\u6b64\uff0c\u73b0\u5728\u6211\u4eec\u5c06\u5728bash shell<code>\/opt\/mssql-tools\/bin\/<\/code>\u4e2d\u6dfb\u52a0\u5230\u6211\u4eec\u7684 PATH \u73af\u5883\u53d8\u91cf\uff0c \u4ee5\u4fbf\u53ef\u4ee5\u4ece bash \u8bbf\u95ee<code>sqlcmd<\/code>\u547d\u4ee4\u4ee5\u8fdb\u884c\u767b\u5f55\u4f1a\u8bdd\u3002<\/p>\n<p>\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">linuxmi@linuxmi:~\/www.linuxmi.com$ <span style=\"color: #ff0000;\">echo 'export PATH=\"$PATH:\/opt\/mssql-tools\/bin\"' &gt;&gt; ~\/.bash_profile<\/span>\r\nlinuxmi@linuxmi:~\/www.linuxmi.com$ <span style=\"color: #ff0000;\">echo 'export PATH=\"$PATH:\/opt\/mssql-tools\/bin\"' &gt;&gt; ~\/.bashrc<\/span>\r\nlinuxmi@linuxmi:~\/www.linuxmi.com$ <span style=\"color: #ff0000;\">source ~\/.bashrc<\/span><\/code><\/pre>\n<h2><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12939\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-14.png\" alt=\"\" width=\"1026\" height=\"283\" \/><\/h2>\n<h2 id=\"connect-to-sql-server-on-linux\">\u5728 Linux \u4e0a\u8fde\u63a5\u5230 SQL Server<\/h2>\n<p>\u8981\u8fde\u63a5\u5230 SQL \u670d\u52a1\u5668\uff0c\u8bf7\u4f7f\u7528 sqlcmd \u547d\u4ee4\u3002\u5b83\u53ef\u4ee5\u5728\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\uff0c\u4e5f\u53ef\u4ee5\u5728\u672c\u5730 SQl \u670d\u52a1\u5668\u4e0a\u3002<\/p>\n<p>\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">linuxmi@linuxmi:~\/www.linuxmi.com$ <span style=\"color: #ff0000;\">sqlcmd -S localhost -U SA -P 'LinuxMi.com@888'<\/span><\/code><\/pre>\n<p>\u8fde\u63a5\u540e\uff0c\u60a8\u4f1a\u5f97\u5230\u63d0\u793a<code>1&gt;<\/code>\u3002\u73b0\u5728\u6211\u4eec\u6765\u68c0\u67e5 MS SQL \u7248\u672c\uff1a<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\">\n<pre class=\"pure-highlightjs\"><code class=\"null\">select @@VERSION \r\ngo<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12943\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-15-1.png\" alt=\"\" width=\"1050\" height=\"647\" \/><\/p>\n<p>\u5982\u679c\u8981\u521b\u5efa\u6570\u636e\u5e93\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b SQL \u547d\u4ee4\u3002<\/p>\n<p>\u4ee5\u4e0b\u6b65\u9aa4\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a <span style=\"color: #ff0000;\">linuxmi<\/span> \u7684\u6570\u636e\u5e93\u3002<\/figure>\n<\/div>\n<pre class=\"pure-highlightjs\"><code class=\"null\">create database linuxmi\r\ngo<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12944\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-16.png\" alt=\"\" width=\"1038\" height=\"231\" \/><\/p>\n<p><strong>\u67e5\u8be2\u6240\u6709\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u7f16\u5199\u4e00\u4e2a\u67e5\u8be2\u4ee5\u8fd4\u56de\u670d\u52a1\u5668\u4e0a\u6240\u6709\u6570\u636e\u5e93\u7684\u540d\u79f0\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">SELECT Name from sys.Databases\r\ngo<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12949\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2022\/02\/mssql-17.png\" alt=\"\" width=\"1038\" height=\"699\" \/><\/p>\n<p><strong>\u9000\u51fa sqlcmd \u547d\u4ee4\u63d0\u793a\u7b26<\/strong><\/p>\n<p>\u8981\u7ed3\u675f\u60a8\u7684sqlcmd\u4f1a\u8bdd\uff0c\u8bf7\u952e\u5165QUIT\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">QUIT<\/code><\/pre>\n<h2>\u91cd\u542f Microsoft SQL \u670d\u52a1\u5668<\/h2>\n<pre class=\"pure-highlightjs\"><code class=\"null\">linuxmi@linuxmi:~\/www.linuxmi.com$ systemctl restart mssql-server.service<\/code><\/pre>\n<h2>\u66f4\u65b0\/\u5347\u7ea7 Microsoft SQL \u670d\u52a1\u5668<\/h2>\n<p>\u6211\u4eec\u6dfb\u52a0\u4e86\u6765\u81ea Microsoft \u7684\u5b58\u50a8\u5e93\u6765\u5b89\u88c5 SQL Server\u3002\u56e0\u6b64\uff0c\u8981\u66f4\u65b0\/\u5347\u7ea7 SQL \u670d\u52a1\u5668\uff0c\u8bf7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">linuxmi@linuxmi:~\/www.linuxmi.com$ sudo apt update &amp;&amp; sudo apt install mssql-server<\/code><\/pre>\n<h2>\u5220\u9664 Microsoft SQL \u670d\u52a1\u5668<\/h2>\n<p>\u8981\u5b8c\u5168\u5220\u9664 SQL Server 2019 \u53ca\u5176\u4f9d\u8d56\u9879\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">linuxmi@linuxmi:~\/www.linuxmi.com$ sudo apt purge mssql-server mssql-tools -y\r\nlinuxmi@linuxmi:~\/www.linuxmi.com$ sudo apt autoremove -y<\/code><\/pre>\n<h3><strong>\u603b\u7ed3<\/strong><\/h3>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5b66\u4e60\u4e86\u5982\u4f55\u5728 Ubuntu 20.04 \u4e0a\u5b89\u88c5 Microsoft SQL Server \u5e76\u8fde\u63a5\u5230 SQL Server \u4ee5\u8fd0\u884c SQL \u67e5\u8be2\u3002\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 Linux \u4e0a\u7684\u65b0 SQL Server \u6267\u884c\u60a8\u60f3\u8981\u7684\u4efb\u4f55\u6570\u636e\u5e93\u6d3b\u52a8\u3002\u611f\u8c22\u60a8\u7684\u9605\u8bfb\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728 Ubuntu 20.04\uff08Ubuntu 18.04 \u548c Ubuntu 16.04 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[947],"class_list":["post-12922","post","type-post","status-publish","format-standard","hentry","category-zixun","tag-sql-server"],"aioseo_notices":[],"views":2500,"_links":{"self":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/12922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/comments?post=12922"}],"version-history":[{"count":12,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/12922\/revisions"}],"predecessor-version":[{"id":12954,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/12922\/revisions\/12954"}],"wp:attachment":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/media?parent=12922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/categories?post=12922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/tags?post=12922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}