0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SQL Server 2022 on Ubuntu 22.04 on Hyper-V

Posted at

SQL Server 2022 on Ubuntu 22.04 on Hyper-V

基本は公式の通り

https://learn.microsoft.com/ja-jp/sql/linux/quickstart-install-connect-ubuntu?view=sql-server-ver16&tabs=ubuntu2204

はまりどころ

curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
curl -fsSL https://packages.microsoft.com/config/ubuntu/22.04/mssql-server-2022.list | sudo tee /etc/apt/sources.list.d/mssql-server-2022.list
sudo apt-get update
sudo apt-get install -y mssql-server

ここまでは公式の通りで問題なし。次がはまりどころ。

sudo /opt/mssql/bin/mssql-conf setup

このコマンドだと対話型で初期設定ができるが、ここで設定したsaのパスワードはなぜか正常に設定されない。
なので次の代替手段で設定する。

ログインしようとしたときのエラー

画面表示

Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : Login failed for user 'sa'..

エラーログ

Error: 18456, Severity: 14, State: 7.

代替手段

ここで一回再起動しておく

sudo reboot

再起動後に「無人インストール」の項目に書いてある方法で設定する
https://learn.microsoft.com/ja-jp/sql/linux/sql-server-linux-setup?view=sql-server-ver16#unattended

sudo MSSQL_PID=Developer ACCEPT_EULA=Y MSSQL_SA_PASSWORD='<password>' /opt/mssql/bin/mssql-conf -n setup

sqlcmdのインストール

ここははまりどころはない

curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
sudo apt-get update
sudo apt-get install mssql-tools18 unixodbc-dev
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bash_profile
source ~/.bash_profile

sqlcmdでログイン

ここにも地味にはまりどころがある

sqlcmd -S localhost -U sa -P '<YourPassword>'

これだけだとたぶんエラーが返ってくる

Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : SSL Provider: [error:0A000086:SSL routines::certificate verify failed:self-signed certificate].
Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : Client unable to establish connection. For solutions related to encryption errors, see https://go.microsoft.com/fwlink/?linkid=2226722.

注意事項に書いてある通り -No をセットするか、-Cで証明書を素通りさせる

sqlcmd -S localhost -U sa -P '<YourPassword>' -C
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?