CentOS 8にMicrosoft SQL Server 2019をインストールしましたが、今回はcommand-line toolsをインストールしてみます。
Install the SQL Server command-line tools
https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-red-hat?view=sql-server-ver15#tools
環境
・CentOS Linux release 8.2.2004 (Core)
・4.18.0-193.6.3.el8_2.x86_64
- Repositoryのダウンロード
- mssql-toolsのインストール
- PATHの追加
- MS SQL Serverに接続
1 2 3 4 5 6 7 8 9 10 11 |
[root@centos8 ~]# curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/8/prod.repo % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 192 100 192 0 0 509 0 --:--:-- --:--:-- --:--:-- 509 [root@centos8 ~]# cat /etc/yum.repos.d/msprod.repo [packages-microsoft-com-prod] name=packages-microsoft-com-prod baseurl=https://packages.microsoft.com/rhel/8/prod/ enabled=1 gpgcheck=1 gpgkey=https://packages.microsoft.com/keys/microsoft.asc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
[root@centos8 ~]# dnf -y install mssql-tools unixODBC-devel packages-microsoft-com-prod 517 kB/s | 5.5 MB 00:10 Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: mssql-tools x86_64 17.5.2.1-1 packages-microsoft-com-prod 223 k unixODBC-devel x86_64 2.3.7-1.rh packages-microsoft-com-prod 42 k Installing dependencies: msodbcsql17 x86_64 17.5.2.1-1 packages-microsoft-com-prod 802 k unixODBC x86_64 2.3.7-1.rh packages-microsoft-com-prod 213 k Transaction Summary ================================================================================ Install 4 Packages Total download size: 1.3 M Installed size: 1.3 M Downloading Packages: (1/4): mssql-tools-17.5.2.1-1.x86_64.rpm 244 kB/s | 223 kB 00:00 (2/4): unixODBC-2.3.7-1.rh.x86_64.rpm 229 kB/s | 213 kB 00:00 (3/4): unixODBC-devel-2.3.7-1.rh.x86_64.rpm 232 kB/s | 42 kB 00:00 (4/4): msodbcsql17-17.5.2.1-1.x86_64.rpm 287 kB/s | 802 kB 00:02 -------------------------------------------------------------------------------- Total 457 kB/s | 1.3 MB 00:02 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : unixODBC-2.3.7-1.rh.x86_64 1/4 Running scriptlet: unixODBC-2.3.7-1.rh.x86_64 1/4 Running scriptlet: msodbcsql17-17.5.2.1-1.x86_64 2/4 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.5.2.1-1.x86_64 2/4 Running scriptlet: msodbcsql17-17.5.2.1-1.x86_64 2/4 Running scriptlet: mssql-tools-17.5.2.1-1.x86_64 3/4 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.5.2.1-1.x86_64 3/4 Installing : unixODBC-devel-2.3.7-1.rh.x86_64 4/4 Running scriptlet: msodbcsql17-17.5.2.1-1.x86_64 4/4 Running scriptlet: unixODBC-devel-2.3.7-1.rh.x86_64 4/4 Verifying : msodbcsql17-17.5.2.1-1.x86_64 1/4 Verifying : mssql-tools-17.5.2.1-1.x86_64 2/4 Verifying : unixODBC-2.3.7-1.rh.x86_64 3/4 Verifying : unixODBC-devel-2.3.7-1.rh.x86_64 4/4 Installed: msodbcsql17-17.5.2.1-1.x86_64 mssql-tools-17.5.2.1-1.x86_64 unixODBC-2.3.7-1.rh.x86_64 unixODBC-devel-2.3.7-1.rh.x86_64 Complete! |
/opt/mssql-tools/binをPATHに追加します。
1 2 |
[root@centos8 ~]# echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc [root@centos8 ~]# source ~/.bashrc |
接続できました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
[root@centos8 ~]# sqlcmd -U SA Password: 1> :Listvar SQLCMDCOLSEP = " " SQLCMDCOLWIDTH = "0" SQLCMDDBNAME = "" SQLCMDEDITOR = "edit.com" SQLCMDERRORLEVEL = "0" SQLCMDHEADERS = "0" SQLCMDINI = "" SQLCMDLOGINTIMEOUT = "8" SQLCMDMAXFIXEDTYPEWIDTH = "0" SQLCMDMAXVARTYPEWIDTH = "256" SQLCMDPACKETSIZE = "4096" SQLCMDSERVER = "centos8.rootlinks.net" SQLCMDSTATTIMEOUT = "0" SQLCMDUSER = "SA" SQLCMDWORKSTATION = "centos8.rootlinks.net" 1> SELECT Name from sys.Databases 2> go Name -------------------------------------------------------------------------------------------------------------------------------- master tempdb model msdb (4 rows affected) 1> quit |
help
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
[root@centos8 ~]# sqlcmd -? Microsoft (R) SQL Server Command Line Tool Version 17.5.0002.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] |