MathJax

MathJax-2

MathJax-3

Google Code Prettify

置頂入手筆記

EnterproseDB Quickstart — 快速入門筆記

由於考慮採用 EnterpriseDB 或是直接用 PostgreSQL 的人,通常需要一些入手的資料。這邊紀錄便提供相關快速上手的簡單筆記 ~ 這篇筆記以 資料庫安裝完畢後的快速使用 為目標,基本紀錄登入使用的範例:

2021年1月1日 星期五

在 LXD 安裝 MS SQL Server 2019 XE

為了測試 PostgreSQL 的 tds_fdw 這個外掛,這邊要在測試環境安裝 Linux 版的 SQL Server XE 看看。這邊用的是 2019 版。這邊裝在 LXD Container 裡面,確定可以運作。


因為 SQL Server 有點龜毛,不能用 1.7GB 記憶體而已。。。至少得 2GB。。。所以使用 Google VM 的話得要把計算資源調整成貴一點點的規格,不能用最便宜的 600MB 記憶體版本。。。

先長一個 Container
lab@lxdlab-edb:~$ lxc launch images:centos/7/amd64 mssqlsvrxe
lab@lxdlab-edb:~$ lxc shell mssqlsvrxe
[root@mssqlsvrxe ~]#


取得 Repo 檔案,然後用 YUM 指令安裝。因為 MS SQL 的 Client 跟 Server 是分開裝的,這邊先裝 Server 部份
[root@mssqlsvrxe ~]# curl -o /etc/yum.repos.d/mssql-server-2019.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2019.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 231 100 231 0 0 115 0 0:00:02 0:00:01 0:00:01 115
[root@mssqlsvrxe ~]#
[root@mssqlsvrxe ~]# yum install -y sudo mssql-server mssql-tools
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: ftp.tc.edu.tw
* extras: ftp.tc.edu.tw
* updates: ftp.tc.edu.tw
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
packages-microsoft-com-mssql-server-2019 | 3.0 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/5): base/7/x86_64/group_gz | 153 kB 00:00:01
(2/5): extras/7/x86_64/primary_db | 206 kB 00:00:01
(3/5): packages-microsoft-com-mssql-server-2019/primary_db | 118 kB 00:00:00
(4/5): updates/7/x86_64/primary_db | 4.5 MB 00:00:13
(5/5): base/7/x86_64/primary_db | 6.1 MB 00:00:16
No package mssql-tools available.
Resolving Dependencies
--> Running transaction check
---> Package mssql-server.x86_64 0:15.0.4053.23-2 will be installed
--> Processing Dependency: openssl >= 1:1.0.1g for package: mssql-server-15.0.1900.25-1.x86_64
--> Processing Dependency: bzip2 for package: mssql-server-15.0.1900.25-1.x86_64
--> Processing Dependency: numactl-libs for package: mssql-server-15.0.1900.25-1.x86_64
--> Processing Dependency: gdb for package: mssql-server-15.0.1900.25-1.x86_64
--> Processing Dependency: cyrus-sasl-gssapi for package: mssql-server-15.0.1900.25-1.x86_64
--> Processing Dependency: libsss_nss_idmap for package: mssql-server-15.0.1900.25-1.x86_64
--> Processing Dependency: cyrus-sasl for package: mssql-server-15.0.1900.25-1.x86_64
---> Package sudo.x86_64 0:1.8.23-9.el7 will be installed
--> Running transaction check
---> Package bzip2.x86_64 0:1.0.6-13.el7 will be installed
---> Package cyrus-sasl.x86_64 0:2.1.26-23.el7 will be installed
---> Package cyrus-sasl-gssapi.x86_64 0:2.1.26-23.el7 will be installed
---> Package gdb.x86_64 0:7.6.1-119.el7 will be installed
---> Package libsss_nss_idmap.x86_64 0:1.16.4-37.el7_8.4 will be installed
---> Package numactl-libs.x86_64 0:2.0.12-5.el7 will be installed
---> Package openssl.x86_64 1:1.0.2k-19.el7 will be installed
--> Processing Dependency: make for package: 1:openssl-1.0.2k-19.el7.x86_64
--> Running transaction check
---> Package make.x86_64 1:3.82-24.el7 will be installed
--> Finished Dependency Resolution


Dependencies Resolved


========================================================================================================================
Package Arch Version Repository Size
========================================================================================================================
Installing:
mssql-server x86_64 15.0.4053.23-2 packages-microsoft-com-mssql-server-2019 209 M
sudo x86_64 1.8.23-9.el7 base 842 k
Installing for dependencies:
bzip2 x86_64 1.0.6-13.el7 base 52 k
cyrus-sasl x86_64 2.1.26-23.el7 base 88 k
cyrus-sasl-gssapi x86_64 2.1.26-23.el7 base 41 k
gdb x86_64 7.6.1-119.el7 base 2.4 M
libsss_nss_idmap x86_64 1.16.4-37.el7_8.4 updates 162 k
make x86_64 1:3.82-24.el7 base 421 k
numactl-libs x86_64 2.0.12-5.el7 base 30 k
openssl x86_64 1:1.0.2k-19.el7 base 493 k


Transaction Summary
========================================================================================================================
Install 2 Packages (+8 Dependent packages)


Total download size: 220 M
Installed size: 228 M
Downloading packages:
(1/10): cyrus-sasl-gssapi-2.1.26-23.el7.x86_64.rpm | 41 kB 00:00:00
(2/10): libsss_nss_idmap-1.16.4-37.el7_8.4.x86_64.rpm | 162 kB 00:00:00
(3/10): bzip2-1.0.6-13.el7.x86_64.rpm | 52 kB 00:00:00
(4/10): cyrus-sasl-2.1.26-23.el7.x86_64.rpm | 88 kB 00:00:01
(5/10): numactl-libs-2.0.12-5.el7.x86_64.rpm | 30 kB 00:00:00
(6/10): make-3.82-24.el7.x86_64.rpm | 421 kB 00:00:01
(7/10): openssl-1.0.2k-19.el7.x86_64.rpm | 493 kB 00:00:02
(8/10): sudo-1.8.23-9.el7.x86_64.rpm | 842 kB 00:00:04
(9/10): gdb-7.6.1-119.el7.x86_64.rpm | 2.4 MB 00:00:09
warning: /var/cache/yum/x86_64/7/packages-microsoft-com-mssql-server-preview/packages/mssql-server-15.0.1900.25-1.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID be1229cf: NOKEY
Public key for mssql-server-15.0.1900.25-1.x86_64.rpm is not installed
(10/10): mssql-server-15.0.1900.25-1.x86_64.rpm | 216 MB 00:05:56
------------------------------------------------------------------------------------------------------------------------
Total 630 kB/s | 220 MB 00:05:57
Retrieving key from https://packages.microsoft.com/keys/microsoft.asc
Importing GPG key 0xBE1229CF:
Userid : "Microsoft (Release signing) <gpgsecurity@microsoft.com>"
Fingerprint: bc52 8686 b50d 79e3 39d3 721c eb3e 94ad be12 29cf
From : https://packages.microsoft.com/keys/microsoft.asc
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : cyrus-sasl-gssapi-2.1.26-23.el7.x86_64 1/10
Installing : 1:make-3.82-24.el7.x86_64 2/10
Installing : 1:openssl-1.0.2k-19.el7.x86_64 3/10
Installing : cyrus-sasl-2.1.26-23.el7.x86_64 4/10
Installing : libsss_nss_idmap-1.16.4-37.el7_8.4.x86_64 5/10
Installing : numactl-libs-2.0.12-5.el7.x86_64 6/10
Installing : bzip2-1.0.6-13.el7.x86_64 7/10
Installing : gdb-7.6.1-119.el7.x86_64 8/10
Installing : mssql-server-15.0.4053.23-2.x86_64 9/10


+--------------------------------------------------------------+
Please run 'sudo /opt/mssql/bin/mssql-conf setup'
to complete the setup of Microsoft SQL Server
+--------------------------------------------------------------+


Installing : sudo-1.8.23-9.el7.x86_64 10/10
Verifying : sudo-1.8.23-9.el7.x86_64 1/10
Verifying : gdb-7.6.1-119.el7.x86_64 2/10
Verifying : bzip2-1.0.6-13.el7.x86_64 3/10
Verifying : numactl-libs-2.0.12-5.el7.x86_64 4/10
Verifying : 1:openssl-1.0.2k-19.el7.x86_64 5/10
Verifying : libsss_nss_idmap-1.16.4-37.el7_8.4.x86_64 6/10
Verifying : cyrus-sasl-2.1.26-23.el7.x86_64 7/10
Verifying : 1:make-3.82-24.el7.x86_64 8/10
Verifying : mssql-server-15.0.4053.23-2.x86_64 9/10
Verifying : cyrus-sasl-gssapi-2.1.26-23.el7.x86_64 10/10


Installed:
mssql-server.x86_64 0:15.0.4053.23-2 sudo.x86_64 0:1.8.23-9.el7


Dependency Installed:
bzip2.x86_64 0:1.0.6-13.el7 cyrus-sasl.x86_64 0:2.1.26-23.el7
cyrus-sasl-gssapi.x86_64 0:2.1.26-23.el7 gdb.x86_64 0:7.6.1-119.el7
libsss_nss_idmap.x86_64 0:1.16.4-37.el7_8.4 make.x86_64 1:3.82-24.el7
numactl-libs.x86_64 0:2.0.12-5.el7 openssl.x86_64 1:1.0.2k-19.el7


Complete!
[root@mssqlsvrxe ~]#



看一下上面,已經告訴你接著該怎做惹~~
下面有選項,不想太麻煩,我選 Express 免費版
密碼的部份有些龜毛。。。要求大小寫英數字混用的八字元規格。
[root@mssqlsvrxe ~]# /opt/mssql/bin/mssql-conf setup
usermod: no changes
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) - CPU Core utilization restricted to 20 physical/40 hyperthreaded
7) Enterprise Core (PAID) - CPU Core utilization up to Operating System Maximum
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=2109348


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): 3
The license terms for this product can be found in
/usr/share/doc/mssql-server or downloaded from:
https://go.microsoft.com/fwlink/?LinkId=2104294


The privacy statement can be viewed at:
https://go.microsoft.com/fwlink/?LinkId=853010


Do you accept the license terms? [Yes/No]:Yes


Enter the SQL Server system administrator password:SQLS1rv1r
Confirm the SQL Server system administrator password: SQLS1rv1r
Configuring SQL Server...


The licensing PID was successfully processed. The new edition is [Express Edition].
ForceFlush is enabled for this instance.
ForceFlush feature is enabled for log durability.
Setup has completed successfully. SQL Server is now starting.
[root@sqlsvr ~]#
[root@mssqlsvrxe ~]# service mssql-server status
Redirecting to /bin/systemctl status mssql-server.service
● mssql-server.service - Microsoft SQL Server Database Engine
Loaded: loaded (/usr/lib/systemd/system/mssql-server.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-08-27 15:01:32 UTC; 43s ago
Docs: https://docs.microsoft.com/en-us/sql/linux
Main PID: 616 (sqlservr)
CGroup: /system.slice/mssql-server.service
├─616 /opt/mssql/bin/sqlservr
└─631 /opt/mssql/bin/sqlservr


Aug 27 15:01:58 mssqlsvrxe sqlservr[616]: 2020-08-27 15:01:58.34 spid9s 9 transactions rolled forward in da...ired.
Aug 27 15:01:59 mssqlsvrxe sqlservr[616]: 2020-08-27 15:01:59.00 spid9s 0 transactions rolled back in datab...ired.
Aug 27 15:01:59 mssqlsvrxe sqlservr[616]: 2020-08-27 15:01:59.01 spid9s Recovery completed for database msd...ired.
Aug 27 15:01:59 mssqlsvrxe sqlservr[616]: 2020-08-27 15:01:59.73 spid11s Clearing tempdb database.
Aug 27 15:02:01 mssqlsvrxe sqlservr[616]: 2020-08-27 15:02:01.07 spid11s [2]. Feature Status: PVS: 0. CTR: 0...e: 1.
Aug 27 15:02:01 mssqlsvrxe sqlservr[616]: 2020-08-27 15:02:01.08 spid11s Starting up database 'tempdb'.
Aug 27 15:02:01 mssqlsvrxe sqlservr[616]: 2020-08-27 15:02:01.71 spid37s The Service Broker endpoint is in d...tate.
Aug 27 15:02:01 mssqlsvrxe sqlservr[616]: 2020-08-27 15:02:01.72 spid37s The Database Mirroring endpoint is ...tate.
Aug 27 15:02:01 mssqlsvrxe sqlservr[616]: 2020-08-27 15:02:01.75 spid37s Service Broker manager has started.
Aug 27 15:02:01 mssqlsvrxe sqlservr[616]: 2020-08-27 15:02:01.76 spid9s Recovery is complete. This is an in...ired.
Hint: Some lines were ellipsized, use -l to show in full.
[root@mssqlsvrxe ~]#


資料庫是在 1433 Port 上運作的,可以在 Host 用 nmap 看到。
這邊如果是完整的 OS,就要記得開防火牆
lab@lxdlab-edb:~$ lxc list mssqlsvrxe
+------------+---------+----------------------+----------------------------------------------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------------+---------+----------------------+----------------------------------------------+-----------+-----------+
| mssqlsvrxe | RUNNING | 10.222.190.41 (eth0) | fd42:c041:253:d153:216:3eff:feaa:9432 (eth0) | CONTAINER | 0 |
+------------+---------+----------------------+----------------------------------------------+-----------+-----------+
lab@lxdlab-edb:~$
lab@lxdlab-edb:~$ nmap -p- 10.222.190.41


Starting Nmap 7.40 ( https://nmap.org ) at 2020-08-27 11:03 EDT
Nmap scan report for 10.222.190.41
Host is up (0.00015s latency).
Not shown: 65534 closed ports
PORT STATE SERVICE
1433/tcp open ms-sql-s


Nmap done: 1 IP address (1 host up) scanned in 2.35 seconds
lab@lxdlab-edb:~$


接著裝 Client:中間有兩個 YES 要買單
[root@mssqlsvrxe ~]# curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 193 100 193 0 0 238 0 --:--:-- --:--:-- --:--:-- 238
[root@mssqlsvrxe ~]#
[root@mssqlsvrxe ~]# yum install -y mssql-tools
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.tc.edu.tw
* extras: ftp.tc.edu.tw
* updates: ftp.tc.edu.tw
packages-microsoft-com-prod | 3.0 kB 00:00:00
packages-microsoft-com-prod/primary_db | 294 kB 00:00:01
Resolving Dependencies
--> Running transaction check
---> Package mssql-tools.x86_64 0:17.6.1.1-1 will be installed
--> Processing Dependency: msodbcsql17 >= 17.3.0.0 for package: mssql-tools-17.6.1.1-1.x86_64
--> Running transaction check
---> Package msodbcsql17.x86_64 0:17.6.1.1-1 will be installed
--> Processing Dependency: unixODBC >= 2.3.1 for package: msodbcsql17-17.6.1.1-1.x86_64
--> Processing Dependency: e2fsprogs for package: msodbcsql17-17.6.1.1-1.x86_64
--> Processing Dependency: libodbcinst.so.2()(64bit) for package: msodbcsql17-17.6.1.1-1.x86_64
--> Running transaction check
---> Package e2fsprogs.x86_64 0:1.42.9-17.el7 will be installed
--> Processing Dependency: libss = 1.42.9-17.el7 for package: e2fsprogs-1.42.9-17.el7.x86_64
--> Processing Dependency: libcom_err(x86-64) = 1.42.9-17.el7 for package: e2fsprogs-1.42.9-17.el7.x86_64
--> Processing Dependency: e2fsprogs-libs(x86-64) = 1.42.9-17.el7 for package: e2fsprogs-1.42.9-17.el7.x86_64
--> Processing Dependency: libss.so.2()(64bit) for package: e2fsprogs-1.42.9-17.el7.x86_64
--> Processing Dependency: libext2fs.so.2()(64bit) for package: e2fsprogs-1.42.9-17.el7.x86_64
--> Processing Dependency: libe2p.so.2()(64bit) for package: e2fsprogs-1.42.9-17.el7.x86_64
---> Package unixODBC.x86_64 0:2.3.7-1.rh will be installed
--> Running transaction check
---> Package e2fsprogs-libs.x86_64 0:1.42.9-17.el7 will be installed
---> Package libcom_err.x86_64 0:1.42.9-16.el7 will be updated
---> Package libcom_err.x86_64 0:1.42.9-17.el7 will be an update
---> Package libss.x86_64 0:1.42.9-17.el7 will be installed
--> Finished Dependency Resolution


Dependencies Resolved


========================================================================================================================
Package Arch Version Repository Size
========================================================================================================================
Installing:
mssql-tools x86_64 17.6.1.1-1 packages-microsoft-com-prod 223 k
Installing for dependencies:
e2fsprogs x86_64 1.42.9-17.el7 base 699 k
e2fsprogs-libs x86_64 1.42.9-17.el7 base 168 k
libss x86_64 1.42.9-17.el7 base 46 k
msodbcsql17 x86_64 17.6.1.1-1 packages-microsoft-com-prod 788 k
unixODBC x86_64 2.3.7-1.rh packages-microsoft-com-prod 213 k
Updating for dependencies:
libcom_err x86_64 1.42.9-17.el7 base 42 k


Transaction Summary
========================================================================================================================
Install 1 Package (+5 Dependent packages)
Upgrade ( 1 Dependent package)


Total download size: 2.1 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/7): libcom_err-1.42.9-17.el7.x86_64.rpm | 42 kB 00:00:00
(2/7): libss-1.42.9-17.el7.x86_64.rpm | 46 kB 00:00:01
(3/7): e2fsprogs-libs-1.42.9-17.el7.x86_64.rpm | 168 kB 00:00:01
(4/7): e2fsprogs-1.42.9-17.el7.x86_64.rpm | 699 kB 00:00:02
(5/7): mssql-tools-17.6.1.1-1.x86_64.rpm | 223 kB 00:00:02
(6/7): msodbcsql17-17.6.1.1-1.x86_64.rpm | 788 kB 00:00:03
(7/7): unixODBC-2.3.7-1.rh.x86_64.rpm | 213 kB 00:00:00
------------------------------------------------------------------------------------------------------------------------
Total 621 kB/s | 2.1 MB 00:00:03
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : libcom_err-1.42.9-17.el7.x86_64 1/8
Installing : libss-1.42.9-17.el7.x86_64 2/8
Installing : e2fsprogs-libs-1.42.9-17.el7.x86_64 3/8
Installing : e2fsprogs-1.42.9-17.el7.x86_64 4/8
Installing : unixODBC-2.3.7-1.rh.x86_64 5/8
The license terms for this product can be downloaded from
https://aka.ms/odbc17eula and found in
/usr/share/doc/msodbcsql17/LICENSE.txt . By entering 'YES',
you indicate that you accept the license terms.


Do you accept the license terms? (Enter YES or NO)
YES
Installing : msodbcsql17-17.6.1.1-1.x86_64 6/8
The license terms for this product can be downloaded from
http://go.microsoft.com/fwlink/?LinkId=746949 and found in
/usr/share/doc/mssql-tools/LICENSE.txt . By entering 'YES',
you indicate that you accept the license terms.


Do you accept the license terms? (Enter YES or NO)
YES
Installing : mssql-tools-17.6.1.1-1.x86_64 7/8
Cleanup : libcom_err-1.42.9-16.el7.x86_64 8/8
Verifying : libss-1.42.9-17.el7.x86_64 1/8
Verifying : mssql-tools-17.6.1.1-1.x86_64 2/8
Verifying : e2fsprogs-libs-1.42.9-17.el7.x86_64 3/8
Verifying : e2fsprogs-1.42.9-17.el7.x86_64 4/8
Verifying : libcom_err-1.42.9-17.el7.x86_64 5/8
Verifying : unixODBC-2.3.7-1.rh.x86_64 6/8
Verifying : msodbcsql17-17.6.1.1-1.x86_64 7/8
Verifying : libcom_err-1.42.9-16.el7.x86_64 8/8


Installed:
mssql-tools.x86_64 0:17.6.1.1-1


Dependency Installed:
e2fsprogs.x86_64 0:1.42.9-17.el7 e2fsprogs-libs.x86_64 0:1.42.9-17.el7 libss.x86_64 0:1.42.9-17.el7
msodbcsql17.x86_64 0:17.6.1.1-1 unixODBC.x86_64 0:2.3.7-1.rh


Dependency Updated:
libcom_err.x86_64 0:1.42.9-17.el7


Complete!
[root@mssqlsvrxe ~]#


現在該來看一下適用啥帳號運作的了
[root@mssqlsvrxe ~]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 43368 4948 ? Ss 14:42 0:00 /sbin/init
root 39 0.0 0.1 39092 3684 ? Ss 14:42 0:00 /usr/lib/systemd/systemd-journald
root 53 0.0 0.1 26388 2816 ? Ss 14:42 0:00 /usr/lib/systemd/systemd-logind
dbus 54 0.0 0.1 58132 4180 ? Ss 14:42 0:00 /usr/bin/dbus-daemon --system --address=systemd: --nofo
root 71 0.0 0.0 6524 1724 console Ss+ 14:42 0:00 /sbin/agetty --noclear --keep-baud console 115200,38400
root 75 0.0 0.1 22704 2732 ? Ss 14:42 0:00 /usr/sbin/crond -n
root 259 0.0 0.1 102904 2884 ? Ss 14:42 0:00 /sbin/dhclient -1 -q -lf /var/lib/dhclient/dhclient--et
root 321 0.0 0.2 284092 5196 ? Ssl 14:42 0:00 /usr/sbin/rsyslogd -n
mssql 616 0.0 0.6 134204 17068 ? Ssl 15:01 0:00 /opt/mssql/bin/sqlservr
mssql 631 0.0 23.9 5261448 614612 ? Sl 15:01 0:25 /opt/mssql/bin/sqlservr
root 799 0.0 0.1 185588 4120 ? Ss 15:06 0:00 su -l
root 800 0.0 0.1 11836 2976 ? S 15:06 0:00 -bash
root 891 0.0 0.1 51760 3448 ? R+ 15:08 0:00 ps aux
[root@mssqlsvrxe ~]#


看起來叫做 m$sql。。。不是,是叫做 mssql
[root@mssqlsvrxe ~]# su - mssql
-bash-4.2$ pwd
/var/opt/mssql
-bash-4.2$ echo $HOME
/var/opt/mssql
-bash-4.2$


看一下執行檔有哪些
-bash-4.2$ ls /opt/
microsoft mssql mssql-tools
-bash-4.2$
-bash-4.2$ ## Client 的執行檔
-bash-4.2$ ls /opt/mssql-tools/bin/
bcp sqlcmd
-bash-4.2$
-bash-4.2$ ## Server 的執行檔
-bash-4.2$ ls /opt/mssql/bin/
compress-dump.sh crash-support-functions.sh generate-sql-dump.sh handle-crash.sh mssql-conf paldumper sqlservr
-bash-4.2$


加進去環境變數吧~
-bash-4.2$ cat << "EOF" >> ~/.bash_profile
export PATH=$PATH:/opt/mssql-tools/bin/
export PATH=$PATH:/opt/mssql/bin/
EOF
-bash-4.2$
-bash-4.2$ source ~/.bash_profile
-bash-4.2$


要登入了,看一下 help,連這個也要長的跟別人不一樣。。。
然後,據說帳號叫做 SA
-bash-4.2$ ip -4 a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
30: eth0@if31: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link-netnsid 0
inet 10.222.190.41/24 brd 10.222.190.255 scope global dynamic eth0
valid_lft 3539sec preferred_lft 3539sec
-bash-4.2$
-bash-4.2$ sqlcmd -?
Microsoft (R) SQL Server Command Line Tool
Version 17.6.0001.1 Linux
Copyright (C) 2017 Microsoft Corporation. All rights reserved.


usage: sqlcmd [-U login id] [-P password]
[-S server or Dsn if -D is provided]
[-H hostname] [-E trusted connection]
[-N Encrypt Connection][-C Trust Server Certificate]
[-d use database name] [-l login timeout] [-t query timeout]
[-h headers] [-s colseparator] [-w screen width]
[-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
[-c cmdend]
[-q "cmdline query"] [-Q "cmdline query" and exit]
[-m errorlevel] [-V severitylevel] [-W remove trailing spaces]
[-u unicode output] [-r[0|1] msgs to stderr]
[-i inputfile] [-o outputfile]
[-k[1|2] remove[replace] control characters]
[-y variable length type display width]
[-Y fixed length type display width]
[-p[1] print statistics[colon format]]
[-R use client regional setting]
[-K application intent]
[-M multisubnet failover]
[-b On error batch abort]
[-D Dsn flag, indicate -S is Dsn]
[-X[1] disable commands, startup script, environment variables [and exit]]
[-x disable variable substitution]
[-g enable column encryption]
[-G use Azure Active Directory for authentication]
[-? show syntax summary]
-bash-4.2$
-bash-4.2$ sqlcmd -S 10.222.190.41 -U SA
Password: SQLS1rv1r
1> create table testms(id int, txt varchar(100))
2> go
1>
1> insert into testms values (1,'hi, ms')
2> go


(1 rows affected)
1>
1> select * from testms
2> go
id txt
----------- ----------------------------------------------------------------------------------------------------
1 hi, ms


(1 rows affected)
1>


查看一下現在在哪裡,後面測 tds_fdw 要用。。
1> SELECT @@SPID AS 'ID',
2> SYSTEM_USER AS 'Login Name',
3> USER AS 'User Name',
4> DB_name() AS 'database'
5> go
ID Login Name User Name database
------ -------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------
51 sa dbo master


(1 rows affected)
1>


然後只要輸入 quit 或按 Ctrl+C 就可以離開了


參考資料
http://sqlserveronlinuxbackup.com/how-to-install-ms-sql-server-on-linux/
https://docs.microsoft.com/zh-tw/sql/linux/quickstart-install-connect-ubuntu?view=sql-server-2017
https://docs.microsoft.com/zh-tw/sql/linux/quickstart-install-connect-red-hat?view=sql-server-ver15
https://dzone.com/articles/getting-started-with-sqlcmd
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/cf7c37d8-1e76-4374-bdef-debad8724da7/sqlcmd-current-database-session-info?forum=sqlgetstarted

沒有留言:

張貼留言