主要参考资料:
Install Microsoft SQL Server 2019 on Ubuntu 20.04/18.04/16.04 LTS
TODO LIST
system has notbeen booted with systemd as init system (PID 1)的问题,暂时没有解决,导致无法继续连接数据库
在安装之前,首先确保Ubuntu的安装镜像源已经更换至任意一个国内镜像源,这里我使用清华的镜像。
选择对应的Ubuntu版本,复制内容。

sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
sudo vim /etc/apt/sources.list

esc,再键入:wq后保存且退出。在Ubuntu Terminal运行一下命令安装 mssql-server 包:
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"
注意:这里不需要更换 ubuntu/20.04/ ,仍然使用 ubuntu/18.04/即可。
sudo apt-get update
sudo apt-get install -y mssql-server
mssql-conf setup,按照提示设置 SA 密码并选择版本:renyimeng@renyimeng-virtual-machine:~$ sudo /opt/mssql/bin/mssql-conf setup
Choose an edition of SQL Server:
  1) Evaluation (free, no production use rights, 180-day limit)
  2) Developer (free, no production use rights)
  3) Express (free)
  4) Web (PAID)
  5) Standard (PAID)
  6) Enterprise (PAID)
  7) Enterprise Core (PAID)
  8) I bought a license through a retail sales channel and have a product key to enter.
Details about editions can be found at
https://go.microsoft.com/fwlink/?LinkId=852748&clcid=0x409
Use of PAID editions of this software requires separate licensing through a
Microsoft Volume Licensing program.
By choosing a PAID edition, you are verifying that you have the appropriate
number of licenses in place to install and run this software.
Enter your edition(1-8): 2
The license terms for this product can be found in
/usr/share/doc/mssql-server or downloaded from:
https://go.microsoft.com/fwlink/?LinkId=855862&clcid=0x409
The privacy statement can be viewed at:
https://go.microsoft.com/fwlink/?LinkId=853010&clcid=0x409
Do you accept the license terms? [Yes/No]:Yes
Enter the SQL Server system administrator password:  <SetStrongNewPassword>
Confirm the SQL Server system administrator password: <ConfirmStrongPassword>
Configuring SQL Server...
ForceFlush is enabled for this instance. 
ForceFlush feature is enabled for log durability.
Created symlink /etc/systemd/system/multi-user.target.wants/mssql-server.service → /lib/systemd/system/mssql-server.service.
Setup has completed successfully. SQL Server is now starting.
注意:SA密码设置规则最少 8 个字符,包括大写和小写字母、十进制数字和/或非字母数字符号。
systemctl status mssql-server --no-pager
如下图所示,则为正常运行。

此时,SQL Server 2019 已在 Ubuntu 虚拟机上运行。
若要创建数据库,则需要使用可在 SQL Server 上运行 Transact-SQL 语句的工具进行连接。 以下步骤将安装 SQL Server 命令行工具:sqlcmd 和 bcp。
通过以下步骤在 Ubuntu 上安装 mssql-tools 和 **unixODBC **插件:
Ubuntu 20.04
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
sudo apt update 
sudo ACCEPT_EULA=Y apt install mssql-tools unixodbc-dev
注意:请将/ubuntu/20.04调整为对应 Ubuntu 版本的序号。
向 bash shell 中的 PATH 环境变量添加 /opt/mssql-tools/bin/
要使 sqlcmd/bcp 能从登陆会话的 bash shell 进行访问,请使用下列命令修改 ~/.bash_profile 文件中的 PATH :
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
要使 sqlcmd/bcp 能从交互式/非登录会话的 bash shell 进行访问,请使用下列命令修改 ~/.bashrc 文件中的 PATH :
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
sqlcmd -S 127.0.0.1 -U SA 
根据提示输入密码后,出现1>则表示连接成功。
以下步骤创建一个名为 TestDB 的新数据库。
1> create database testDB;
2> select name from sys.databases;
GO 才能执行以前的命令:3> GO
QUIT退出SQL命令行:1> QUIT



创建好8张表后,使用命令:
SELECT
  *
FROM
  INFORMATION_SCHEMA.TABLES;
GO
查看当前所有表的名称:

首先,确保数据已经去除竖线:
head -10 new_region.tbl  # 查看文件前2行

使用命令将已经去除行末竖线的数据加载到数据库TPCH中,并创建相应的表:
BULK INSERT region FROM '/home/renyimeng/renyimeng/tpch-dbgen/TPCH_data/new_region.tbl' WITH (FIELDTERMINATOR = '|',ROWTERMINATOR = '\n');
使用如下命令查看region表的行数:
select count(*) as region_rows from region;
输出结果应当如下所示:

